mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
added creation folder min, where minimized styles and scripts would be
This commit is contained in:
parent
b71e25379d
commit
555582eccf
1 changed files with 37 additions and 11 deletions
|
|
@ -1,5 +1,7 @@
|
|||
/* Модуль сжатия js-скриптов и css*/
|
||||
|
||||
console.log('minify.js loaded...');
|
||||
|
||||
/* функция сжимает js-скрипты
|
||||
* и сохраняет их с именем .min.js
|
||||
*/
|
||||
|
|
@ -7,15 +9,39 @@
|
|||
var fs = require('fs');
|
||||
var path=require('path');
|
||||
|
||||
var MinFolder='./min/';
|
||||
/* function clear MinFolder
|
||||
* if we could not create
|
||||
* directory and it is
|
||||
* not exist
|
||||
*/
|
||||
var folderExist = function(pError){
|
||||
if(!pError)
|
||||
console.log('folder exist: min');
|
||||
else MinFolder='';
|
||||
};
|
||||
|
||||
/*
|
||||
* function says thet folder created
|
||||
* if everything is OK, or
|
||||
* moves to folderExist function
|
||||
*/
|
||||
var makeFolder = function(pError){
|
||||
if(!pError)
|
||||
console.log('folder created: min');
|
||||
else fs.stat(MinFolder,folderExist);
|
||||
};
|
||||
|
||||
/* Trying to create folder min
|
||||
* where woud be minifyed versions
|
||||
* of files
|
||||
*/
|
||||
fs.mkdir(MinFolder,777,makeFolder);
|
||||
|
||||
/* CONSTANTS */
|
||||
/* dir contains css-files */
|
||||
var CSSDIR = 'css/';
|
||||
|
||||
/* ---------------------------------- */
|
||||
console.log('minify.js loaded...');
|
||||
console.log('current dir: ' + process.cwd());
|
||||
/* ---------------------------------- */
|
||||
|
||||
exports.jsScripts=function jsScripts(){
|
||||
'use strict';
|
||||
|
||||
|
|
@ -81,11 +107,11 @@ exports.jsScripts=function jsScripts(){
|
|||
(final_code=final_code
|
||||
.replace('cloudfunc.js','cloudfunc.min.js')
|
||||
.replace('keyBinding.js','keyBinding.min.js')
|
||||
.replace('/lib','')
|
||||
.replace('/lib/client','')).length);
|
||||
.replace('/lib',MinFolder)
|
||||
.replace('/lib/client',MinFolder)).length);
|
||||
|
||||
/* записываем сжатый js-скрипт*/
|
||||
fs.writeFile(path.basename(minFileName), final_code, fileWrited(minFileName));
|
||||
fs.writeFile(MinFolder+path.basename(minFileName), final_code, fileWrited(minFileName));
|
||||
};
|
||||
console.log('reading file ' + CLIENT_JS+'...');
|
||||
fs.readFile(CLIENT_JS,fileReaded(CLIENT_JS,dataReaded_f));
|
||||
|
|
@ -159,10 +185,10 @@ exports.cssStyles=function cssStyles(pImgConvertToBase64_b){
|
|||
if(pImgConvertToBase64_b)
|
||||
base64_images(lAllStyle);
|
||||
else
|
||||
fs.writeFile('all.min.css', lAllStyle, fileWrited('all.min.css'));
|
||||
fs.writeFile(MinFolder + 'all.min.css', lAllStyle, fileWrited('all.min.css'));
|
||||
}
|
||||
/* в другом случае - записываем сжатый css файл*/
|
||||
else fs.writeFile(path.basename(minFileName), final_code, fileWrited(minFileName));
|
||||
else fs.writeFile(MinFolder + path.basename(minFileName), final_code, fileWrited(minFileName));
|
||||
};
|
||||
|
||||
console.log('reading file ' + STYLE_CSS+'...');
|
||||
|
|
@ -258,7 +284,7 @@ function base64_images(pFileContent_s){
|
|||
}
|
||||
b64img.fromString(pFileContent_s, '.','', function(err, css){
|
||||
console.log('images converted to base64 and saved in css file');
|
||||
fs.writeFile('all.min.css', css, fileWrited('all.min.css'));
|
||||
fs.writeFile(MinFolder + 'all.min.css', css, fileWrited('all.min.css'));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue