feature(cloudcmd) rm appCache

This commit is contained in:
coderaiser 2014-08-26 10:41:49 -04:00
parent 8445d32283
commit b8a1176c26
7 changed files with 2 additions and 210 deletions

View file

@ -216,7 +216,6 @@ All main configuration could be done via `json/config.json`.
"auth" : false, /* enable http authentication */
"username" : "root", /* username for authentication */
"password" : "toor", /* password hash in sha-1 for authentication*/
"appCache" : false, /* cache files for offline use */
"analytics" : true, /* google analytics support */
"diff" : true, /* when save - send patch, not whole file */
"zip" : true, /* zip text before send / unzip before save */

View file

@ -15,7 +15,6 @@
mellow = require(DIR_SERVER + 'mellow'),
ponse = require(DIR_SERVER + 'ponse'),
files = require(DIR_SERVER + 'files'),
AppCache = require(DIR_SERVER + 'appcache'),
update = require(DIR_SERVER + 'update'),
minify = require(DIR_SERVER + 'minify'),
@ -76,14 +75,6 @@
data = options.data,
panel = options.panel;
if (!Config.appCache)
data = Util.rmStr(data, [
/* min */
' manifest=/cloudcmd.appcache',
/* normal */
' manifest="/cloudcmd.appcache"'
]);
if (!Config.showKeysPanel) {
keysPanel = '<div class="keyspanel';
data = data.replace(keysPanel + '"', keysPanel +' hidden"');
@ -109,23 +100,6 @@
return data;
}
/**
* init and process of appcache if it allowed in config
*/
function appCacheProcessing() {
var FONT_REMOTE = '//themes.googleusercontent.com/static/fonts/droidsansmono/v4/ns-m2xQYezAtqh7ai59hJUYuTAAIFFn5GTWtryCmBQ4.woff',
FONT_LOCAL = './font/DroidSansMono.woff',
JQUERY_REMOTE = '//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js',
JQUERY_LOCAL = './lib/client/jquery.js',
files = [{}, {}];
files[0][FONT_REMOTE] = FONT_LOCAL;
files[1][JQUERY_REMOTE] = JQUERY_LOCAL;
AppCache.addFiles(files);
AppCache.createManifest();
}
function init(config) {
var paramsStart;
@ -149,7 +123,6 @@
}
paramsStart = {
appcache : appCacheProcessing,
rest : main.rest,
route : route
};

View file

@ -2,7 +2,6 @@
<li><span><input type="checkbox" id="auth" {{ auth }} ></input></span><label for="auth"> Auth</label></li>
<li><span><input type="text" class="form-control" placeholder="username" id="username" value="{{ username }}"></input></span></li>
<li><span><input type="password" class="form-control" placeholder="password" id="password" value="{{ password }}" ></input></span></li>
<li><span><input type="checkbox" id="appCache" {{ appCache }} ></input></span><label for="appCache"> App cache</label></li>
<li><span><input type="checkbox" id="analytics" {{ analytics }} ></input></span><label for="analytics"> Analytics</label></li>
<li><span><input type="checkbox" id="diff" {{ diff }} ></input></span><label for="diff"> Diff</label></li>
<li><span><input type="checkbox" id="zip" {{ zip }} ></input></span><label for="zip"> Zip</label></li>

View file

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html manifest="/cloudcmd.appcache">
<html>
<head>
<meta charset="utf-8">
<meta name="robots" content="noindex,nofollow">

View file

@ -2,7 +2,6 @@
"auth": false,
"username": "root",
"password": "435b41068e8665513a20070c033b08b9c66e4332",
"appСache": false,
"analytics": true,
"diff": true,
"zip" : true,

View file

@ -26,12 +26,9 @@
CloudFunc = require(DIR_LIB + 'cloudfunc'),
minify = require(DIR_SERVER + 'minify'),
AppCache = require(DIR_SERVER + 'appcache'),
Socket = require(DIR_SERVER + 'socket'),
Console = require(DIR_SERVER + 'console'),
Terminal = !WIN ? require(DIR_SERVER + 'terminal') : {
init: function() {}
},
Terminal = !WIN ? require(DIR_SERVER + 'terminal') : function() {},
join = require(DIR_SERVER + 'join'),
ponse = require(DIR_SERVER + 'ponse'),
express = require(DIR_SERVER + 'express'),
@ -40,16 +37,6 @@
Rest, Route;
/* базовая инициализация */
function init(appCacheCallback) {
var config = main.config;
/* создаём файл app cache */
if (config.appcache && AppCache && config.server)
Util.exec(appCacheCallback);
}
/**
* start server function
*
@ -67,8 +54,6 @@
Rest = options.rest;
Route = options.route;
init(options.appcache);
port = process.env.PORT || /* c9 */
process.env.app_port || /* nodester */
process.env.VCAP_APP_PORT || /* cloudfoundry */
@ -220,10 +205,6 @@
name = path.join(dir, name);
/* watching is file changed */
if (config.appcache)
AppCache.watch(name);
ponse.sendFile({
name : name,
cache : config.cache,

View file

@ -1,159 +0,0 @@
(function() {
'use strict';
if (!global.cloudcmd)
return console.log(
'# appcache.js' + '\n' +
'# -----------' + '\n' +
'# Module is part of Cloud Commander,' + '\n' +
'# used for work with Aplication Cache.' + '\n' +
'# If you wont to see at work set appcache: true' + '\n' +
'# in config.json and start cloudcmd.js' + '\n' +
'# http://cloudcmd.io' + '\n');
var main = global.cloudcmd.main,
DIR = '../',
WIN = process.platform === 'win32',
fs = require('fs'),
Util = require(DIR + 'util'),
/* varible contain all watched file names
* {name: true}
*/
FileNames = {},
NamesList_s = '',
FallBack_s = '',
/* function thet use for crossplatform
* access to fs.watch or fs.watchFile function
*/
fs_watch = null,
on_fs_watch = null,
firstFileRead_b = true,
Manifest = '';
setWatachFunctions();
/* function add file or files to manifest
* Examples:
* exports.addFiles('jquery.js'),
* exports.addFiles(['jquery.js', 'client.js']);
* exports.addFiles([{'http://cdn.jquery/jq.js':'jquery.js'}, 'client.js']);
*/
exports.addFiles = function(pFileNames) {
var i, n, lName, lCurrentName,
watch = exports.watch;
/* if a couple files */
if (Util.isArray(pFileNames)) {
n = pFileNames.length;
for (i = 0; i < n; i++) {
/* if fallback setted up */
lCurrentName = pFileNames[i];
if (Util.isObject(lCurrentName))
for (lName in lCurrentName) {
FallBack_s += lName + ' ' + lCurrentName[lName] + '\n';
watch(lCurrentName[lName]);
}
else
watch(pFileNames[i]);
}
} else
watch(pFileNames);
};
exports.createManifest = function(){
var lAllNames = main.require('node_modules/minify/hashes');
if (lAllNames)
for (var lName in lAllNames){
if (lName.indexOf('min') > 0)
lName = 'node_modules/minify/min/' + lName;
exports.watch(lName);
}
processManifest();
};
exports.watch = function(pFileName) {
if (!FileNames[pFileName] &&
pFileName !== './cloudcmd.appcache') {
Util.log(pFileName + ' is watched');
/* adding try...catch
* if watched files would be more then system limit
*/
var lWatch_f = function() {
Util.exec.try(function() {
fs_watch(pFileName, on_fs_watch(pFileName));
});
};
/* if file.exists function exist and
* file actually exists
*/
if (fs.exists)
fs.exists(pFileName, lWatch_f);
else
lWatch_f();
NamesList_s += pFileName + '\n';
FileNames[pFileName] = true;
} else if (firstFileRead_b) {
processManifest();
firstFileRead_b = false;
}
};
function setWatachFunctions() {
if (WIN) {
/* good on windows */
fs_watch = fs.watch;
on_fs_watch = onWatch;
}
else {
/* good on linux */
fs_watch = fs.watchFile;
on_fs_watch = onWatchFile;
}
}
function onWatch () {
return function(pEvent, pFileName) {
Util.log(pEvent);
Util.log('file ' + pFileName + ' is changed');
processManifest();
};
}
function onWatchFile(pFileName) {
return function(pCurr, pPrev) {
if (pCurr.mtime !== pPrev.mtime) {
Util.log('file ' + pFileName + ' is changed');
processManifest();
}
};
}
function processManifest() {
Manifest = 'CACHE MANIFEST\n' +
'#' + Date() + '\n' +
'CACHE:\n' +
NamesList_s +
'NETWORK:\n' +
'*\n' +
'FALLBACK:\n' +
FallBack_s;
fs.writeFile('cloudcmd.appcache', Manifest, function() {
Util.log('cloudcmd.appcache refreshed');
});
}
})();