mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-20 18:18:56 +00:00
feature(mellow) add from npm
This commit is contained in:
parent
a3e067481e
commit
b6216c4c0f
7 changed files with 10 additions and 192 deletions
|
|
@ -1,60 +0,0 @@
|
|||
(function() {
|
||||
'use strict';
|
||||
|
||||
var DIR = '../',
|
||||
DIR_SERVER = DIR + 'server/',
|
||||
|
||||
isWin = process.platform === 'win32',
|
||||
Util = require(DIR + 'util'),
|
||||
|
||||
win = require(DIR_SERVER + 'win'),
|
||||
flop = require(DIR_SERVER + 'flop');
|
||||
|
||||
exports.read = read;
|
||||
exports.convertPath = convertPath;
|
||||
|
||||
function read(path, callback) {
|
||||
if (isWin && path === '/')
|
||||
getRoot(callback);
|
||||
else
|
||||
flop.read(path, callback);
|
||||
}
|
||||
|
||||
function getRoot(callback) {
|
||||
win.getVolumes(function(error, volumes) {
|
||||
var data = {
|
||||
path : '/',
|
||||
files : []
|
||||
};
|
||||
|
||||
if (!error)
|
||||
data.files = volumes.map(function(volume) {
|
||||
return {
|
||||
name: volume,
|
||||
size: 'dir',
|
||||
mode: '--- --- ---',
|
||||
owner: 0
|
||||
};
|
||||
});
|
||||
|
||||
callback(error, data);
|
||||
});
|
||||
}
|
||||
|
||||
function convertPath(path) {
|
||||
var volume;
|
||||
|
||||
Util.check(arguments, ['path']);
|
||||
|
||||
if (isWin && path !== '/') {
|
||||
volume = path[1];
|
||||
path = path.split('')
|
||||
.slice(2)
|
||||
.join('');
|
||||
|
||||
path = volume + ':' + (path || '\\');
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
})();
|
||||
|
|
@ -24,7 +24,8 @@
|
|||
github = require(DIR + 'github'),
|
||||
flop = require(DIR + 'flop'),
|
||||
packer = require(DIR + 'packer'),
|
||||
mellow = require(DIR + 'mellow'),
|
||||
tryRequire = require('./tryRequire'),
|
||||
mellow = tryRequire('mellow', {log: true, exit: true}),
|
||||
ponse = require(DIR + 'ponse'),
|
||||
pipe = require(DIR + 'pipe'),
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@
|
|||
files = require(DIR_SERVER + 'files'),
|
||||
flop = require(DIR_SERVER + 'flop'),
|
||||
hash = require(DIR_SERVER + 'hash'),
|
||||
mellow = require(DIR_SERVER + 'mellow'),
|
||||
tryRequire = require(DIR_SERVER + 'tryRequire'),
|
||||
mellow = tryRequire('mellow', {log: true, exit: true}),
|
||||
beautify = require(DIR_SERVER + 'beautify'),
|
||||
minify = require(DIR_SERVER + 'minify'),
|
||||
Util = require(DIR + 'util');
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
tryRequire = require(DIR + 'tryRequire'),
|
||||
pipe = require(DIR + 'pipe'),
|
||||
mellow = require(DIR + 'mellow'),
|
||||
mellow = tryRequire('mellow', {log: true, exit: true}),
|
||||
ponse = require(DIR + 'ponse'),
|
||||
|
||||
marked = tryRequire('marked');
|
||||
|
|
|
|||
|
|
@ -9,7 +9,10 @@
|
|||
|
||||
fs = require('fs'),
|
||||
|
||||
mellow = require(DIR_SERVER + 'mellow'),
|
||||
tryRequire = require(DIR_SERVER + 'tryRequire'),
|
||||
|
||||
mellow = tryRequire('mellow', {log: true, exit: true}),
|
||||
|
||||
ponse = require(DIR_SERVER + 'ponse'),
|
||||
files = require(DIR_SERVER + 'files'),
|
||||
minify = require(DIR_SERVER + 'minify'),
|
||||
|
|
|
|||
|
|
@ -1,128 +0,0 @@
|
|||
(function() {
|
||||
'use strict';
|
||||
|
||||
/* win.js
|
||||
* -----------
|
||||
*
|
||||
* used for work with windows specific
|
||||
* functions like volumes.
|
||||
*/
|
||||
|
||||
var spawn = require('child_process').spawn,
|
||||
exec = require('child_process').exec,
|
||||
DIR = '../',
|
||||
DIR_SERVER = DIR + 'server/',
|
||||
Util = require(DIR + 'util'),
|
||||
pipe = require(DIR_SERVER + 'pipe'),
|
||||
|
||||
WIN = process.platform === 'win32',
|
||||
WIN_VOLUME = '^[a-z]{1}:$';
|
||||
|
||||
exports.getVolumes = getVolumes;
|
||||
exports.prepareCodePage = prepareCodePage;
|
||||
|
||||
exports.isVolume = isVolume;
|
||||
exports.isChangeVolume = isChangeVolume;
|
||||
|
||||
function getVolumes(callback) {
|
||||
var wmic = spawn('wmic', ['logicaldisk', 'get', 'name']);
|
||||
|
||||
Util.check(arguments, ['callback']);
|
||||
|
||||
/* stream should be closed on win xp*/
|
||||
wmic.stdin.end();
|
||||
|
||||
pipe.getBody(wmic.stdout, function(error, data) {
|
||||
if (error)
|
||||
callback(error);
|
||||
else
|
||||
parse(data, callback);
|
||||
});
|
||||
|
||||
wmic.stderr.on('data', callback);
|
||||
wmic.on('error', callback);
|
||||
}
|
||||
|
||||
function parse(data, callback) {
|
||||
var volumes = [],
|
||||
strDrop = [
|
||||
'\r', '\n',
|
||||
'Name', ' ',
|
||||
];
|
||||
|
||||
if (data) {
|
||||
volumes = Util.rmStr(data, strDrop)
|
||||
.split(':');
|
||||
|
||||
volumes.pop();
|
||||
}
|
||||
|
||||
callback(null, volumes);
|
||||
}
|
||||
|
||||
function prepareCodePage() {
|
||||
/* if we on windows and command is build in
|
||||
* change code page to unicode becouse
|
||||
* windows use unicode on non English versions
|
||||
*/
|
||||
|
||||
if (process.platform === 'win32')
|
||||
getCodePage(function(codepage) {
|
||||
if (codepage) {
|
||||
process.on('SIGINT', function() {
|
||||
exec('chcp ' + codepage, function() {
|
||||
process.exit();
|
||||
});
|
||||
});
|
||||
|
||||
exec('chcp 65001', function(error, stdout, stderror) {
|
||||
if (error)
|
||||
console.log(error);
|
||||
|
||||
if (stderror)
|
||||
console.log(stderror);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getCodePage(callback) {
|
||||
exec('chcp', function(error, stdout, stderror) {
|
||||
var index, codepage;
|
||||
|
||||
if (!error && !stderror && stdout) {
|
||||
index = stdout.indexOf(':');
|
||||
codepage = stdout.slice(index + 2);
|
||||
}
|
||||
|
||||
callback(codepage);
|
||||
});
|
||||
}
|
||||
|
||||
function isVolume(command) {
|
||||
var is, winVolume;
|
||||
|
||||
Util.check(arguments, ['command']);
|
||||
|
||||
if (WIN) {
|
||||
winVolume = new RegExp(WIN_VOLUME + '\\\\.*', 'i');
|
||||
is = command.match(winVolume);
|
||||
}
|
||||
|
||||
return is;
|
||||
}
|
||||
|
||||
function isChangeVolume(command) {
|
||||
var is, winVolume;
|
||||
|
||||
Util.check(arguments, ['command']);
|
||||
|
||||
if (WIN) {
|
||||
winVolume = new RegExp(WIN_VOLUME, 'i');
|
||||
is = command.match(winVolume);
|
||||
}
|
||||
|
||||
return is;
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
@ -32,6 +32,7 @@
|
|||
"http-auth": "2.1.x",
|
||||
"js-beautify": "~1.5.4",
|
||||
"marked": "~0.3.2",
|
||||
"mellow": "~0.9.7",
|
||||
"minify": "~1.3.0",
|
||||
"mkdirp": "~0.5.0",
|
||||
"nicki": "~1.2.0",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue