-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·103 lines (92 loc) · 2.64 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
#!/usr/bin/env node
// Spawn NPM asynchronously
// const child = spawn('npm', ['list', '-g', '-depth', '0'], { stdio: 'inherit' });
// // Spawn NPM synchronously
// const result = spawn.sync('npm', ['list', '-g', '-depth', '0'], { stdio: 'inherit' })
//quicktype --just-types -o 129_req_body_other.ts --src-lang schema 129_req_body_other.json
// const result = spawn.sync('quicktype', ['--just-types', '-o', '129_req_body_other.ts', '--src-lang', 'schema', '129_req_body_other.json'])
// console.log("result ", result)
const program = require('commander');
const path = require('path')
const { version } = { version: '0.0.1' }
// console.log("-----", process.cwd("/etc"), path.resolve(__dirname, "etc/host"), __dirname)
// return;
const actionsMap = {
// create: {
// description: 'crate project',
// alias: 'cr',
// examples: [
// 'wby create <template-name>'
// ],
// },
// config: {
// description: 'config info',
// alias: 'c',
// examples: [
// 'wby config get <k>',
// 'wby config set <k> <v>'
// ]
// },
// build: {
// description: 'build',
// alias: 'bu',
// examples: [
// 'wby build'
// ]
// },
// start: {
// description: 'start',
// alias: 's',
// examples: [
// 'wby start'
// ]
// },
interface: {
description: '生成接口约束文件.ts',
alias: 'inter',
examples: [
'rappter interface'
]
},
actions: {
description: '生成action creator.ts',
alias: 'act',
examples: [
'rappter actions'
]
},
reducer: {
description: '生成reducer creator.ts',
alias: 'act',
examples: [
'rappter reducer'
]
}
}
Object.keys(actionsMap).forEach((key) => {
const action = actionsMap[key]
// console.log(action)
program
.command(key)
.alias(action.alias)
.description(action.description)
.action(() => {
if (action === '*') {
console.log(action.description)
} else {
// console.log("===", process.argv.slice(3))
require(path.resolve(__dirname, "scripts", key))(...process.argv.slice(3))
}
});
})
program.on('--help', () => {
Object.keys(actionsMap).forEach((key) => {
const action = actionsMap[key];
(action.examples || []).forEach((example) => {
console.log(` ${example}`)
})
})
})
program
.version(version)
.parse(process.argv);