-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
129 lines (118 loc) · 4.67 KB
/
index.js
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#! /usr/bin/env node
const program = require('commander')
const chalk = require('chalk')
const figlet = require('figlet')
const { wrapLoading } = require('./lib/Generator')
const { getRepoList } = require('./lib/http')
const ora = require('ora')
program.name(require('./package.json').commandName);
// 配置提示信息
program
// 监听 --help 执行
.on('--help', () => {
// 使用figlet 绘制 Logo
const rgb = chalk.rgb(94, 231, 223)
console.log('\r' + rgb(figlet.textSync('yutu', {
font: 'speed',
horizontalLayout: 'default',
verticalLayout: 'default',
width: 120,
whitespaceBreak: true
})) + chalk.green('欢迎使用 yutuz cli !\n') + chalk.red(' ♥') + chalk.rgb(238, 0, 238)(` by 杉菜酱~ https://github.com/coder-fang ©${new Date().getFullYear()}`));
// 新增说明信息
console.log(`\r\n${chalk.bgBlue("yt")} ${chalk.green(`info`)} ${chalk.cyan(`[Core/cli]`)} @yutuz-cli/core@${require('./package.json').version} `)
console.log(`\rRun ${chalk.blue(`yt <command> --help`)} for details usage of given command. \r\n`)
})
program
// 定义命令和参数
.command('create <app-name>')
.description('create a new project')
// -f or --force 为强制创建,如果创建的目录存在则直接覆盖
.option('-f, --force', 'overwrite target directory if it exist')
.action((name, options) => {
// 在 create.js 中执行创建任务
require('./lib/create.js')(name, options)
})
program
// 配置版本号信息
.version(`v${require('./package.json').version}`)
.usage('<command> [options]')
// 配置config 命令
program
.command('config [value]')
.description('inspect and modify the config')
.option('-g, --get <path>', 'get value from option')
.option('-s, --set <path> <value>')
.option('-d, --delete <path>', 'delete option from config')
.action((value, options) => {
console.log(value, options);
})
// 配置ui命令
program
.command('ui')
.description('start add open roc-cli ui')
.option('-p, --port <port>', 'Port used for the UI Server')
.action((option) => {
console.log(option);
})
// 初始化命令行(yt init my_template)
// program
// .command('init <template> <app-name>')
// .description('初始化项目模板')
// .option('-g, --get <path>', 'get value from option')
// .option('-s, --set <path> <value>')
// .option('-d, --delete <path>', 'delete option from config')
// .action(async(template) => {
// let message = 'Verifying this templates...'
// const spinner = ora(message)
// spinner.start()
// const repoList = await wrapLoading(getRepoList, null)
// if (!repoList) return
// const repos = repoList.map(item => item.name)
// if(!repos.includes(template)){
// message = '该项目模板不存在,请输入有效的模板名称!'
// spinner.fail(chalk.red(message))
// console.log("\r\nPlease Enter `yt list` to find the names of all valid templates,\r\n\nfrom" +
// " which you can select the appropriate project template.\r\n");
// return;
// }else {
// // 下载模板
// // template
// message = '项目初始化成功!'
// spinner.succeed(chalk.blue(message))
// }
// })
// 查看所有的可用模板(yt list )
program
.command('list')
.description('查看所有的可用模版')
.action(async() => {
let message = 'waiting fetch template...'
const spinner = ora(message)
spinner.start()
const repoList = await wrapLoading(getRepoList,null)
if (!repoList) return;
const repos = repoList.map(item => item.name)
message = '所有的项目模板加载完毕!'
spinner.succeed(chalk.blue(message))
for (let key in repos) {
console.log(repos[key])
}
})
program
.command('g')
.description('start add open roc-cli ui')
.option('-p, --port <port>', 'Port used for the UI Server')
.action((option) => {
console.log(option);
})
program
.command('*')
.description('找不到相应的命令')
.action(() => {
const message = '找不到相应的命令!'
const spinner = ora(message)
spinner.fail(chalk.red(message))
})
// 解析用户执行命令传入参数
program.parse(process.argv);