Commit b61519a8 authored by super-lin0's avatar super-lin0

cli init

parents
Pipeline #118 canceled with stages
node_modules
.DS_Store
*.gzip
*.zip
*.tgz
*.log
dist
*.bak
package-*.json
yarn-*.json
yarn.lock
es
# bisheng生成的结果文件。
_site
.idea
packages/react-imap/demo-web/
packages/react-imap/docs/
# inquire + commander + chalk 学习
参考资料
<a href="https://aotu.io/notes/2016/08/09/command-line-development/index.html">跟着老司机玩转 Node 命令行
</a>
#!/usr/bin/env node
require("../lib/index");
const program = require("commander");
const chalk = require("chalk");
const inquirer = require("inquirer");
program
.version("0.0.1")
.option("-C, --chdir <path>", "change the working directory")
.option("-c, --config <path>", "set config path. defaults to ./deploy.conf")
.option("-T, --no-tests", "ignore test hook");
program
.command("init")
.alias("i")
.description("run remote setup commands")
.action(function() {
console.log(chalk.red("开启前端工程化之路"));
const prompts = [
{
type: "list",
name: "type",
message: "请选择项目类型:",
pageSize: 4,
choices: [
{ name: "Web端项目", value: "web" },
{ name: "PC端项目", value: "pc" },
{ name: "Demo项目", value: "demo" },
{ name: "Blank项目", value: "blank" },
{ name: "Test项目", value: "test" },
{ name: "Mobile端项目", value: "mobile" }
]
}
];
inquirer.prompt(prompts).then(answers => {
console.log("Hello, world", answers);
console.log(chalk.green("收工咯"));
console.log(chalk.blue("收工咯"));
console.log(chalk.blue.bgRed("收工咯")); //支持设置背景
console.log(chalk.blue(JSON.stringify(answers)));
});
});
// program
// .command("exec <cmd>")
// .description("run the given remote command")
// .action(function(cmd) {
// console.log('exec "%s"', cmd);
// });
// program
// .command("teardown <dir> [otherDirs...]")
// .description("run teardown commands")
// .action(function(dir, otherDirs) {
// console.log('dir "%s"', dir);
// if (otherDirs) {
// otherDirs.forEach(function(oDir) {
// console.log('dir "%s"', oDir);
// });
// }
// });
// program
// .command("*")
// .description("deploy the given env")
// .action(function(env) {
// console.log('deploying "%s"', env);
// });
program.parse(process.argv);
{
"name": "commander-demo",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"chalk": "^2.4.2",
"commander": "^3.0.2",
"inquirer": "^7.0.0"
},
"bin": {
"heracles": "./bin/npmrc.js"
},
"scripts": {
"start": "node index.js"
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment