From d6b1111325008725bc778a020af28f3931addb35 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Fri, 8 Jun 2012 14:26:56 +0000 Subject: [PATCH] resolved bug with js-minification --- minify.js | 20 ++++++++++++++++---- server.js | 18 +++++++++++++++--- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/minify.js b/minify.js index 3b8b8abd..ea558a05 100644 --- a/minify.js +++ b/minify.js @@ -1,10 +1,14 @@ -/* Модуль сжатия js-скриптов*/ +/* Модуль сжатия js-скриптов и css*/ /* https://github.com/GoalSmashers/clean-css */ -exports.jsScripts=jsScripts; -function jsScripts(){ + + +/* функция сжимает js-скрипты + * и сохраняет их с именем .min.js + */ +exports.jsScripts=function jsScripts(){ 'use strict'; /* подключаем модуль uglify-js @@ -15,11 +19,12 @@ function jsScripts(){ var jsp = require("uglify-js").parser; var pro = require("uglify-js").uglify; }catch(error){ - return console.log('ERROR. error loading minificatoin js\n' + + console.log('ERROR. error loading minificatoin js\n' + 'to use minification you need to install uglify-js\n' + 'npm install uglify-js\n' + 'https://github.com/mishoo/UglifyJS\n' + error); + return false; } var fs = require('fs'); @@ -78,4 +83,11 @@ function jsScripts(){ error?console.log(error):dataReaded(); }; } +}; + +/* функция сжимает css-стили + * и сохраняет их с именем .min.css + */ +exports.cssStyles=function cssStyles(){ + 'use strict'; }; \ No newline at end of file diff --git a/server.js b/server.js index 04f9e310..d40fb5fe 100644 --- a/server.js +++ b/server.js @@ -113,9 +113,15 @@ CloudServer.Minify={ scripts : function(){ if(CloudServer.Minimize.scriptSize){ var lMinify = require('./minify'); - lMinify.jsScripts(); + var lResult_b=lMinify.jsScripts(); + /* if we get false, files wasn't minified + * error ocured + */ + CloudServer.Minify.done=(lResult_b===undefined?true:false); } - } + }, + /* свойство показывающее случилась ли ошибка*/ + done: false }; //var DirContent; @@ -428,7 +434,13 @@ CloudServer._readDir=function (pError, pFiles) * минифицированый */ lIndex=lIndex.toString(); - CloudServer.Minimize.scriptSize? + + /* if scripts shoud be minified and + * minification proceed sucessfully + * we include minified version of + * clien.js to index.html + */ + (CloudServer.Minimize.scriptSize && CloudServer.Minify.done)? lIndex=lIndex.replace('client.js','client.min.js'):''; lIndex=lIndex.toString().replace('
','
'+lList);