mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature(cloudcmd) es2015-ify
This commit is contained in:
parent
7a23dbfb30
commit
629967b7d1
5 changed files with 114 additions and 103 deletions
6
.babelrc
Normal file
6
.babelrc
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"presets": [
|
||||||
|
"es2015"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -15,3 +15,5 @@ modules/fancybox/sprite.psd
|
||||||
|
|
||||||
*.swp
|
*.swp
|
||||||
|
|
||||||
|
bin-legacy
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,5 +10,8 @@ app.json
|
||||||
circle.yml
|
circle.yml
|
||||||
|
|
||||||
bin/release.js
|
bin/release.js
|
||||||
|
|
||||||
legacy
|
legacy
|
||||||
|
|
||||||
|
bin-legacy/release.js
|
||||||
|
|
||||||
|
|
|
||||||
195
bin/cloudcmd.js
195
bin/cloudcmd.js
|
|
@ -2,73 +2,69 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var Info = require('../package'),
|
const Info = require('../package');
|
||||||
DIR = __dirname + '/../',
|
const DIR = __dirname + '/../';
|
||||||
DIR_LIB = DIR + 'lib/',
|
const DIR_LIB = DIR + 'lib/';
|
||||||
DIR_SERVER = DIR_LIB + 'server/',
|
const DIR_SERVER = DIR_LIB + 'server/';
|
||||||
|
|
||||||
exit = require(DIR_SERVER + 'exit'),
|
const exit = require(DIR_SERVER + 'exit');
|
||||||
config = require(DIR_SERVER + 'config'),
|
const config = require(DIR_SERVER + 'config');
|
||||||
|
|
||||||
options,
|
const argv = process.argv;
|
||||||
argv = process.argv,
|
const args = require('minimist')(argv.slice(2), {
|
||||||
|
string: [
|
||||||
args = require('minimist')(argv.slice(2), {
|
'port',
|
||||||
string: [
|
'password',
|
||||||
'port',
|
'username',
|
||||||
'password',
|
'config',
|
||||||
'username',
|
'editor',
|
||||||
'config',
|
'root',
|
||||||
'editor',
|
'prefix'
|
||||||
'root',
|
],
|
||||||
'prefix'
|
boolean: [
|
||||||
],
|
'auth',
|
||||||
boolean: [
|
'repl',
|
||||||
'auth',
|
'save',
|
||||||
'repl',
|
'server',
|
||||||
'save',
|
'online',
|
||||||
'server',
|
'open',
|
||||||
'online',
|
'minify',
|
||||||
'open',
|
'progress',
|
||||||
'minify',
|
'config-dialog',
|
||||||
'progress',
|
'console',
|
||||||
'html-dialogs',
|
'one-panel-mode'
|
||||||
'console',
|
],
|
||||||
'config-dialog',
|
default: {
|
||||||
'one-panel-mode'
|
server : true,
|
||||||
],
|
auth : config('auth'),
|
||||||
default: {
|
port : config('port'),
|
||||||
server : true,
|
minify : config('minify'),
|
||||||
auth : config('auth'),
|
online : config('online'),
|
||||||
port : config('port'),
|
open : config('open'),
|
||||||
minify : config('minify'),
|
editor : config('editor') || 'edward',
|
||||||
online : config('online'),
|
username : config('username'),
|
||||||
open : config('open'),
|
root : config('root') || '/',
|
||||||
editor : config('editor') || 'edward',
|
prefix : config('prefix') || '',
|
||||||
username : config('username'),
|
progress : config('progress'),
|
||||||
root : config('root') || '/',
|
console : defaultTrue(config('console')),
|
||||||
prefix : config('prefix') || '',
|
|
||||||
progress : config('progress'),
|
'config-dialog': defaultTrue(config('configDialog')),
|
||||||
console : defaultTrue(config('console')),
|
'one-panel-mode': config('onePanelMode'),
|
||||||
|
},
|
||||||
'html-dialogs': config('htmlDialogs'),
|
alias: {
|
||||||
'config-dialog': defaultTrue(config('configDialog')),
|
v: 'version',
|
||||||
'one-panel-mode': config('onePanelMode'),
|
h: 'help',
|
||||||
},
|
p: 'password',
|
||||||
alias: {
|
o: 'online',
|
||||||
v: 'version',
|
u: 'username',
|
||||||
h: 'help',
|
s: 'save',
|
||||||
p: 'password',
|
a: 'auth',
|
||||||
o: 'online',
|
c: 'config'
|
||||||
u: 'username',
|
},
|
||||||
s: 'save',
|
unknown: (cmd) => {
|
||||||
a: 'auth',
|
exit('\'%s\' is not a cloudcmd option. See \'cloudcmd --help\'.', cmd);
|
||||||
c: 'config'
|
}
|
||||||
},
|
});
|
||||||
unknown: function(cmd) {
|
|
||||||
exit('\'%s\' is not a cloudcmd option. See \'cloudcmd --help\'.', cmd);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (args.version) {
|
if (args.version) {
|
||||||
version();
|
version();
|
||||||
|
|
@ -97,7 +93,7 @@ if (args.version) {
|
||||||
|
|
||||||
readConfig(args.config);
|
readConfig(args.config);
|
||||||
|
|
||||||
options = {
|
const options = {
|
||||||
root: args.root,
|
root: args.root,
|
||||||
editor: args.editor,
|
editor: args.editor,
|
||||||
prefix: args.prefix
|
prefix: args.prefix
|
||||||
|
|
@ -111,7 +107,7 @@ if (args.version) {
|
||||||
if (!args.save)
|
if (!args.save)
|
||||||
start(options);
|
start(options);
|
||||||
else
|
else
|
||||||
config.save(function() {
|
config.save(() => {
|
||||||
start(options);
|
start(options);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -124,12 +120,12 @@ function defaultTrue(value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateRoot(root) {
|
function validateRoot(root) {
|
||||||
var validate = require('../lib/server/validate');
|
const validate = require('../lib/server/validate');
|
||||||
validate.root(root, console.log);
|
validate.root(root, console.log);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPassword(password) {
|
function getPassword(password) {
|
||||||
var criton = require('criton');
|
const criton = require('criton');
|
||||||
|
|
||||||
return criton(password, config('algo'));
|
return criton(password, config('algo'));
|
||||||
}
|
}
|
||||||
|
|
@ -139,14 +135,14 @@ function version() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function start(config) {
|
function start(config) {
|
||||||
var SERVER = '../lib/server';
|
const SERVER = '../lib/server';
|
||||||
|
|
||||||
if (args.server)
|
if (args.server)
|
||||||
require(SERVER)(config);
|
require(SERVER)(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
function port(arg) {
|
function port(arg) {
|
||||||
var number = parseInt(arg, 10);
|
const number = parseInt(arg, 10);
|
||||||
|
|
||||||
if (!isNaN(number))
|
if (!isNaN(number))
|
||||||
config('port', number);
|
config('port', number);
|
||||||
|
|
@ -155,34 +151,35 @@ function port(arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function readConfig(name) {
|
function readConfig(name) {
|
||||||
var fs, data, error, tryCatch;
|
if (!name)
|
||||||
|
return;
|
||||||
|
|
||||||
if (name) {
|
const tryCatch = require('try-catch');
|
||||||
fs = require('fs');
|
const readjson = require('readjson');
|
||||||
tryCatch = require('try-catch');
|
|
||||||
error = tryCatch(function() {
|
let data;
|
||||||
var json = fs.readFileSync(name);
|
|
||||||
data = JSON.parse(json);
|
const error = tryCatch(() => {
|
||||||
|
data = readjson.sync(name);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (error)
|
||||||
|
exit(error.message);
|
||||||
|
else
|
||||||
|
Object.keys(data).forEach((item) => {
|
||||||
|
config(item, data[item]);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (error)
|
|
||||||
exit(error.message);
|
|
||||||
else
|
|
||||||
Object.keys(data).forEach(function(item) {
|
|
||||||
config(item, data[item]);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function help() {
|
function help() {
|
||||||
var bin = require('../json/help'),
|
const bin = require('../json/help');
|
||||||
usage = 'Usage: cloudcmd [options]',
|
const usage = 'Usage: cloudcmd [options]';
|
||||||
url = Info.homepage;
|
const url = Info.homepage;
|
||||||
|
|
||||||
console.log(usage);
|
console.log(usage);
|
||||||
console.log('Options:');
|
console.log('Options:');
|
||||||
|
|
||||||
Object.keys(bin).forEach(function(name) {
|
Object.keys(bin).forEach((name) => {
|
||||||
console.log(' %s %s', name, bin[name]);
|
console.log(' %s %s', name, bin[name]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -195,21 +192,19 @@ function repl() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkUpdate() {
|
function checkUpdate() {
|
||||||
var load = require('package-json'),
|
const load = require('package-json');
|
||||||
chalk = require('chalk'),
|
const chalk = require('chalk');
|
||||||
rendy = require('rendy');
|
const rendy = require('rendy');
|
||||||
|
|
||||||
load(Info.name, 'latest').then(function(data) {
|
load(Info.name, 'latest').then((data) => {
|
||||||
var latest,
|
const version = data.version;
|
||||||
current,
|
|
||||||
version = data.version;
|
|
||||||
|
|
||||||
if (version !== Info.version) {
|
if (version !== Info.version) {
|
||||||
latest = rendy('update available: {{ latest }}', {
|
const latest = rendy('update available: {{ latest }}', {
|
||||||
latest: chalk.green.bold('v' + version),
|
latest: chalk.green.bold('v' + version),
|
||||||
});
|
});
|
||||||
|
|
||||||
current = chalk.dim(rendy('(current: v{{ current }})', {
|
const current = chalk.dim(rendy('(current: v{{ current }})', {
|
||||||
current: Info.version
|
current: Info.version
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
|
||||||
11
package.json
11
package.json
|
|
@ -35,7 +35,8 @@
|
||||||
"server"
|
"server"
|
||||||
],
|
],
|
||||||
"bin": {
|
"bin": {
|
||||||
"cloudcmd": "bin/cloudcmd.js"
|
"cloudcmd": "bin-legacy/cloudcmd.js",
|
||||||
|
"cloudcmd+": "bin/cloudcmd.js"
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"dirs_legacy": "bin lib",
|
"dirs_legacy": "bin lib",
|
||||||
|
|
@ -59,7 +60,7 @@
|
||||||
"test": "tape 'test/**/*.js'",
|
"test": "tape 'test/**/*.js'",
|
||||||
"watch:test": "nodemon -w lib -w test -x \"npm run test\"",
|
"watch:test": "nodemon -w lib -w test -x \"npm run test\"",
|
||||||
"spell": "yaspeller .",
|
"spell": "yaspeller .",
|
||||||
"wisdom": "npm run docker:rm-old; bin/release.js",
|
"wisdom": "npm run build; npm run docker:rm-old; bin/release.js",
|
||||||
"postpublish": "redrun --parallel docker docker:alpine",
|
"postpublish": "redrun --parallel docker docker:alpine",
|
||||||
"docker:pull:node": "docker pull node",
|
"docker:pull:node": "docker pull node",
|
||||||
"docker:pull:alpine": "docker pull mhart/alpine-node",
|
"docker:pull:alpine": "docker pull mhart/alpine-node",
|
||||||
|
|
@ -77,7 +78,9 @@
|
||||||
"docker:rm:latest-alpine": "docker rmi coderaiser/cloudcmd:latest-alpine",
|
"docker:rm:latest-alpine": "docker rmi coderaiser/cloudcmd:latest-alpine",
|
||||||
"docker:rm-old": "redrun --parallel docker:rm:*",
|
"docker:rm-old": "redrun --parallel docker:rm:*",
|
||||||
"coverage": "nyc npm test",
|
"coverage": "nyc npm test",
|
||||||
"report": "nyc report --reporter=text-lcov | coveralls"
|
"report": "nyc report --reporter=text-lcov | coveralls",
|
||||||
|
"6to5:bin": "babel bin -d bin-legacy",
|
||||||
|
"build": "redrun 6to5:*"
|
||||||
},
|
},
|
||||||
"directories": {
|
"directories": {
|
||||||
"man": "man"
|
"man": "man"
|
||||||
|
|
@ -125,6 +128,8 @@
|
||||||
"writejson": "^1.1.0"
|
"writejson": "^1.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"babel-cli": "^6.18.0",
|
||||||
|
"babel-preset-es2015": "^6.18.0",
|
||||||
"coveralls": "^2.11.6",
|
"coveralls": "^2.11.6",
|
||||||
"es6-promisify": "^5.0.0",
|
"es6-promisify": "^5.0.0",
|
||||||
"eslint": "^3.1.1",
|
"eslint": "^3.1.1",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue