moving out doit from minify to cloudcmd

This commit is contained in:
coderaiser 2012-12-27 05:23:08 -05:00
parent b2463867d7
commit 02f8648c19
3 changed files with 73 additions and 80 deletions

View file

@ -26,6 +26,7 @@
Server.start(Config, {
appcache : appCacheProcessing,
index : indexProcessing,
minimize : minimize,
rest : rest,
route : route
});
@ -38,7 +39,7 @@
*/
function indexProcessing(pData){
var lReplace_s,
lData = pData.data,
lData = pData.data,
lAdditional = pData.additional;
/*
@ -88,6 +89,41 @@
lAppCache.createManifest();
}
/**
* Функция минимизирует css/js/html
* если установлены параметры минимизации
*/
function minimize(pAllowed){
var lOptimizeParams = [],
lStyleCSS = DIR + 'css/style.css',
lResetCSS = DIR + 'css/reset.css',
lIndex = DIR + 'html/index.html',
lMinify = Server.Minify;
if (pAllowed.js) {
lOptimizeParams.push(LIBDIR + 'client.js');
}
if (pAllowed.html)
lOptimizeParams.push(lIndex);
if (pAllowed.css) {
var lStyles = [];
lStyles[0] = {};
lStyles[0][lStyleCSS] = pAllowed.img;
lStyles[1] = {};
lStyles[1][lResetCSS] = pAllowed.img;
lOptimizeParams.push(lStyles[0]);
lOptimizeParams.push(lStyles[1]);
}
if (lOptimizeParams.length)
lMinify.optimize(lOptimizeParams);
}
/**
* rest interface
* @pConnectionData {request, responce}

View file

@ -91,11 +91,13 @@
CloudServer.Socket = main.socket;
/* базовая инициализация */
CloudServer.init = (function(pAppCachProcessing){
CloudServer.init = function(pAppCachProcessing){
var lConfig = this.Config,
lMinify = this.Minify,
lCache = this.Cache,
lAppCache = this.AppCache;
lAppCache = this.AppCache,
lMinifyAllowed = lConfig.minification;
/* Переменная в которой храниться кэш*/
lCache.setAllowed(lConfig.cache.allowed);
@ -103,15 +105,15 @@
/* Change default parameters of
* js/css/html minification
*/
lMinify.setAllowed(lConfig.minification);
lMinify.setAllowed(lMinifyAllowed);
/* Если нужно минимизируем скрипты */
lMinify._allowed = lMinify.doit();
Util.exec(CloudServer.minimize, lMinifyAllowed);
/* создаём файл app cache */
if( lConfig.appcache && lAppCache && lConfig.server )
Util.exec( pAppCachProcessing );
});
};
/**
@ -135,6 +137,7 @@
CloudServer.indexProcessing = pProcessing.index;
CloudServer.rest = pProcessing.rest;
CloudServer.route = pProcessing.route;
CloudServer.minimize = pProcessing.minimize;
this.init(pProcessing.appcache);

View file

@ -6,13 +6,15 @@
var main = global.cloudcmd.main,
DIR = main.DIR,
LIBDIR = main.LIBDIR,
HTMLDIR = main.HTMLDIR;
HTMLDIR = main.HTMLDIR,
Minify = main.require('minify');
exports.Minify = {
/* pathes to directories */
INDEX : HTMLDIR + 'index.html',
INDEX : HTMLDIR + 'index.html',
/* приватный переключатель минимизации */
_allowed :{
_allowed : {
css : true,
js : true,
html : true,
@ -34,66 +36,13 @@
*/
setAllowed :(function(pAllowed){
if(pAllowed){
this._allowed = pAllowed;
this._allowed = pAllowed;
}
}),
/*
* Функция минимизирует css/js/html
* если установлены параметры минимизации
*/
doit :(function(){
var lMinify = main.require('minify');
if(!lMinify){
this._allowed = {js:false,css:false,html:false};
console.log('You coud install minify ' +
'for better download spead:\n' +
'npm i minify');
return this._allowed;
}
/*
* temporary changed dir path,
* becouse directory lib is write
* protected by others by default
* so if node process is started
* from other user (root for example
* in nodester) we can not write
* minified versions
*/
this.MinFolder = lMinify.MinFolder;
var lOptimizeParams = [],
lStyleCSS = DIR + 'css/style.css',
lResetCSS = DIR + 'css/reset.css';
if (this._allowed.js) {
lOptimizeParams.push(LIBDIR + 'client.js');
}
if (this._allowed.html)
lOptimizeParams.push(this.INDEX);
if (this._allowed.css) {
var lStyles = [];
lStyles[0] = {};
lStyles[0][lStyleCSS] = this._allowed.img;
lStyles[1] = {};
lStyles[1][lResetCSS] = this._allowed.img;
lOptimizeParams.push(lStyles[0]);
lOptimizeParams.push(lStyles[1]);
}
if (lOptimizeParams.length)
lMinify.optimize(lOptimizeParams);
this.Cache = lMinify.Cache;
return this._allowed;
}),
optimize: function(pName, pParams){
@ -101,21 +50,26 @@
pParams.force = this.force;
if(this._allowed.css ||
this._allowed.js ||
this._allowed.html){
var lMinify = main.require('minify');
if(!this.MinFolder)
this.MinFolder = Minify.MinFolder;
if(!this.Cache)
this.Cache = Minify.Cache;
if(this._allowed.css || this._allowed.js || this._allowed.html){
if(Minify)
Minify.optimize(pName, pParams);
else{
lResult = false;
if(lMinify)
lMinify.optimize(pName, pParams);
else{
lResult = false;
this._allowed = {js:false,css:false,html:false};
console.log('Could not minify ' +
'without minify module\n' +
'npm i minify');
}
this._allowed = {
js : false,
css : false,
html : false};
console.log('Could not minify ' +
'without minify module\n' +
'npm i minify');
}
}
else lResult = false;
@ -124,6 +78,6 @@
/* minification folder name */
MinFolder : '',
Cache : {}
Cache : null
};
})();