Skip to content

Commit

Permalink
update:english command.
Browse files Browse the repository at this point in the history
  • Loading branch information
kvkens committed Jan 6, 2017
1 parent 3041108 commit 63e6545
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 32 deletions.
8 changes: 4 additions & 4 deletions bin/uba.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ const chalk = require('chalk');
const argv = require('minimist')(process.argv.slice(2));
const commands = argv._;
const help = require('../lib/help');
const init = require('../lib/init');

if (commands.length === 0) {
if (argv.version || argv.v) {
console.log(chalk.green(require('../package.json').version));
help.version();
} else if (argv.help || argv.h) {
help.help();
} else {
const init = require('../lib/init');
init();
help.help();
}
} else {
switch (commands[0]) {
case 'init':
require('../lib/quick')(commands);
init();
break;
default:
break;
Expand Down
13 changes: 7 additions & 6 deletions lib/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Module : helper
* Author : Kvkens([email protected])
* Date : 2016-10-13 19:58:42
* Update : 2016-12-29 08:44:13
* Update : 2017-01-06 10:13:35
*/

'use strict';
Expand All @@ -13,23 +13,24 @@ const fs = require('fs');

module.exports = {
help: () => {
console.log(chalk.green('1. uba Generate best practices'));
console.log(chalk.green('2. uba --help or -h Help'));
console.log(chalk.green('uba help'));
console.log(chalk.green('1. uba init Generate best practices'));
console.log(chalk.green('2. uba -h Help'));
},
version: () => {
console.log();
console.log(chalk.green('当前版本:v' + require('../package.json').version));
console.log(chalk.green('Version : ' + require('../package.json').version));
console.log();
process.exit();
},
info: (msg) => {
// console.log();
console.log(chalk.cyan("信息:" + msg));
console.log(chalk.cyan("Info : " + msg));
// console.log();
},
error: (msg) => {
// console.log();
console.log(chalk.red("错误:" + msg));
console.log(chalk.red("Error : " + msg));
// console.log();
},
merge: (destination, source) => {
Expand Down
21 changes: 10 additions & 11 deletions lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const spawn = require('cross-spawn');


module.exports = () => {
help.info("正在加载远程数据请稍等...");
help.info("Available official templates:");
var repoNameData = [];
request({
url: 'https://api.github.com/users/uba-templates/repos',
Expand All @@ -40,15 +40,14 @@ module.exports = () => {
inquirer.prompt([{
type: 'list',
name: 'selectRepo',
message: '选择在线最佳实践:',
message: 'Please select :',
choices: repoNameData
}]).then(function(answers) {
var selectName = answers.selectRepo.split(' - ')[0];
//console.log(chalk.green(`已选择[${selectName}]`));
var questions = [{
type: 'input',
name: 'selectName',
message: '最佳实践目录名称:',
message: 'boilerplate name :',
default: function() {
return 'uba-boilerplate';
}
Expand All @@ -60,22 +59,22 @@ module.exports = () => {
if (!pathExists.sync(name)) {
fs.mkdirSync(root);
} else {
help.error(`当前工程 ${name} 已存在,当前操作终止.`);
help.error(`directory ${name} already exists.`);
process.exit(0);
}
help.info(`开始下载 ${template} 最佳实践模板请稍等...`);
help.info(`Downloading ${template} please wait.`);
//TODO 开始下载
download(help.getInitGithubRepo(template), `${name}`, function(err) {
if (!err) {
help.info(`最佳实践 ${name} 创建完毕.`);
help.info(`Boilerplate ${name} done.`);
inquirer.prompt([{
type: 'confirm',
message: '是否自动安装npm依赖包',
message: 'Automatically install NPM dependent packages?',
name: 'ok'
}]).then(function(res) {
var npmInstallChdir = path.resolve('.', name);
if (res.ok) {
help.info(`开始安装npm依赖包请稍等...`);
help.info(`Install NPM dependent packages,please wait.`);
//TODO 选择自动安装
process.chdir(npmInstallChdir);
var args = ['install'].filter(function(e) {
Expand All @@ -89,11 +88,11 @@ module.exports = () => {
console.error('`npm ' + args.join(' ') + '` failed');
return;
}
help.info(`自动安装完毕.`);
help.info(`NPM package installed.`);
});

} else {
help.error(`取消自动安装npm依赖包,请手动执行npm install.`);
help.error(`Cancel the installation of NPM dependent package,please run npm install.`);
}

});
Expand Down
19 changes: 9 additions & 10 deletions lib/quick.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const spawn = require('cross-spawn');

module.exports = (commands) => {
if (commands.length !== 3) {
help.error(' uba init 命令不正确.');
help.error(' uba init bad');
process.exit(0);
}
var name = null,
Expand All @@ -33,21 +33,21 @@ module.exports = (commands) => {
if (!pathExists.sync(name)) {
fs.mkdirSync(root);
} else {
help.error(`当前文件夹 ${name} 已经存在了,当前操作终止.`);
help.error(`directory ${name} already exists.`);
process.exit(0);
}
help.info(`开始下载 ${template} 最佳实践模板请稍等.`);
help.info(`Downloading ${template} please wait.`);
download(help.getInitGithubRepo(template), `${name}`, function(err) {
if (!err) {
help.info(`最佳实践 ${name} 创建完毕.`);
help.info(`Boilerplate ${name} done.`);
inquirer.prompt([{
type: 'confirm',
message: '是否自动安装npm依赖包',
message: 'Automatically install NPM dependent packages?',
name: 'ok'
}]).then(function(res) {
var npmInstallChdir = path.resolve('.', name);
if (res.ok) {
help.info(`开始安装npm依赖包请稍等...`);
help.info(`Install NPM dependent packages,please wait.`);
//TODO 选择自动安装
process.chdir(npmInstallChdir);
var args = ['install'].filter(function(e) {
Expand All @@ -61,17 +61,16 @@ module.exports = (commands) => {
console.error('`npm ' + args.join(' ') + '` failed');
return;
}
help.info(`自动安装完毕.`);
help.info(`NPM package installed.`);
});

} else {
help.error(`取消自动安装npm依赖包,请手动执行npm install.`);
help.error(`Cancel the installation of NPM dependent package,please run npm install.`);
}

});

} else {
help.error(`最佳实践下载失败,请检查最佳实践名字是否正确或网络错误.`);
console.error(requestBody.message);
}
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uba",
"version": "2.0.2",
"version": "2.0.3",
"description": "a font-end develop tool for tinper",
"main": "bin/uba.js",
"bin": {
Expand Down

0 comments on commit 63e6545

Please sign in to comment.