mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-19 01:17:18 +00:00
moving out doit from minify to cloudcmd
This commit is contained in:
parent
b2463867d7
commit
02f8648c19
3 changed files with 73 additions and 80 deletions
|
|
@ -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
|
||||
};
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue