Skip to content

Commit 3a7de72

Browse files
committed
fix(lib): 同步cli.js与ykit.common.js
1 parent 9eca6bc commit 3a7de72

File tree

2 files changed

+33
-34
lines changed

2 files changed

+33
-34
lines changed

lib/cli.js

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
'use strict';
22

33
require('./global');
4+
var version = require('../package.json').version;
5+
var optimist = require('optimist');
6+
var rightPad = require('right-pad');
47

58
var Manager = require('./modules/manager.js');
69

7-
var helpTitle = function helpTitle() {
8-
info();
9-
info('===================== YKit ' + packageJSON.version + ' ====================');
10-
info();
11-
};
10+
var helpTitle = '\n===================== YKit ' + version + ' ====================\n';
1211

1312
var initOptions = function initOptions(cmd) {
1413
if (cmd.setOptions) {
@@ -24,46 +23,46 @@ var initOptions = function initOptions(cmd) {
2423
};
2524

2625
var cli = module.exports = {
27-
run: function run(cmdName) {
28-
if (cmdName === '-v' || cmdName === '--version') {
29-
log(packageJSON.version);
26+
run: function run(option) {
27+
if (option === '-v' || option === '--version') {
28+
log(version);
3029
return;
31-
} else if (cmdName === '-h' || cmdName === '--help') {
30+
} else if (option === '-h' || option === '--help' || !option) {
3231
cli.help();
3332
return;
3433
}
3534

36-
var project = Manager.getProject(process.cwd()),
37-
cmd = project.commands.filter(function (item) {
38-
return item.name == cmdName;
35+
var project = Manager.getProject(process.cwd());
36+
var command = project.commands.filter(function (command) {
37+
return command.name == option;
3938
})[0];
40-
if (!cmd) {
41-
error('请确认是否存在 ' + cmdName + ' 命令');
39+
if (!command) {
40+
error('请确认是否存在 ' + option + ' 命令');
4241
return;
4342
}
44-
cmd = cmd.module;
45-
var options = initOptions(cmd);
43+
var module = command.module;
44+
var options = initOptions(module);
4645
if (options.h || options.help) {
47-
helpTitle();
48-
info('命令:', cmdName);
49-
info('说明:', cmd.usage || '');
46+
info(helpTitle);
47+
info('命令:', option);
48+
info('说明:', module.usage || '');
5049
info();
5150
optimist.showHelp();
5251
info(' 如果需要帮助, 请使用 ykit {命令名} --help ');
5352
} else {
54-
cmd.run.call({ project: project }, options);
53+
module.run.call({ project: project }, options);
5554
}
5655
},
5756
help: function help() {
58-
helpTitle();
57+
info(helpTitle);
5958
Manager.getProject(process.cwd()).commands.forEach(function (command) {
6059
info(' ' + rightPad(command.name, 15) + ' # ' + (command.module.usage || ''));
6160
});
6261
info();
63-
info('可用的全局配置有:', (Manager.readRC().configs || []).map(function (item) {
62+
info(' 可用的全局配置有:', (Manager.readRC().configs || []).map(function (item) {
6463
return item.name.substring(12);
6564
}).join(', '));
6665
info();
67-
info(' 如果需要帮助, 请使用 ykit {命令名} --help ');
66+
info(' 如果需要帮助, 请使用 ykit {命令名} --help\n');
6867
}
6968
};

lib/config/initTmpl/ykit.common.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
exports.config = function() {
1+
"use strict";
2+
3+
exports.config = function () {
24
// 项目资源入口
35
this.setExports([
46
// './scripts/index.js',
@@ -12,18 +14,16 @@ exports.config = function() {
1214

1315
// sync到开发机配置
1416
this.setSync({
15-
host : "192.168.237.71",
17+
host: "192.168.237.71",
1618
path: "/home/q/www/qunarzz.com/#_name"
1719
});
1820

1921
// 自定义命令
20-
this.setCommands([
21-
{
22-
name: '#_name_cmd',
23-
module: {
24-
usage: '项目自定义命令',
25-
run: function () {}
26-
}
22+
this.setCommands([{
23+
name: '#_name_cmd',
24+
module: {
25+
usage: '项目自定义命令',
26+
run: function run() {}
2727
}
28-
]);
29-
};
28+
}]);
29+
};

0 commit comments

Comments
 (0)