-
Notifications
You must be signed in to change notification settings - Fork 13
/
bin.js
executable file
·198 lines (195 loc) · 4.23 KB
/
bin.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/usr/bin/env node
'use strict'
const yargs = require('yargs')
const {scanEntry, compileSingleFile} = require('./scanner.js')
// const generate = require('./generator.js')
const watcher = require('./watcher.js')
const init = require('./creator.js')
yargs
.command('init [dest]', 'create a new ef.qt project', (yargs) => {
yargs
.positional('dest', {
describe: 'destinaion directory to put template in',
default: '.',
type: 'string'
})
.option('o', {
alias: 'overwrite',
demandOption: false,
describe: 'overwrite existing file',
type: 'bool'
})
}, (argv) => {
init(argv.dest, !!argv.overwrite, {verbose: argv.verbose, dryrun: argv.dryrun})
})
.command('generate [dir]', 'scan templates and generate C++ code', (yargs) => {
yargs
.positional('dir', {
default: '.',
describe: 'which folder to scan from',
type: 'string'
})
.option('o', {
alias: 'output',
demandOption: false,
default: 'ef.hpp',
describe: 'output file(or folder with -s) for generated code, default to `.efgenerated/ef\' with -s',
type: 'string'
})
.option('s', {
alias: 'seperate',
demandOption: false,
describe: 'seperate the generated header into headers for each template',
type: 'bool'
})
.option('e', {
alias: 'extension',
demandOption: false,
default: 'hpp',
describe: 'generated header file extension, useful with -s',
type: 'string'
})
.option('i', {
alias: 'ignore',
demandOption: false,
default: [],
describe: 'folders to be ignored during scan',
type: 'array'
})
.option('t', {
alias: 'typedef',
demandOption: false,
default: '.eftypedef',
describe: 'Extra param type definition',
type: 'string'
})
}, (argv) => {
scanEntry({
dir: argv.dir,
outPath: argv.output,
seperate: argv.seperate,
extensionName: argv.extension,
ignores: argv.ignore,
extraTypeDef: argv.typedef
}, {
verbose: argv.verbose,
dryrun: argv.dryrun
})
})
.command('compile <input> <output>', 'compile one template to one file', (yargs) => {
yargs
.positional('input', {
describe: 'input file path',
type: 'string'
})
.positional('output', {
describe: 'output file path',
type: 'string'
})
.option('b', {
alias: 'base',
demandOption: false,
default: '.',
describe: 'Base dir to the input file',
type: 'string'
})
.option('t', {
alias: 'typedef',
demandOption: false,
default: '.eftypedef',
describe: 'Extra param type definition',
type: 'string'
})
}, (argv) => {
compileSingleFile({
input: argv.input,
output: argv.output,
base: argv.base,
extraTypeDef: argv.typedef
}, {
verbose: argv.verbose,
dryrun: argv.dryrun
})
})
.command('watch [dir]', 'watch template file change and re-generate immediately', (yargs) => {
yargs
.positional('dir', {
describe: 'directory to watch',
default: '.',
type: 'string'
}).
option('d', {
alias: 'debounce',
demandOption: false,
default: 1,
describe: 'debounce time before re-generate in seconds',
type: 'number'
})
.option('o', {
alias: 'output',
demandOption: false,
default: 'ef.hpp',
describe: 'output file for generated code',
type: 'string'
})
.option('s', {
alias: 'seperate',
demandOption: false,
describe: 'seperate the generated header into headers for each template',
type: 'bool'
})
.option('e', {
alias: 'extension',
demandOption: false,
default: 'hpp',
describe: 'generated header file extension, useful with -s',
type: 'string'
})
.option('i', {
alias: 'ignore',
demandOption: false,
default: [],
describe: 'folders to be ignored during scan',
type: 'array'
})
.option('t', {
alias: 'typedef',
demandOption: false,
default: '.eftypedef',
describe: 'Extra param type definition',
type: 'string'
})
}, (argv) => {
watcher({
dir: argv.dir,
debounce: argv.debounce,
outPath: argv.output,
seperate: argv.seperate,
extensionName: argv.extension,
ignores: argv.ignore,
extraTypeDef: argv.extra
}, {
verbose: argv.verbose,
dryrun: argv.dryrun
})
})
.option('v', {
alias: 'verbose',
demandOption: false,
describe: 'show verbose log',
type: 'bool'
})
.option('D', {
alias: 'dryrun',
demandOption: false,
describe: 'do everything but real modifications',
type: 'bool'
})
.help('h')
.alias('h', 'help')
.demandCommand()
.recommendCommands()
.strict()
.completion()
.config()
.parse()