@mpilk/mp-route 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.cjs CHANGED
@@ -1,331 +1,331 @@
1
- #!/usr/bin/env node
2
- 'use strict'
3
-
4
- var commander = require('commander')
5
- var path = require('path')
6
- var fs = require('fs')
7
- var pino = require('pino')
8
- var mpShared = require('@mpilk/mp-shared')
9
- var lodashEs = require('lodash-es')
10
- var chokidar = require('chokidar')
11
-
12
- function _interopDefault(e) {
13
- return e && e.__esModule ? e : { default: e }
14
- }
15
-
16
- var path__default = /*#__PURE__*/ _interopDefault(path)
17
- var fs__default = /*#__PURE__*/ _interopDefault(fs)
18
- var pino__default = /*#__PURE__*/ _interopDefault(pino)
19
- var chokidar__default = /*#__PURE__*/ _interopDefault(chokidar)
20
-
21
- // package.json
22
- var version = '1.1.3'
23
- var _indexPath = ''
24
- var logger = pino__default.default({
25
- transport: {
26
- target: 'pino-pretty',
27
- options: {
28
- colorize: true
29
- // ignore: 'hostname,pid',
30
- }
31
- }
32
- })
33
- var verboseLogger = logger.child({ verbose: true })
34
- function builderWithWatch(options) {
35
- let timer = null
36
- function run() {
37
- if (timer) clearTimeout(timer)
38
- timer = setTimeout(() => {
39
- timer = null
40
- return builder(options)
41
- }, options?.delay || 200)
42
- }
43
- return chokidar__default.default
44
- .watch([
45
- `src/**/${options?.routeName || 'route'}.{ts,js}`,
46
- `src/${options?.tabbarName || 'tabbar'}.{ts,js}`
47
- ])
48
- .on('all', (eventName) => {
49
- switch (eventName) {
50
- case 'add':
51
- case 'change':
52
- case 'unlink':
53
- run()
54
- break
55
- }
56
- })
57
- }
58
- async function builder(options = {}) {
59
- const {
60
- input = './src',
61
- routeName = 'route',
62
- tabbarName = 'tabbar',
63
- pagesPath = './src/pages.json',
64
- verbose
65
- } = options
66
- logger.info('\u5F00\u59CB\u751F\u6210\u8DEF\u7531\u6587\u4EF6...')
67
- const filePaths = loadDirFiles(input, routeName)
68
- logger.info(
69
- `\u6839\u636E ${routeName} \u627E\u5230 ${filePaths.length} \u4E2A\u6587\u4EF6`
70
- )
71
- const routeConfigs = []
72
- for (const filePath of filePaths) {
73
- verbose &&
74
- verboseLogger.info(`\u5F00\u59CB\u89E3\u6790\u6587\u4EF6 ${filePath}`)
75
- let content = await mpShared.loadFileContent(filePath)
76
- if (!content || typeof content !== 'object' || lodashEs.isEmpty(content)) {
77
- verbose &&
78
- verboseLogger.info(
79
- `\u6587\u4EF6 ${filePath} \u4E3A\u7A7A\uFF0C\u8DF3\u8FC7`
80
- )
81
- continue
82
- }
83
- if (!lodashEs.isArray(content)) content = [content]
84
- verbose &&
85
- verboseLogger.info(
86
- `\u6587\u4EF6 ${filePath} \u89E3\u6790\u5B8C\u6210\uFF1A${JSON.stringify(
87
- content
88
- )}`
89
- )
90
- routeConfigs.push(...content)
91
- }
92
- const rs = buildRoute(routeConfigs)
93
- if (_indexPath) {
94
- const idx2 = rs.pages.findIndex((page) => page.path === _indexPath)
95
- if (idx2 !== -1) rs.pages.unshift(...rs.pages.splice(idx2, 1))
96
- }
97
- logger.info('\u8DEF\u7531\u6587\u4EF6\u89E3\u6790\u5B8C\u6210')
98
- if (!rs.condition.list.length) rs.condition = void 0
99
- else if (rs.condition.list.length && rs.condition.current === -1)
100
- rs.condition.current = 0
101
- const idx = rs.pages.findIndex((page) => page['_index'])
102
- if (idx !== -1) rs.pages.unshift(...rs.pages.splice(idx, 1))
103
- let tabbarObj
104
- const [tabbarPath] = loadDirFiles('./src', tabbarName)
105
- if (tabbarPath && !lodashEs.isEmpty(tabbarPath)) {
106
- logger.info(`\u6839\u636E ${tabbarName} \u627E\u52301\u4E2A\u6587\u4EF6`)
107
- tabbarObj = await mpShared.loadFileContent(tabbarPath)
108
- if (tabbarObj && !lodashEs.isEmpty(tabbarObj)) rs.tabBar = tabbarObj
109
- }
110
- const {
111
- debug: _debug = false,
112
- pages,
113
- subPackages,
114
- preloadRule,
115
- condition,
116
- tabBar,
117
- ...otherProps
118
- } = await mpShared.loadJson(pagesPath)
119
- const writeContent = {
120
- debug: _debug,
121
- pages: rs.pages || pages,
122
- subPackages: rs.subPackages || subPackages,
123
- preloadRule: rs.preloadRule || preloadRule,
124
- condition: rs.condition || condition,
125
- tabBar: tabbarObj || tabBar,
126
- ...otherProps
127
- }
128
- await mpShared.outputFile(pagesPath, JSON.stringify(writeContent, null, 2))
129
- logger.info('\u8DEF\u7531\u6587\u4EF6\u751F\u6210\u5B8C\u6210\uFF01')
130
- }
131
- function buildRoute(content, ext = {}) {
132
- const result = {
133
- pages: [],
134
- subPackages: [],
135
- preloadRule: {},
136
- condition: {
137
- current: -1,
138
- list: []
139
- }
140
- }
141
- const { parentName = '', parentPath = '', subpackageRoot = '' } = ext
142
- for (const route of content) {
143
- const {
144
- subPackages = false,
145
- isSubpackage = subPackages,
146
- path: path2,
147
- title,
148
- name,
149
- children
150
- } = route
151
- const style = {
152
- navigationBarTitleText: title || name || parentName,
153
- ...route.style
154
- }
155
- const _path = pathJoin(parentPath, path2)
156
- if (isSubpackage && !subpackageRoot) {
157
- let { preLoadPath, preLoadNetwork } = route
158
- const { pages, preloadRule, condition } = buildRoute(children ?? [], {
159
- parentName: style.navigationBarTitleText,
160
- subpackageRoot: _path
161
- })
162
- const subPackage = {
163
- root: _path,
164
- pages
165
- }
166
- result.preloadRule = deepMerge(result.preloadRule, preloadRule)
167
- result.condition = deepMerge(result.condition, condition)
168
- if (condition.current > -1)
169
- result.condition.current = result.condition?.list?.indexOf(
170
- condition.list[condition.current]
171
- )
172
- result.subPackages.push(subPackage)
173
- if (preLoadPath) {
174
- if (!lodashEs.isArray(preLoadPath)) preLoadPath = [preLoadPath]
175
- const preLoadRule = preLoadPath.reduce((acc, cur) => {
176
- acc[pathJoin(cur)] = {
177
- network: preLoadNetwork,
178
- packages: [_path]
179
- }
180
- return acc
181
- }, {})
182
- result.preloadRule = deepMerge(result.preloadRule, preLoadRule)
183
- }
184
- continue
185
- }
186
- if (children?.length) {
187
- const {
188
- pages,
189
- subPackages: subPackages2,
190
- preloadRule,
191
- condition
192
- } = buildRoute(children, {
193
- parentName: style.navigationBarTitleText,
194
- parentPath: _path,
195
- subpackageRoot
196
- })
197
- result.pages = deepMerge(result.pages, pages)
198
- result.subPackages = deepMerge(result.subPackages, subPackages2)
199
- result.preloadRule = deepMerge(result.preloadRule, preloadRule)
200
- result.condition = deepMerge(result.condition, condition)
201
- if (condition.current > -1)
202
- result.condition.current = result.condition?.list?.indexOf(
203
- condition.list[condition.current]
204
- )
205
- } else {
206
- const { conditionActive, conditionQuery } = route
207
- const item = {
208
- path: _path,
209
- style
210
- }
211
- route.isIndex && (_indexPath = _path)
212
- result.pages.push(item)
213
- if (conditionQuery || conditionActive) {
214
- const conditionItem = {
215
- name: style.navigationBarTitleText,
216
- path: _path,
217
- query: conditionQuery
218
- }
219
- result.condition.list.push(conditionItem)
220
- if (conditionActive)
221
- result.condition.current =
222
- result.condition.list?.indexOf(conditionItem)
223
- }
224
- }
225
- }
226
- return result
227
- }
228
- var extension = ['.ts', '.js', '.mjs', '.json']
229
- function loadDirFiles(roots, name, exitByFirst = false) {
230
- if (!Array.isArray(roots)) roots = [roots]
231
- const files = []
232
- for (let root of roots) {
233
- root = path__default.default.resolve(root)
234
- if (!fs__default.default.existsSync(root)) continue
235
- const stat = fs__default.default.statSync(root)
236
- const regex = new RegExp(`${name}(${extension.join('|')})$`)
237
- if (stat.isFile() && regex.test(root)) {
238
- files.push(root)
239
- if (exitByFirst) break
240
- }
241
- if (stat.isDirectory()) {
242
- const dirents = fs__default.default
243
- .readdirSync(root)
244
- .map((o) => path__default.default.resolve(root, o))
245
- files.push(...loadDirFiles(dirents, name))
246
- }
247
- }
248
- return files
249
- }
250
- function pathJoin(...paths) {
251
- return paths.join('/').split('/').filter(Boolean).join('/')
252
- }
253
- function deepMerge(target, ...sources) {
254
- if (typeof target !== 'object' || target === null) target = {}
255
- if (!sources.length) return target
256
- for (const source of sources) {
257
- if (typeof source !== 'object' || source === null) continue
258
- if (lodashEs.isArray(target) && lodashEs.isArray(source)) {
259
- const set = /* @__PURE__ */ new Set([...target, ...source])
260
- return [...set]
261
- } else if (
262
- lodashEs.isPlainObject(target) &&
263
- lodashEs.isPlainObject(source)
264
- ) {
265
- for (const key in source) {
266
- if (
267
- key in target &&
268
- typeof target[key] === 'object' &&
269
- typeof source[key] === 'object'
270
- ) {
271
- target[key] = deepMerge(target[key], source[key])
272
- } else {
273
- target[key] = source[key] || target[key]
274
- }
275
- }
276
- }
277
- }
278
- return target
279
- }
280
-
281
- // src/cli.ts
282
- commander.program
283
- .name('uni-route')
284
- .description(
285
- `\u8FD9\u662F\u4E00\u4E2A\u7528\u6765\u751F\u6210 uni-app \u8DEF\u7531\u6587\u4EF6\u7684\u5DE5\u5177
286
- \u901A\u8FC7\u626B\u63CFsrc\u76EE\u5F55\u4E0B\u7684\u914D\u7F6E\u6587\u4EF6\uFF0C\u751F\u6210 uni-app \u8DEF\u7531\u914D\u7F6E\u6587\u4EF6\u3002`
287
- )
288
- .version(version)
289
- commander.program
290
- .option(
291
- '-i, --input <input>',
292
- '\u626B\u63CF\u914D\u7F6E\u7684\u6587\u4EF6\u5939\u5165\u53E3\u8DEF\u5F84',
293
- 'src/'
294
- )
295
- .option(
296
- '-rn, --routeName <routeName>',
297
- '\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84',
298
- 'route'
299
- )
300
- .option(
301
- '-tn, --tabbarName <tabbarName>',
302
- '\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84',
303
- 'tabbar'
304
- )
305
- .option(
306
- '-pp, --pagesPath <pagesPath>',
307
- '\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84',
308
- 'src/pages.json'
309
- )
310
- .option(
311
- '-vvv, --verbose',
312
- '\u8F93\u51FA\u8BE6\u7EC6\u7684\u8C03\u8BD5\u4FE1\u606F'
313
- )
314
- commander.program
315
- .command('build', { isDefault: true })
316
- .description(
317
- '\u641C\u7D22\u8DEF\u5F84\u4E0B\u7684\u8DEF\u7531\u6587\u4EF6\uFF0C\u751F\u6210\u8DEF\u7531\u914D\u7F6E'
318
- )
319
- .action((_, command) => {
320
- builder(command.optsWithGlobals())
321
- })
322
- commander.program
323
- .command('watch')
324
- .description(
325
- '\u76D1\u542C\u6587\u4EF6\u53D8\u5316\uFF0C\u5B9E\u65F6\u751F\u6210\u8DEF\u7531\u914D\u7F6E'
326
- )
327
- .option('-t --delay [delay]', '\u5EF6\u8FDF\u65F6\u95F4')
328
- .action((_, command) => {
329
- builderWithWatch(command.optsWithGlobals())
330
- })
331
- commander.program.parse()
1
+ #!/usr/bin/env node
2
+ 'use strict'
3
+
4
+ var commander = require('commander')
5
+ var path = require('path')
6
+ var fs = require('fs')
7
+ var pino = require('pino')
8
+ var mpShared = require('@mpilk/mp-shared')
9
+ var lodashEs = require('lodash-es')
10
+ var chokidar = require('chokidar')
11
+
12
+ function _interopDefault(e) {
13
+ return e && e.__esModule ? e : { default: e }
14
+ }
15
+
16
+ var path__default = /*#__PURE__*/ _interopDefault(path)
17
+ var fs__default = /*#__PURE__*/ _interopDefault(fs)
18
+ var pino__default = /*#__PURE__*/ _interopDefault(pino)
19
+ var chokidar__default = /*#__PURE__*/ _interopDefault(chokidar)
20
+
21
+ // package.json
22
+ var version = '3.0.1'
23
+ var _indexPath = ''
24
+ var logger = pino__default.default({
25
+ transport: {
26
+ target: 'pino-pretty',
27
+ options: {
28
+ colorize: true
29
+ // ignore: 'hostname,pid',
30
+ }
31
+ }
32
+ })
33
+ var verboseLogger = logger.child({ verbose: true })
34
+ function builderWithWatch(options) {
35
+ let timer = null
36
+ function run() {
37
+ if (timer) clearTimeout(timer)
38
+ timer = setTimeout(() => {
39
+ timer = null
40
+ return builder(options)
41
+ }, options?.delay || 200)
42
+ }
43
+ return chokidar__default.default
44
+ .watch([
45
+ `src/**/${options?.routeName || 'route'}.{ts,js}`,
46
+ `src/${options?.tabbarName || 'tabbar'}.{ts,js}`
47
+ ])
48
+ .on('all', (eventName) => {
49
+ switch (eventName) {
50
+ case 'add':
51
+ case 'change':
52
+ case 'unlink':
53
+ run()
54
+ break
55
+ }
56
+ })
57
+ }
58
+ async function builder(options = {}) {
59
+ const {
60
+ input = './src',
61
+ routeName = 'route',
62
+ tabbarName = 'tabbar',
63
+ pagesPath = './src/pages.json',
64
+ verbose
65
+ } = options
66
+ logger.info('\u5F00\u59CB\u751F\u6210\u8DEF\u7531\u6587\u4EF6...')
67
+ const filePaths = loadDirFiles(input, routeName)
68
+ logger.info(
69
+ `\u6839\u636E ${routeName} \u627E\u5230 ${filePaths.length} \u4E2A\u6587\u4EF6`
70
+ )
71
+ const routeConfigs = []
72
+ for (const filePath of filePaths) {
73
+ verbose &&
74
+ verboseLogger.info(`\u5F00\u59CB\u89E3\u6790\u6587\u4EF6 ${filePath}`)
75
+ let content = await mpShared.loadFileContent(filePath)
76
+ if (!content || typeof content !== 'object' || lodashEs.isEmpty(content)) {
77
+ verbose &&
78
+ verboseLogger.info(
79
+ `\u6587\u4EF6 ${filePath} \u4E3A\u7A7A\uFF0C\u8DF3\u8FC7`
80
+ )
81
+ continue
82
+ }
83
+ if (!lodashEs.isArray(content)) content = [content]
84
+ verbose &&
85
+ verboseLogger.info(
86
+ `\u6587\u4EF6 ${filePath} \u89E3\u6790\u5B8C\u6210\uFF1A${JSON.stringify(
87
+ content
88
+ )}`
89
+ )
90
+ routeConfigs.push(...content)
91
+ }
92
+ const rs = buildRoute(routeConfigs)
93
+ if (_indexPath) {
94
+ const idx2 = rs.pages.findIndex((page) => page.path === _indexPath)
95
+ if (idx2 !== -1) rs.pages.unshift(...rs.pages.splice(idx2, 1))
96
+ }
97
+ logger.info('\u8DEF\u7531\u6587\u4EF6\u89E3\u6790\u5B8C\u6210')
98
+ if (!rs.condition.list.length) rs.condition = void 0
99
+ else if (rs.condition.list.length && rs.condition.current === -1)
100
+ rs.condition.current = 0
101
+ const idx = rs.pages.findIndex((page) => page['_index'])
102
+ if (idx !== -1) rs.pages.unshift(...rs.pages.splice(idx, 1))
103
+ let tabbarObj
104
+ const [tabbarPath] = loadDirFiles('./src', tabbarName)
105
+ if (tabbarPath && !lodashEs.isEmpty(tabbarPath)) {
106
+ logger.info(`\u6839\u636E ${tabbarName} \u627E\u52301\u4E2A\u6587\u4EF6`)
107
+ tabbarObj = await mpShared.loadFileContent(tabbarPath)
108
+ if (tabbarObj && !lodashEs.isEmpty(tabbarObj)) rs.tabBar = tabbarObj
109
+ }
110
+ const {
111
+ debug: _debug = false,
112
+ pages,
113
+ subPackages,
114
+ preloadRule,
115
+ condition,
116
+ tabBar,
117
+ ...otherProps
118
+ } = await mpShared.loadJson(pagesPath)
119
+ const writeContent = {
120
+ debug: _debug,
121
+ pages: rs.pages || pages,
122
+ subPackages: rs.subPackages || subPackages,
123
+ preloadRule: rs.preloadRule || preloadRule,
124
+ condition: rs.condition || condition,
125
+ tabBar: tabbarObj || tabBar,
126
+ ...otherProps
127
+ }
128
+ await mpShared.outputFile(pagesPath, JSON.stringify(writeContent, null, 2))
129
+ logger.info('\u8DEF\u7531\u6587\u4EF6\u751F\u6210\u5B8C\u6210\uFF01')
130
+ }
131
+ function buildRoute(content, ext = {}) {
132
+ const result = {
133
+ pages: [],
134
+ subPackages: [],
135
+ preloadRule: {},
136
+ condition: {
137
+ current: -1,
138
+ list: []
139
+ }
140
+ }
141
+ const { parentName = '', parentPath = '', subpackageRoot = '' } = ext
142
+ for (const route of content) {
143
+ const {
144
+ subPackages = false,
145
+ isSubpackage = subPackages,
146
+ path: path2,
147
+ title,
148
+ name,
149
+ children
150
+ } = route
151
+ const style = {
152
+ navigationBarTitleText: title || name || parentName,
153
+ ...route.style
154
+ }
155
+ const _path = pathJoin(parentPath, path2)
156
+ if (isSubpackage && !subpackageRoot) {
157
+ let { preLoadPath, preLoadNetwork } = route
158
+ const { pages, preloadRule, condition } = buildRoute(children ?? [], {
159
+ parentName: style.navigationBarTitleText,
160
+ subpackageRoot: _path
161
+ })
162
+ const subPackage = {
163
+ root: _path,
164
+ pages
165
+ }
166
+ result.preloadRule = deepMerge(result.preloadRule, preloadRule)
167
+ result.condition = deepMerge(result.condition, condition)
168
+ if (condition.current > -1)
169
+ result.condition.current = result.condition?.list?.indexOf(
170
+ condition.list[condition.current]
171
+ )
172
+ result.subPackages.push(subPackage)
173
+ if (preLoadPath) {
174
+ if (!lodashEs.isArray(preLoadPath)) preLoadPath = [preLoadPath]
175
+ const preLoadRule = preLoadPath.reduce((acc, cur) => {
176
+ acc[pathJoin(cur)] = {
177
+ network: preLoadNetwork,
178
+ packages: [_path]
179
+ }
180
+ return acc
181
+ }, {})
182
+ result.preloadRule = deepMerge(result.preloadRule, preLoadRule)
183
+ }
184
+ continue
185
+ }
186
+ if (children?.length) {
187
+ const {
188
+ pages,
189
+ subPackages: subPackages2,
190
+ preloadRule,
191
+ condition
192
+ } = buildRoute(children, {
193
+ parentName: style.navigationBarTitleText,
194
+ parentPath: _path,
195
+ subpackageRoot
196
+ })
197
+ result.pages = deepMerge(result.pages, pages)
198
+ result.subPackages = deepMerge(result.subPackages, subPackages2)
199
+ result.preloadRule = deepMerge(result.preloadRule, preloadRule)
200
+ result.condition = deepMerge(result.condition, condition)
201
+ if (condition.current > -1)
202
+ result.condition.current = result.condition?.list?.indexOf(
203
+ condition.list[condition.current]
204
+ )
205
+ } else {
206
+ const { conditionActive, conditionQuery } = route
207
+ const item = {
208
+ path: _path,
209
+ style
210
+ }
211
+ route.isIndex && (_indexPath = _path)
212
+ result.pages.push(item)
213
+ if (conditionQuery || conditionActive) {
214
+ const conditionItem = {
215
+ name: style.navigationBarTitleText,
216
+ path: _path,
217
+ query: conditionQuery
218
+ }
219
+ result.condition.list.push(conditionItem)
220
+ if (conditionActive)
221
+ result.condition.current =
222
+ result.condition.list?.indexOf(conditionItem)
223
+ }
224
+ }
225
+ }
226
+ return result
227
+ }
228
+ var extension = ['.ts', '.js', '.mjs', '.json']
229
+ function loadDirFiles(roots, name, exitByFirst = false) {
230
+ if (!Array.isArray(roots)) roots = [roots]
231
+ const files = []
232
+ for (let root of roots) {
233
+ root = path__default.default.resolve(root)
234
+ if (!fs__default.default.existsSync(root)) continue
235
+ const stat = fs__default.default.statSync(root)
236
+ const regex = new RegExp(`${name}(${extension.join('|')})$`)
237
+ if (stat.isFile() && regex.test(root)) {
238
+ files.push(root)
239
+ if (exitByFirst) break
240
+ }
241
+ if (stat.isDirectory()) {
242
+ const dirents = fs__default.default
243
+ .readdirSync(root)
244
+ .map((o) => path__default.default.resolve(root, o))
245
+ files.push(...loadDirFiles(dirents, name))
246
+ }
247
+ }
248
+ return files
249
+ }
250
+ function pathJoin(...paths) {
251
+ return paths.join('/').split('/').filter(Boolean).join('/')
252
+ }
253
+ function deepMerge(target, ...sources) {
254
+ if (typeof target !== 'object' || target === null) target = {}
255
+ if (!sources.length) return target
256
+ for (const source of sources) {
257
+ if (typeof source !== 'object' || source === null) continue
258
+ if (lodashEs.isArray(target) && lodashEs.isArray(source)) {
259
+ const set = /* @__PURE__ */ new Set([...target, ...source])
260
+ return [...set]
261
+ } else if (
262
+ lodashEs.isPlainObject(target) &&
263
+ lodashEs.isPlainObject(source)
264
+ ) {
265
+ for (const key in source) {
266
+ if (
267
+ key in target &&
268
+ typeof target[key] === 'object' &&
269
+ typeof source[key] === 'object'
270
+ ) {
271
+ target[key] = deepMerge(target[key], source[key])
272
+ } else {
273
+ target[key] = source[key] || target[key]
274
+ }
275
+ }
276
+ }
277
+ }
278
+ return target
279
+ }
280
+
281
+ // src/cli.ts
282
+ commander.program
283
+ .name('uni-route')
284
+ .description(
285
+ `\u8FD9\u662F\u4E00\u4E2A\u7528\u6765\u751F\u6210 uni-app \u8DEF\u7531\u6587\u4EF6\u7684\u5DE5\u5177
286
+ \u901A\u8FC7\u626B\u63CFsrc\u76EE\u5F55\u4E0B\u7684\u914D\u7F6E\u6587\u4EF6\uFF0C\u751F\u6210 uni-app \u8DEF\u7531\u914D\u7F6E\u6587\u4EF6\u3002`
287
+ )
288
+ .version(version)
289
+ commander.program
290
+ .option(
291
+ '-i, --input <input>',
292
+ '\u626B\u63CF\u914D\u7F6E\u7684\u6587\u4EF6\u5939\u5165\u53E3\u8DEF\u5F84',
293
+ 'src/'
294
+ )
295
+ .option(
296
+ '-rn, --routeName <routeName>',
297
+ '\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84',
298
+ 'route'
299
+ )
300
+ .option(
301
+ '-tn, --tabbarName <tabbarName>',
302
+ '\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84',
303
+ 'tabbar'
304
+ )
305
+ .option(
306
+ '-pp, --pagesPath <pagesPath>',
307
+ '\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84',
308
+ 'src/pages.json'
309
+ )
310
+ .option(
311
+ '-vvv, --verbose',
312
+ '\u8F93\u51FA\u8BE6\u7EC6\u7684\u8C03\u8BD5\u4FE1\u606F'
313
+ )
314
+ commander.program
315
+ .command('build', { isDefault: true })
316
+ .description(
317
+ '\u641C\u7D22\u8DEF\u5F84\u4E0B\u7684\u8DEF\u7531\u6587\u4EF6\uFF0C\u751F\u6210\u8DEF\u7531\u914D\u7F6E'
318
+ )
319
+ .action((_, command) => {
320
+ builder(command.optsWithGlobals())
321
+ })
322
+ commander.program
323
+ .command('watch')
324
+ .description(
325
+ '\u76D1\u542C\u6587\u4EF6\u53D8\u5316\uFF0C\u5B9E\u65F6\u751F\u6210\u8DEF\u7531\u914D\u7F6E'
326
+ )
327
+ .option('-t --delay [delay]', '\u5EF6\u8FDF\u65F6\u95F4')
328
+ .action((_, command) => {
329
+ builderWithWatch(command.optsWithGlobals())
330
+ })
331
+ commander.program.parse()
package/dist/cli.d.cts CHANGED
@@ -1 +1 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
package/dist/cli.d.ts CHANGED
@@ -1 +1 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node