mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-21 10:38:26 +00:00
minor changes
This commit is contained in:
parent
46f9cf7e87
commit
41c5b1d836
2 changed files with 241 additions and 240 deletions
445
cloudcmd.js
445
cloudcmd.js
|
|
@ -1,223 +1,224 @@
|
|||
(function(){
|
||||
'use strict';
|
||||
|
||||
var DIR = __dirname + '/',
|
||||
main = require(DIR + 'lib/server/main'),
|
||||
|
||||
LIBDIR = main.LIBDIR,
|
||||
SRVDIR = main.SRVDIR,
|
||||
CLIENTDIR = LIBDIR + 'client',
|
||||
|
||||
path = main.path,
|
||||
fs = main.fs,
|
||||
CloudFunc = main.cloudfunc,
|
||||
AppCache = main.appcache,
|
||||
Util = main.util,
|
||||
update = main.update,
|
||||
|
||||
server = main.librequire('server'),
|
||||
Minify = main.minify,
|
||||
Config = main.config,
|
||||
|
||||
REQUEST = 'request',
|
||||
RESPONSE = 'response',
|
||||
INDEX = DIR + 'html' + main.SLASH + 'index.html';
|
||||
|
||||
/* reinit main dir os if we on
|
||||
* Win32 should be backslashes */
|
||||
DIR = main.DIR;
|
||||
|
||||
readConfig();
|
||||
server.start(Config, {
|
||||
appcache : appCacheProcessing,
|
||||
minimize : minimize,
|
||||
rest : rest,
|
||||
route : route
|
||||
});
|
||||
|
||||
if(update)
|
||||
update.get();
|
||||
|
||||
/**
|
||||
* additional processing of index file
|
||||
*/
|
||||
function indexProcessing(pData){
|
||||
var lReplace_s,
|
||||
lData = pData.data,
|
||||
lAdditional = pData.additional;
|
||||
|
||||
/*
|
||||
* если выбрана опция минимизировать скрипты
|
||||
* меняем в index.html обычные css на
|
||||
* минифицированый
|
||||
*/
|
||||
if(Minify.allowed.css){
|
||||
var lPath = '/' + Minify.MinFolder.replace(DIR, '');
|
||||
lReplace_s = '<link rel=stylesheet href="/css/reset.css">';
|
||||
lData = Util.removeStr(lData, lReplace_s)
|
||||
.replace('/css/style.css', lPath + 'all.min.css');
|
||||
}
|
||||
|
||||
/* меняем title */
|
||||
lReplace_s = '<div id=fm class=no-js>';
|
||||
lData = lData.replace(lReplace_s, lReplace_s + lAdditional)
|
||||
.replace('<title>Cloud Commander</title>',
|
||||
'<title>' + CloudFunc.getTitle() + '</title>');
|
||||
|
||||
if(!Config.appcache)
|
||||
lData = Util.removeStr(lData, ' manifest="/cloudcmd.appcache"');
|
||||
|
||||
if(!Config.show_keys_panel){
|
||||
var lKeysPanel = '<div id=keyspanel';
|
||||
lData = lData.replace(lKeysPanel, lKeysPanel +' class=hidden');
|
||||
}
|
||||
|
||||
return lData;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* init and process of appcache if it allowed in config
|
||||
*/
|
||||
function appCacheProcessing(){
|
||||
var 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(Config.minification.css)
|
||||
lFiles.push('node_modules/minify/min/all.min.css');
|
||||
|
||||
AppCache.addFiles(lFiles);
|
||||
AppCache.createManifest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Функция минимизирует css/js/html
|
||||
* если установлены параметры минимизации
|
||||
*/
|
||||
function minimize(pAllowed){
|
||||
var lOptimizeParams = [],
|
||||
lStyleCSS = DIR + 'css/style.css',
|
||||
lResetCSS = DIR + 'css/reset.css',
|
||||
|
||||
lCSSOptions = {
|
||||
img : pAllowed.img,
|
||||
merge : true
|
||||
};
|
||||
|
||||
if (pAllowed.js)
|
||||
lOptimizeParams.push(LIBDIR + 'client.js');
|
||||
|
||||
if (pAllowed.html)
|
||||
lOptimizeParams.push(INDEX);
|
||||
|
||||
if (pAllowed.css) {
|
||||
var lStyles = [{}, {}];
|
||||
lStyles[0][lStyleCSS] = lCSSOptions;
|
||||
lStyles[1][lResetCSS] = lCSSOptions;
|
||||
|
||||
lOptimizeParams.push(lStyles[0]);
|
||||
lOptimizeParams.push(lStyles[1]);
|
||||
}
|
||||
|
||||
if (lOptimizeParams.length)
|
||||
Minify.optimize(lOptimizeParams, {
|
||||
force: true
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* rest interface
|
||||
* @pConnectionData {request, responce}
|
||||
*/
|
||||
function rest(pConnectionData){
|
||||
return Util.exec(main.rest, pConnectionData);
|
||||
}
|
||||
|
||||
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 ){
|
||||
Util.log('current dir: ' + DIR);
|
||||
process.chdir(lServerDir);
|
||||
}
|
||||
Util.log('server dir: ' + lServerDir);
|
||||
Util.log('reading configuretion file config.json...');
|
||||
|
||||
if(Config){
|
||||
Util.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') {
|
||||
Util.log(process.argv);
|
||||
Config.server =
|
||||
Config.logs = false;
|
||||
}
|
||||
|
||||
if (Config.logs) {
|
||||
Util.log('log param setted up in config.json\n' +
|
||||
'from now all logs will be writed to log.txt');
|
||||
writeLogsToFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* routing of server queries
|
||||
*/
|
||||
function route(pParams){
|
||||
var lRet,
|
||||
lName = pParams.name;
|
||||
|
||||
if( Util.strCmp(lName, '/auth') ){
|
||||
Util.log('* Routing' +
|
||||
'-> auth');
|
||||
|
||||
pParams.name = main.HTMLDIR + lName + '.html';
|
||||
lRet = main.sendFile(pParams);
|
||||
}else if( Util.strCmp(lName, '/auth/github') ){
|
||||
Util.log('* Routing' +
|
||||
'-> github');
|
||||
|
||||
pParams.name = main.HTMLDIR + lName + '.html';
|
||||
lRet = main.sendFile(pParams);
|
||||
}else if( Util.isContainStr(lName, CloudFunc.FS) ||
|
||||
Util.isContainStr(lName, CloudFunc.NO_JS ) ||
|
||||
Util.strCmp(lName, '/') ||
|
||||
Util.strCmp(lName, 'json') ){
|
||||
|
||||
lRet = main.commander.sendContent({
|
||||
request : pParams[REQUEST],
|
||||
response : pParams[RESPONSE],
|
||||
processing : indexProcessing,
|
||||
index : Minify.allowed.html ? Minify.getName(INDEX) : INDEX
|
||||
});
|
||||
}
|
||||
|
||||
return lRet;
|
||||
}
|
||||
|
||||
|
||||
/* 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);
|
||||
}
|
||||
(function(){
|
||||
'use strict';
|
||||
|
||||
var DIR = __dirname + '/',
|
||||
main = require(DIR + 'lib/server/main'),
|
||||
|
||||
LIBDIR = main.LIBDIR,
|
||||
SRVDIR = main.SRVDIR,
|
||||
CLIENTDIR = LIBDIR + 'client',
|
||||
HTMLDIR = main.HTMLDIR,
|
||||
|
||||
path = main.path,
|
||||
fs = main.fs,
|
||||
CloudFunc = main.cloudfunc,
|
||||
AppCache = main.appcache,
|
||||
Util = main.util,
|
||||
update = main.update,
|
||||
|
||||
server = main.librequire('server'),
|
||||
Minify = main.minify,
|
||||
Config = main.config,
|
||||
|
||||
REQUEST = 'request',
|
||||
RESPONSE = 'response',
|
||||
INDEX = HTMLDIR + 'index.html';
|
||||
|
||||
/* reinit main dir os if we on
|
||||
* Win32 should be backslashes */
|
||||
DIR = main.DIR;
|
||||
|
||||
readConfig();
|
||||
server.start(Config, {
|
||||
appcache : appCacheProcessing,
|
||||
minimize : minimize,
|
||||
rest : rest,
|
||||
route : route
|
||||
});
|
||||
|
||||
if(update)
|
||||
update.get();
|
||||
|
||||
/**
|
||||
* additional processing of index file
|
||||
*/
|
||||
function indexProcessing(pData){
|
||||
var lReplace_s,
|
||||
lData = pData.data,
|
||||
lAdditional = pData.additional;
|
||||
|
||||
/*
|
||||
* если выбрана опция минимизировать скрипты
|
||||
* меняем в index.html обычные css на
|
||||
* минифицированый
|
||||
*/
|
||||
if(Minify.allowed.css){
|
||||
var lPath = '/' + Minify.MinFolder.replace(DIR, '');
|
||||
lReplace_s = '<link rel=stylesheet href="/css/reset.css">';
|
||||
lData = Util.removeStr(lData, lReplace_s)
|
||||
.replace('/css/style.css', lPath + 'all.min.css');
|
||||
}
|
||||
|
||||
/* меняем title */
|
||||
lReplace_s = '<div id=fm class=no-js>';
|
||||
lData = lData.replace(lReplace_s, lReplace_s + lAdditional)
|
||||
.replace('<title>Cloud Commander</title>',
|
||||
'<title>' + CloudFunc.getTitle() + '</title>');
|
||||
|
||||
if(!Config.appcache)
|
||||
lData = Util.removeStr(lData, ' manifest="/cloudcmd.appcache"');
|
||||
|
||||
if(!Config.show_keys_panel){
|
||||
var lKeysPanel = '<div id=keyspanel';
|
||||
lData = lData.replace(lKeysPanel, lKeysPanel +' class=hidden');
|
||||
}
|
||||
|
||||
return lData;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* init and process of appcache if it allowed in config
|
||||
*/
|
||||
function appCacheProcessing(){
|
||||
var 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(Config.minification.css)
|
||||
lFiles.push('node_modules/minify/min/all.min.css');
|
||||
|
||||
AppCache.addFiles(lFiles);
|
||||
AppCache.createManifest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Функция минимизирует css/js/html
|
||||
* если установлены параметры минимизации
|
||||
*/
|
||||
function minimize(pAllowed){
|
||||
var lOptimizeParams = [],
|
||||
lStyleCSS = DIR + 'css/style.css',
|
||||
lResetCSS = DIR + 'css/reset.css',
|
||||
|
||||
lCSSOptions = {
|
||||
img : pAllowed.img,
|
||||
merge : true
|
||||
};
|
||||
|
||||
if (pAllowed.js)
|
||||
lOptimizeParams.push(LIBDIR + 'client.js');
|
||||
|
||||
if (pAllowed.html)
|
||||
lOptimizeParams.push(INDEX);
|
||||
|
||||
if (pAllowed.css) {
|
||||
var lStyles = [{}, {}];
|
||||
lStyles[0][lStyleCSS] = lCSSOptions;
|
||||
lStyles[1][lResetCSS] = lCSSOptions;
|
||||
|
||||
lOptimizeParams.push(lStyles[0]);
|
||||
lOptimizeParams.push(lStyles[1]);
|
||||
}
|
||||
|
||||
if (lOptimizeParams.length)
|
||||
Minify.optimize(lOptimizeParams, {
|
||||
force: true
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* rest interface
|
||||
* @pConnectionData {request, responce}
|
||||
*/
|
||||
function rest(pConnectionData){
|
||||
return Util.exec(main.rest, pConnectionData);
|
||||
}
|
||||
|
||||
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 ){
|
||||
Util.log('current dir: ' + DIR);
|
||||
process.chdir(lServerDir);
|
||||
}
|
||||
Util.log('server dir: ' + lServerDir);
|
||||
Util.log('reading configuretion file config.json...');
|
||||
|
||||
if(Config){
|
||||
Util.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') {
|
||||
Util.log(process.argv);
|
||||
Config.server =
|
||||
Config.logs = false;
|
||||
}
|
||||
|
||||
if (Config.logs) {
|
||||
Util.log('log param setted up in config.json\n' +
|
||||
'from now all logs will be writed to log.txt');
|
||||
writeLogsToFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* routing of server queries
|
||||
*/
|
||||
function route(pParams){
|
||||
var lRet,
|
||||
lName = pParams.name;
|
||||
|
||||
if( Util.strCmp(lName, '/auth') ){
|
||||
Util.log('* Routing' +
|
||||
'-> auth');
|
||||
|
||||
pParams.name = main.HTMLDIR + lName + '.html';
|
||||
lRet = main.sendFile(pParams);
|
||||
}else if( Util.strCmp(lName, '/auth/github') ){
|
||||
Util.log('* Routing' +
|
||||
'-> github');
|
||||
|
||||
pParams.name = main.HTMLDIR + lName + '.html';
|
||||
lRet = main.sendFile(pParams);
|
||||
}else if( Util.isContainStr(lName, CloudFunc.FS) ||
|
||||
Util.isContainStr(lName, CloudFunc.NO_JS ) ||
|
||||
Util.strCmp(lName, '/') ||
|
||||
Util.strCmp(lName, 'json') ){
|
||||
|
||||
lRet = main.commander.sendContent({
|
||||
request : pParams[REQUEST],
|
||||
response : pParams[RESPONSE],
|
||||
processing : indexProcessing,
|
||||
index : Minify.allowed.html ? Minify.getName(INDEX) : INDEX
|
||||
});
|
||||
}
|
||||
|
||||
return lRet;
|
||||
}
|
||||
|
||||
|
||||
/* 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);
|
||||
}
|
||||
})();
|
||||
|
|
@ -1,18 +1,18 @@
|
|||
|
||||
/* c9.io kill active node process */
|
||||
|
||||
(function(){
|
||||
'use strict';
|
||||
|
||||
var exec = require('child_process').exec,
|
||||
lCmd = 'kill -9' + ' ' + /* kill finded process */
|
||||
'`ps ax' + '|' + /* show all process */
|
||||
'grep node-openshift' + '|' + /* find node-openshift */
|
||||
'grep -v grep' + '|' + /* exlude grep command */
|
||||
'awk "{print $1}"`'; /* show first collumn */
|
||||
|
||||
exec(lCmd, function(error, stdout, stderr){
|
||||
console.log(error || stdout || stderr);
|
||||
});
|
||||
|
||||
})();
|
||||
#!/usr/bin/env node
|
||||
/* c9.io kill active node process */
|
||||
|
||||
(function(){
|
||||
'use strict';
|
||||
|
||||
var exec = require('child_process').exec,
|
||||
lCmd = 'kill -9' + ' ' + /* kill finded process */
|
||||
'`ps ax' + '|' + /* show all process */
|
||||
'grep node-openshift' + '|' + /* find node-openshift */
|
||||
'grep -v grep' + '|' + /* exlude grep command */
|
||||
'awk "{print $1}"`'; /* show first collumn */
|
||||
|
||||
exec(lCmd, function(error, stdout, stderr){
|
||||
console.log(error || stdout || stderr);
|
||||
});
|
||||
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue