Skip to content

Commit 15965e5

Browse files
pengjieJayFate
authored andcommitted
fix: packages/hap-toolkit/bin/index.js
Signed-off-by: pengjie <[email protected]>
1 parent 9f2d248 commit 15965e5

File tree

1 file changed

+43
-7
lines changed

1 file changed

+43
-7
lines changed

packages/hap-toolkit/bin/index.js

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ program.version(require('../package').version, '-v, --version').usage('<command>
3131

3232
program
3333
.command('init <app-name>')
34+
.option('--dsl <name>', 'init project by specific dsl template, eg: vue')
3435
.option(
3536
'-d --deviceType <deviceTypeList>',
3637
'init project by specific device separated with comma "," eg: tv,car'
@@ -78,11 +79,15 @@ program
7879
'custom output rpk file name',
7980
validateBuildNameFormat
8081
)
82+
.option(
83+
'--target [target]',
84+
'构建应用的类型(卡片或APP),值只能为app、card、 all, 默认all',
85+
'all'
86+
)
8187
.action((options) => {
8288
// 必备参数:当开发者不传递该参数时,要解析为默认
8389
const signModeTmp = options.disableSign && compileOptionsMeta.signModeEnum.NULL
8490
options.signMode = validateSignMode(signModeTmp, compileOptionsMeta.signModeEnum.BUILD)
85-
8691
const { compile } = require('../lib/commands/compile')
8792
compile('native', 'dev', false, options)
8893
})
@@ -204,6 +209,11 @@ program
204209
'custom output rpk file name',
205210
validateBuildNameFormat
206211
)
212+
.option(
213+
'--target [target]',
214+
'构建应用的类型(卡片或APP),值只能为app、card、 all, 默认all',
215+
'all'
216+
)
207217
.action((options) => {
208218
// 必备参数:当开发者不传递该参数时,要解析为默认
209219
const signModeTmp = options.disableSign && compileOptionsMeta.signModeEnum.NULL
@@ -213,6 +223,20 @@ program
213223
compile('native', 'prod', false, options)
214224
})
215225

226+
program
227+
.command('remote-preview')
228+
.description('preview app by the qrcode')
229+
.option('-o,--qr-output <path>', 'the qr-image will be output to the specified directory')
230+
.option('--env <env>', "switching the environment, 'production' or 'development'")
231+
.action((options) => {
232+
const { compile } = require('../lib/commands/compile')
233+
const signModeTmp = options.disableSign && compileOptionsMeta.signModeEnum.NULL
234+
options.signMode = validateSignMode(signModeTmp, compileOptionsMeta.signModeEnum.RELEASE)
235+
options.compile = compile
236+
237+
const { remotePreview } = require('@hap-toolkit/server')
238+
remotePreview(options)
239+
})
216240
program
217241
.command('preview <target>')
218242
.description('preview app in your browser')
@@ -430,14 +454,26 @@ function validateSplitChunksMode(value) {
430454
* @return {string}
431455
*/
432456
function validateBuildNameFormat(value) {
433-
// 转成枚举常量比较
434-
value = value.toUpperCase()
435-
436-
let ret = value
457+
let ret = value.toUpperCase()
458+
const reg = /(^custom=)(.*)/i
459+
if (!compileOptionsMeta.buildNameFormat[ret]) {
460+
ret = value.replace(reg, 'CUSTOM=$2')
461+
}
437462

438-
if (!compileOptionsMeta.buildNameFormat[value]) {
463+
if (
464+
(!compileOptionsMeta.buildNameFormat[ret] && !ret.startsWith('CUSTOM=')) ||
465+
ret === 'CUSTOM='
466+
) {
467+
if (ret.startsWith('CUSTOM')) {
468+
colorconsole.warn(
469+
`当前buildNameFormat参数不支持: ${value} ,请添加自定义custom值,改为默认值:${compileOptionsMeta.buildNameFormat.DEFAULT}`
470+
)
471+
} else {
472+
colorconsole.warn(
473+
`当前buildNameFormat参数不支持: ${value} ,改为默认值:${compileOptionsMeta.buildNameFormat.DEFAULT}`
474+
)
475+
}
439476
ret = compileOptionsMeta.buildNameFormat.DEFAULT
440-
colorconsole.warn(`当前buildNameFormat参数不支持: ${value} ,改为默认值:${ret}`)
441477
}
442478
return ret
443479
}

0 commit comments

Comments
 (0)