From a25708700e58ea1d702aa75c8df7b2a677769b33 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Fri, 2 Nov 2012 04:06:28 -0400 Subject: [PATCH] minor changes --- cloudcmd.js | 241 +++++++++--------- .../storage/github/lib/underscore-min.js | 31 --- lib/server/appcache.js | 2 +- lib/server/srvfunc.js | 2 + 4 files changed, 120 insertions(+), 156 deletions(-) delete mode 100644 lib/client/storage/github/lib/underscore-min.js diff --git a/cloudcmd.js b/cloudcmd.js index 0a53e35e..1bfe096f 100644 --- a/cloudcmd.js +++ b/cloudcmd.js @@ -1,124 +1,117 @@ -"use strict"; - -var DIR = process.cwd() + '/', - LIBDIR = DIR + 'lib/', - SRVDIR = LIBDIR + 'server/', - - srvfunc = require(SRVDIR + 'srvfunc'), - path = require('path'), - fs = require('fs'), - Server = srvfunc.require(DIR + 'server'), - CloudFunc = srvfunc.require(LIBDIR +'cloudfunc'), - update = srvfunc.require(SRVDIR + 'update'), - - srv = Server.CloudServer, - Config = readConfig(); - -Server.start(Config, indexProcessing); - -if(update) - update.get(); - -function indexProcessing(pIndex, pList){ - var lWin32 = process.platform === 'win32'; - - /* если выбрана опция минифизировать скрпиты - * меняем в index.html обычные css на - * минифицированый - */ - if(srv.Minify._allowed.css){ - var lReplace_s = ''; - else - lReplace_s = lReplace_s + '"/css/reset.css">'; - - pIndex = pIndex.replace(lReplace_s, ''); - pIndex = pIndex.replace('/css/style.css', srv.Minify.MinFolder + 'all.min.css'); - } - - pIndex = pIndex.replace('
', - '
'+ pList); - - /* меняем title */ - pIndex = pIndex.replace('Cloud Commander', - '' + CloudFunc.setTitle() + ''); - - if(!srv.Config.appcache){ - if(lWin32) - pIndex = pIndex.replace(' manifest=/cloudcmd.appcache', ''); - else - pIndex = pIndex.replace(' manifest="/cloudcmd.appcache"', ''); - } - - return pIndex; - -} - -function appCacheProcessing(){ - var lAppCache = srv.AppCache, - - lFiles = [{'//themes.googleusercontent.com/static/fonts/droidsansmono/v4/ns-m2xQYezAtqh7ai59hJUYuTAAIFFn5GTWtryCmBQ4.woff' : './font/DroidSansMono.woff'}, - {'//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js' : './lib/client/jquery.js'}]; - - if(srv.Minify._allowed.css) - lFiles.push('./min/all.min.css'); - - lAppCache.addFiles(lFiles); - lAppCache.createManifest(); -} - -function readConfig(){ - - /* Determining server.js directory - * and chang current process directory - * (usually /) to it. - * argv[1] - is always script name - */ - var lServerDir = path.dirname(process.argv[1]), - lProcessDir = process.cwd(); - lConfig = {}; - - if(lProcessDir !== lServerDir){ - console.log('current dir: ' + lProcessDir); - process.chdir(lServerDir); - } - console.log('server dir: ' + lServerDir); - - console.log('reading configuretion file config.json...'); - var lConfig = srvfunc.require(DIR + 'config'); - if(lConfig){ - console.log('config.json readed'); - - /* if command line parameter testing resolved - * setting config to testing, so server - * not created, just init and - * all logs writed to screen - */ - var lArg = process.argv[process.argv.length - 1]; - if ( lArg === 'test' || lArg === 'test\r') { - console.log(process.argv); - lConfig.server = false; - lConfig.logs = false; - } - - if (lConfig.logs) { - console.log('log param setted up in config.json\n' + - 'from now all logs will be writed to log.txt'); - writeLogsToFile(); - } - } - - return lConfig; -} - -/* function sets stdout to file log.txt */ -function writeLogsToFile(){ - var stdo = fs.createWriteStream('./log.txt'); - - process.stdout.write = (function(write) { - return function(string, encoding, fd) { - stdo.write(string); - }; - })(process.stdout.write); -} +"use strict"; + +var DIR = process.cwd() + '/', + LIBDIR = DIR + 'lib/', + SRVDIR = LIBDIR + 'server/', + + srvfunc = require(SRVDIR + 'srvfunc'), + path = require('path'), + fs = require('fs'), + Server = srvfunc.require(DIR + 'server'), + CloudFunc = srvfunc.require(LIBDIR + 'cloudfunc'), + Util = srvfunc.require(LIBDIR + 'util'), + update = srvfunc.require(SRVDIR + 'update'), + + srv = Server.CloudServer, + Config = srvfunc.require(DIR + 'config'); + + +readConfig(); +Server.start(Config, indexProcessing, appCacheProcessing); + +if(update) + update.get(); + + +function indexProcessing(pIndex, pList){ + /* если выбрана опция минифизировать скрпиты + * меняем в index.html обычные css на + * минифицированый + */ + if(srv.Minify._allowed.css){ + var lReplace_s = '' : '"/css/reset.css">'); + + pIndex = Util.removeStr(pIndex, lReplace_s); + pIndex = pIndex.replace('/css/style.css', srv.Minify.MinFolder + 'all.min.css'); + } + + pIndex = pIndex.replace('
', + '
'+ pList); + + /* меняем title */ + pIndex = pIndex.replace('Cloud Commander', + '' + CloudFunc.setTitle() + ''); + + if(!srv.Config.appcache) + pIndex = srvfunc.isWin32 ? + Util.removeStr(pIndex, ' manifest=/cloudcmd.appcache') : + Util.removeStr(pIndex, ' manifest="/cloudcmd.appcache"'); + + return pIndex; + +} + +function appCacheProcessing(){ + var lAppCache = srv.AppCache, + + lFiles = [{'//themes.googleusercontent.com/static/fonts/droidsansmono/v4/ns-m2xQYezAtqh7ai59hJUYuTAAIFFn5GTWtryCmBQ4.woff' : './font/DroidSansMono.woff'}, + {'//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js' : './lib/client/jquery.js'}]; + + if(srv.Minify._allowed.css) + lFiles.push('./min/all.min.css'); + + lAppCache.addFiles(lFiles); + lAppCache.createManifest(); +} + +function readConfig(){ + + /* Determining server.js directory + * and chang current process directory + * (usually /) to it. + * argv[1] - is always script name + */ + var lServerDir = path.dirname(process.argv[1]); + + if( DIR !== lServerDir ){ + console.log('current dir: ' + lProcessDir); + process.chdir(lServerDir); + } + console.log('server dir: ' + lServerDir + '\n' + + 'reading configuretion file config.json...'); + + if(Config){ + console.log('config.json readed'); + + /* if command line parameter testing resolved + * setting config to testing, so server + * not created, just init and + * all logs writed to screen + */ + var lArg = process.argv; + lArg = lArg[lArg.length - 1]; + if ( lArg === 'test' || lArg === 'test\r') { + console.log(process.argv); + Config.server = + Config.logs = false; + } + + if (Config.logs) { + console.log('log param setted up in config.json\n' + + 'from now all logs will be writed to log.txt'); + writeLogsToFile(); + } + } +} + +/* function sets stdout to file log.txt */ +function writeLogsToFile(){ + var stdo = fs.createWriteStream('./log.txt'); + + process.stdout.write = (function(write) { + return function(string, encoding, fd) { + stdo.write(string); + }; + })(process.stdout.write); +} diff --git a/lib/client/storage/github/lib/underscore-min.js b/lib/client/storage/github/lib/underscore-min.js deleted file mode 100644 index 5b55f32b..00000000 --- a/lib/client/storage/github/lib/underscore-min.js +++ /dev/null @@ -1,31 +0,0 @@ -// Underscore.js 1.3.1 -// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. -// Underscore is freely distributable under the MIT license. -// Portions of Underscore are inspired or borrowed from Prototype, -// Oliver Steele's Functional, and John Resig's Micro-Templating. -// For all details and documentation: -// http://documentcloud.github.com/underscore -(function(){function q(a,c,d){if(a===c)return a!==0||1/a==1/c;if(a==null||c==null)return a===c;if(a._chain)a=a._wrapped;if(c._chain)c=c._wrapped;if(a.isEqual&&b.isFunction(a.isEqual))return a.isEqual(c);if(c.isEqual&&b.isFunction(c.isEqual))return c.isEqual(a);var e=l.call(a);if(e!=l.call(c))return false;switch(e){case "[object String]":return a==String(c);case "[object Number]":return a!=+a?c!=+c:a==0?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source== -c.source&&a.global==c.global&&a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if(typeof a!="object"||typeof c!="object")return false;for(var f=d.length;f--;)if(d[f]==a)return true;d.push(a);var f=0,g=true;if(e=="[object Array]"){if(f=a.length,g=f==c.length)for(;f--;)if(!(g=f in a==f in c&&q(a[f],c[f],d)))break}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return false;for(var h in a)if(b.has(a,h)&&(f++,!(g=b.has(c,h)&&q(a[h],c[h],d))))break;if(g){for(h in c)if(b.has(c, -h)&&!f--)break;g=!f}}d.pop();return g}var r=this,G=r._,n={},k=Array.prototype,o=Object.prototype,i=k.slice,H=k.unshift,l=o.toString,I=o.hasOwnProperty,w=k.forEach,x=k.map,y=k.reduce,z=k.reduceRight,A=k.filter,B=k.every,C=k.some,p=k.indexOf,D=k.lastIndexOf,o=Array.isArray,J=Object.keys,s=Function.prototype.bind,b=function(a){return new m(a)};if(typeof exports!=="undefined"){if(typeof module!=="undefined"&&module.exports)exports=module.exports=b;exports._=b}else r._=b;b.VERSION="1.3.1";var j=b.each= -b.forEach=function(a,c,d){if(a!=null)if(w&&a.forEach===w)a.forEach(c,d);else if(a.length===+a.length)for(var e=0,f=a.length;e2;a== -null&&(a=[]);if(y&&a.reduce===y)return e&&(c=b.bind(c,e)),f?a.reduce(c,d):a.reduce(c);j(a,function(a,b,i){f?d=c.call(e,d,a,b,i):(d=a,f=true)});if(!f)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){var f=arguments.length>2;a==null&&(a=[]);if(z&&a.reduceRight===z)return e&&(c=b.bind(c,e)),f?a.reduceRight(c,d):a.reduceRight(c);var g=b.toArray(a).reverse();e&&!f&&(c=b.bind(c,e));return f?b.reduce(g,c,d,e):b.reduce(g,c)};b.find=b.detect= -function(a,c,b){var e;E(a,function(a,g,h){if(c.call(b,a,g,h))return e=a,true});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(A&&a.filter===A)return a.filter(c,b);j(a,function(a,g,h){c.call(b,a,g,h)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;j(a,function(a,g,h){c.call(b,a,g,h)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,b){var e=true;if(a==null)return e;if(B&&a.every===B)return a.every(c,b);j(a,function(a,g,h){if(!(e= -e&&c.call(b,a,g,h)))return n});return e};var E=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(C&&a.some===C)return a.some(c,d);j(a,function(a,b,h){if(e||(e=c.call(d,a,b,h)))return n});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;return p&&a.indexOf===p?a.indexOf(c)!=-1:b=E(a,function(a){return a===c})};b.invoke=function(a,c){var d=i.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)?c||a:a[c]).apply(a,d)})};b.pluck= -function(a,c){return b.map(a,function(a){return a[c]})};b.max=function(a,c,d){if(!c&&b.isArray(a))return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a))return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;bd?1:0}),"value")};b.groupBy=function(a,c){var d={},e=b.isFunction(c)?c:function(a){return a[c]};j(a,function(a,b){var c=e(a,b);(d[c]||(d[c]=[])).push(a)});return d};b.sortedIndex=function(a, -c,d){d||(d=b.identity);for(var e=0,f=a.length;e>1;d(a[g])=0})})};b.difference=function(a){var c=b.flatten(i.call(arguments,1));return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=i.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e=0;d--)b=[a[d].apply(this,b)];return b[0]}}; -b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=J||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a,d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]=b[d]});return a};b.defaults=function(a){j(i.call(arguments, -1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};b.isEqual=function(a,b){return q(a,b,[])};b.isEmpty=function(a){if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(b.has(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=o||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)}; -b.isArguments=function(a){return l.call(a)=="[object Arguments]"};if(!b.isArguments(arguments))b.isArguments=function(a){return!(!a||!b.has(a,"callee"))};b.isFunction=function(a){return l.call(a)=="[object Function]"};b.isString=function(a){return l.call(a)=="[object String]"};b.isNumber=function(a){return l.call(a)=="[object Number]"};b.isNaN=function(a){return a!==a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isDate=function(a){return l.call(a)=="[object Date]"}; -b.isRegExp=function(a){return l.call(a)=="[object RegExp]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.has=function(a,b){return I.call(a,b)};b.noConflict=function(){r._=G;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")};b.mixin=function(a){j(b.functions(a), -function(c){K(c,b[c]=a[c])})};var L=0;b.uniqueId=function(a){var b=L++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var t=/.^/,u=function(a){return a.replace(/\\\\/g,"\\").replace(/\\'/g,"'")};b.template=function(a,c){var d=b.templateSettings,d="var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('"+a.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(d.escape||t,function(a,b){return"',_.escape("+ -u(b)+"),'"}).replace(d.interpolate||t,function(a,b){return"',"+u(b)+",'"}).replace(d.evaluate||t,function(a,b){return"');"+u(b).replace(/[\r\n\t]/g," ")+";__p.push('"}).replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t")+"');}return __p.join('');",e=new Function("obj","_",d);return c?e(c,b):function(a){return e.call(this,a,b)}};b.chain=function(a){return b(a).chain()};var m=function(a){this._wrapped=a};b.prototype=m.prototype;var v=function(a,c){return c?b(a).chain():a},K=function(a,c){m.prototype[a]= -function(){var a=i.call(arguments);H.call(a,this._wrapped);return v(c.apply(b,a),this._chain)}};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var b=k[a];m.prototype[a]=function(){var d=this._wrapped;b.apply(d,arguments);var e=d.length;(a=="shift"||a=="splice")&&e===0&&delete d[0];return v(d,this._chain)}});j(["concat","join","slice"],function(a){var b=k[a];m.prototype[a]=function(){return v(b.apply(this._wrapped,arguments),this._chain)}});m.prototype.chain=function(){this._chain= -true;return this};m.prototype.value=function(){return this._wrapped}}).call(this); diff --git a/lib/server/appcache.js b/lib/server/appcache.js index 97307f4d..a0f732bf 100644 --- a/lib/server/appcache.js +++ b/lib/server/appcache.js @@ -88,7 +88,7 @@ exports.watch = function(pFileName){ }; function setWatachFunctions(){ - if(process.platform === 'win32'){ + if(srvfunc.isWin32){ /* good on windows */ fs_watch = fs.watch; on_fs_watch = onWatch; diff --git a/lib/server/srvfunc.js b/lib/server/srvfunc.js index 07f11504..9ce667c6 100644 --- a/lib/server/srvfunc.js +++ b/lib/server/srvfunc.js @@ -22,4 +22,6 @@ return lModule; }; + + exports.isWin32 = process.platform === 'win32'; }()); \ No newline at end of file