-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
79 lines (64 loc) · 2.23 KB
/
cli.js
File metadata and controls
79 lines (64 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#! /usr/bin/env node
// #! 符号的名称叫 Shebang,用于指定脚本的解释程序
// Node CLI 应用入口文件必须要有这样的文件头
// 如果是Linux 或者 macOS 系统下还需要修改此文件的读写权限为 755
// 具体就是通过 chmod 755 cli.js 实现修改
// 用于检查入口文件是否正常执行
console.log('isolcat-cli')
// 引入各种包
const program = require("commander")
const chalk = require('chalk')
const inquirer = require('inquirer');
const ora = require("ora");
const spinner = ora("Loading unicorns");
var figlet = require('figlet');
// 解析用户执行时输入的参数
// process.argv是node.js提供的属性
// npm run server --post 3000
// 后面的 --post 3000就是用户输入的参数
program
.name("isolcat-cli")
.usage(`<command> [option]`)
.version(`1.0.0`);
// 使用 cyan 颜色
program.on("--help", function() {
// 前后两个空行调整格式,更舒适
console.log();
console.log(
`Run ${chalk.cyan(
"isolcat <command> --help"
)} for detailed usage of given command.`
);
console.log();
});
// zc 入口文件
program
.command("create <project-name>") // 增加创建指令
.description("create a new project") // 添加描述信息
.option("-f, --force", "overwrite target directory if it exists") // 强制覆盖
.action((projectName, cmd) => {
// 引入 create 模块,并传入参数
require("./bin/create")(projectName, cmd);
});
program
.command("config [value]") // config 命令
.description("inspect and modify the config")
.option("-g, --get <key>", "get value by key")
.option("-s, --set <key> <value>", "set option[key] is value")
.option("-d, --delete <key>", "delete option by key")
.action((value, keys) => {
// value 可以取到 [value] 值,keys会获取到命令参数
console.log(value, keys);
});
// 艺术字
console.log(
"\r\n" +
figlet.textSync("isolcat", {
font: "Ghost",
horizontalLayout: "default",
verticalLayout: "default",
width: 80,
whitespaceBreak: true,
})
);
program.parse(process.argv);