mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature(config) minification -> minify: {} -> true
This commit is contained in:
parent
a479b73cf2
commit
cb5a529fb4
5 changed files with 39 additions and 66 deletions
7
HELP.md
7
HELP.md
|
|
@ -140,12 +140,7 @@ All main configuration could be done via [config.json](json/config.json "Config"
|
|||
"appcache" : false, /* cache files for offline use */
|
||||
"analytics" : true, /* google analytics suport */
|
||||
"localStorage" : true, /* cache directory data */
|
||||
"minification" : { /* minification of js,css,html and img */
|
||||
"js" : false, /* minify module needed */
|
||||
"css" : false, /* npm i minify */
|
||||
"html" : true,
|
||||
"img" : false
|
||||
},
|
||||
"minify" : true /* minification of js,css,html and img */
|
||||
"online" : true, /* load js files from cdn or local path */
|
||||
"cache" : true,
|
||||
"logs" : false, /* logs or console ouput */
|
||||
|
|
|
|||
61
cloudcmd.js
61
cloudcmd.js
|
|
@ -44,7 +44,7 @@
|
|||
/**
|
||||
* additional processing of index file
|
||||
*/
|
||||
function indexProcessing(pData){
|
||||
function indexProcessing(pData) {
|
||||
var lPath, lReplace, lKeysPanel,
|
||||
lData = pData.data,
|
||||
lAdditional = pData.additional;
|
||||
|
|
@ -54,31 +54,31 @@
|
|||
* меняем в index.html обычные css на
|
||||
* минифицированый
|
||||
*/
|
||||
if (Minify.allowed.css){
|
||||
if (Minify.allowed) {
|
||||
lPath = '/' + Util.removeStr(Minify.MinFolder, DIR);
|
||||
lReplace = '<link rel=stylesheet href="/css/reset.css">';
|
||||
lData = Util.removeStr(lData, lReplace)
|
||||
.replace('/css/style.css', lPath + 'all.min.css');
|
||||
}
|
||||
|
||||
if (!Config.appcache)
|
||||
lData = Util.removeStr(lData, [
|
||||
/* min */
|
||||
'manifest=/cloudcmd.appcache',
|
||||
/* normal */
|
||||
'manifest="/cloudcmd.appcache"'
|
||||
]);
|
||||
|
||||
if (!Config.show_keys_panel) {
|
||||
lKeysPanel = '<div id=keyspanel';
|
||||
lData = lData.replace(lKeysPanel, lKeysPanel +' class=hidden');
|
||||
}
|
||||
|
||||
lData = Util.render(lData, {
|
||||
title : CloudFunc.getTitle(),
|
||||
fm : lAdditional
|
||||
});
|
||||
|
||||
if (!Config.appcache)
|
||||
lData = Util.removeStr(lData, [
|
||||
/* min */
|
||||
' manifest=/cloudcmd.appcache',
|
||||
/* normal */
|
||||
' manifest="/cloudcmd.appcache"'
|
||||
]);
|
||||
|
||||
if (!Config.show_keys_panel){
|
||||
lKeysPanel = '<div id=keyspanel';
|
||||
lData = lData.replace(lKeysPanel, lKeysPanel +' class=hidden');
|
||||
}
|
||||
|
||||
return lData;
|
||||
|
||||
}
|
||||
|
|
@ -96,7 +96,7 @@
|
|||
lFiles[0][lFONT_REMOTE] = lFONT_LOCAL;
|
||||
lFiles[1][lJQUERY_REMOTE] = lJQUERY_LOCAL;
|
||||
|
||||
if (Config.minification.css)
|
||||
if (Config.minify)
|
||||
lFiles.push('node_modules/minify/min/all.min.css');
|
||||
|
||||
AppCache.addFiles(lFiles);
|
||||
|
|
@ -109,22 +109,19 @@
|
|||
*/
|
||||
function minimize(pAllowed){
|
||||
var lOptimizeParams = [],
|
||||
lStyleCSS = DIR + 'css/style.css',
|
||||
lResetCSS = DIR + 'css/reset.css',
|
||||
lStyles = [{}, {}],
|
||||
lStyleCSS = DIR + 'css/style.css',
|
||||
lResetCSS = DIR + 'css/reset.css',
|
||||
|
||||
lCSSOptions = {
|
||||
img : pAllowed.img,
|
||||
lCSSOptions = {
|
||||
img : true,
|
||||
merge : true
|
||||
};
|
||||
|
||||
if (pAllowed.js)
|
||||
if (pAllowed) {
|
||||
lOptimizeParams.push(LIBDIR + 'client.js');
|
||||
|
||||
if (pAllowed.html)
|
||||
lOptimizeParams.push(INDEX);
|
||||
|
||||
if (pAllowed.css) {
|
||||
var lStyles = [{}, {}];
|
||||
|
||||
lStyles[0][lStyleCSS] = lCSSOptions;
|
||||
lStyles[1][lResetCSS] = lCSSOptions;
|
||||
|
||||
|
|
@ -240,14 +237,14 @@
|
|||
var lStr = pData.toString(),
|
||||
lReadedConf = Util.parseJSON(lStr);
|
||||
|
||||
if (!Config.minification)
|
||||
if (!Config.minify)
|
||||
main.config = Config = lReadedConf;
|
||||
|
||||
Util.tryCatchLog(function(){
|
||||
Config.minification.js = lReadedConf.minification.js;
|
||||
Config.cache = lReadedConf.cache;
|
||||
Config.minify = lReadedConf.minify;
|
||||
Config.cache = lReadedConf.cache;
|
||||
|
||||
Minify.setAllowed(Config.minification);
|
||||
Minify.setAllowed(Config.minify);
|
||||
});
|
||||
}
|
||||
else
|
||||
|
|
@ -318,9 +315,9 @@
|
|||
main.sendResponse(p);
|
||||
}
|
||||
else{ /* get back html*/
|
||||
p.name = Minify.allowed.html ? Minify.getName(INDEX) : INDEX;
|
||||
p.name = Minify.allowed ? Minify.getName(INDEX) : INDEX;
|
||||
fs.readFile(p.name, function(pError, pData){
|
||||
if (!pError){
|
||||
if (!pError) {
|
||||
var lPanel = CloudFunc.buildFromJSON(pJSON, FileTemplate, PathTemplate),
|
||||
lList = '<ul id=left class=panel>' + lPanel + '</ul>' +
|
||||
'<ul id=right class=panel>' + lPanel + '</ul>';
|
||||
|
|
|
|||
|
|
@ -3,12 +3,7 @@
|
|||
"appcache": false,
|
||||
"analytics": true,
|
||||
"localStorage": true,
|
||||
"minification": {
|
||||
"js": true,
|
||||
"css": true,
|
||||
"html": true,
|
||||
"img": true
|
||||
},
|
||||
"minify": true,
|
||||
"online": true,
|
||||
"cache": true,
|
||||
"logs": false,
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
/* базовая инициализация */
|
||||
function init(pAppCachProcessing) {
|
||||
var lConfig = main.config,
|
||||
lMinifyAllowed = lConfig.minification;
|
||||
lMinifyAllowed = lConfig.minify;
|
||||
|
||||
/* Change default parameters of
|
||||
* js/css/html minification
|
||||
|
|
@ -179,9 +179,7 @@
|
|||
lName = Path.join(DIR, lName);
|
||||
lMin = Minify.allowed,
|
||||
lExt = Util.getExtension(lName),
|
||||
lResult = lExt === '.js' && lMin.js ||
|
||||
lExt === '.css' && lMin.css ||
|
||||
lExt === '.html' && lMin.html;
|
||||
lResult = lMin && Util.strCmp(lExt, ['.js', '.css', '.html']);
|
||||
|
||||
Util.ifExec(!lResult,
|
||||
function(pParams) {
|
||||
|
|
|
|||
|
|
@ -29,12 +29,7 @@
|
|||
/* pathes to directories */
|
||||
INDEX : HTMLDIR + 'index.html',
|
||||
/* приватный переключатель минимизации */
|
||||
allowed : {
|
||||
css : true,
|
||||
js : true,
|
||||
html : true,
|
||||
img : true
|
||||
},
|
||||
allowed : true,
|
||||
|
||||
/* функция разрешает или
|
||||
* запрещает минимизировать
|
||||
|
|
@ -47,19 +42,16 @@
|
|||
* и сохранение их в css-файл
|
||||
*/
|
||||
setAllowed :function(pAllowed) {
|
||||
this.allowed = pAllowed && Minify ? pAllowed : {
|
||||
js : false,
|
||||
css : false,
|
||||
html : false
|
||||
};
|
||||
this.allowed = pAllowed && Minify;
|
||||
},
|
||||
|
||||
optimize: function(pName, pParams) {
|
||||
var lRet;
|
||||
|
||||
if (Minify) {
|
||||
pParams.name = Minify.getName(pName);
|
||||
|
||||
lRet = this.allowed.css || this.allowed.js || this.allowed.html;
|
||||
lRet = this.allowed;
|
||||
|
||||
if(!this.MinFolder)
|
||||
this.MinFolder = Minify.MinFolder;
|
||||
|
|
@ -75,12 +67,8 @@
|
|||
});
|
||||
}
|
||||
else {
|
||||
this.allowed = {
|
||||
js : false,
|
||||
css : false,
|
||||
html : false
|
||||
};
|
||||
|
||||
this.allowed = false;
|
||||
|
||||
Util.log(COULD_NOT_MINIFY);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue