Skip to content

Commit fbdbd57

Browse files
authored
fix: add rpk in watch mode and add validator for some csses and prope… (#115)
* fix: add rpk when in watch mode Signed-off-by: lilei946 <snowinter2008@gmail.com> * feat: add validator for some csses and properties Signed-off-by: lilei946 <snowinter2008@gmail.com> --------- Signed-off-by: lilei946 <snowinter2008@gmail.com>
1 parent a08613c commit fbdbd57

File tree

5 files changed

+75
-29
lines changed

5 files changed

+75
-29
lines changed

packages/hap-compiler/src/style/validator.js

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,26 @@ const validator = {
579579
}
580580
}
581581
},
582+
maxLength: function (v, units, defaultValueIfNotSupported) {
583+
v = (v || '').toString().trim()
584+
if (v === 'none') {
585+
return {
586+
value: v
587+
}
588+
} else {
589+
return validator.length(v, units, defaultValueIfNotSupported)
590+
}
591+
},
592+
minLength: function (v, units, defaultValueIfNotSupported) {
593+
v = (v || '').toString().trim()
594+
if (v === 'auto') {
595+
return {
596+
value: v
597+
}
598+
} else {
599+
return validator.length(v, units, defaultValueIfNotSupported)
600+
}
601+
},
582602
/**
583603
* 颜色值校验, 支持 rgb, rgba, #fff, #ffffff, named-color #f0ff #ff00ff00
584604
* @param v
@@ -2418,6 +2438,16 @@ const validator = {
24182438
)
24192439
}
24202440
}
2441+
},
2442+
letterSpacing: function (v, units, defaultValueIfNotSupported) {
2443+
v = (v || '').toString().trim()
2444+
if (v === 'normal') {
2445+
return {
2446+
value: v
2447+
}
2448+
} else {
2449+
return validator.length(v, units, defaultValueIfNotSupported)
2450+
}
24212451
}
24222452
}
24232453

@@ -2517,10 +2547,10 @@ const validatorMap = {
25172547
transitionTimingFunction: validateTimingFunction,
25182548
width: validator.length,
25192549
height: validator.length,
2520-
minHeight: validator.length,
2521-
minWidth: validator.length,
2522-
maxHeight: validator.length,
2523-
maxWidth: validator.length,
2550+
minHeight: validator.minLength,
2551+
minWidth: validator.minLength,
2552+
maxHeight: validator.maxLength,
2553+
maxWidth: validator.maxLength,
25242554
padding: makeAbbrAttrValidator('arraylength', [
25252555
'paddingTop',
25262556
'paddingRight',
@@ -2684,7 +2714,8 @@ const validatorMap = {
26842714
themeThumbColor: makeEnumValidator(themeColors),
26852715
themeTrackColor: makeEnumValidator(themeColors),
26862716
themeSelectColor: makeEnumValidator(themeColors),
2687-
themeBlockColor: makeEnumValidator(themeColors)
2717+
themeBlockColor: makeEnumValidator(themeColors),
2718+
letterSpacing: validator.letterSpacing
26882719
}
26892720

26902721
/**

packages/hap-compiler/src/template/validator.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ const tagCommon = {
9191
},
9292
descendantfocusability: {
9393
enum: ['before', 'after', 'block']
94+
},
95+
overflow: {
96+
enum: ['visible', 'hidden']
9497
}
9598
},
9699
children: ['block', 'slot', 'component'], // 通用控制组件

packages/hap-packager/src/process/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { colorconsole } from '@hap-toolkit/shared-utils'
6+
import { colorconsole, isNeedFullPackage } from '@hap-toolkit/shared-utils'
77

88
import { SINGLE_PKG_SIZE, FULL_PKG_SIZE } from '../common/constant'
99

@@ -55,12 +55,12 @@ async function buildDebugModeProjectAndOutput(
5555
disableStreamPack
5656
) {
5757
const { privatekey, certificate } = signConfig
58-
const hasSubPackages = subPackages.length
58+
const needFullPackage = isNeedFullPackage()
5959

6060
let fullPackageBuffer
6161

6262
// Step1. 生成整包rpk
63-
if (!hasSubPackages) {
63+
if (needFullPackage) {
6464
fullPackageBuffer = await createAndSignBuffer(fullPackage, privatekey, certificate)
6565
}
6666

@@ -73,7 +73,7 @@ async function buildDebugModeProjectAndOutput(
7373

7474
// Step3. 默认携带META,如果禁用流失打包,需要删除META
7575
if (disableStreamPack) {
76-
if (!hasSubPackages) {
76+
if (needFullPackage) {
7777
fullPackageBuffer = await removeMetaForRpkOrRpksFile(fullPackageBuffer)
7878
}
7979
subPackageBuffers = await Promise.all(subPackageBuffers.map(removeMetaForRpkOrRpksFile))

packages/hap-packager/src/router/routes.js

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import moment from 'moment'
1010

1111
import {
1212
colorconsole,
13-
readJson,
1413
relateCwd,
1514
globalConfig,
1615
recordClient,
17-
getRecordClient
16+
getRecordClient,
17+
isNeedFullPackage
1818
} from '@hap-toolkit/shared-utils'
1919

2020
import {
@@ -64,26 +64,13 @@ async function bundle(context, next) {
6464
const projectName = projectInfo.projectName
6565
const projectVersion = projectInfo.projectVersion
6666
const platformVersion = context.request.query.platformVersion
67-
let useAppRpk = false
68-
// 应用模式下
67+
let useFullPackage = false
68+
// 调试器选择应用模式下
6969
if (parseInt(context.request.query.mode || 0) === 0) {
70-
// 读取 manifest
71-
let manifest
72-
try {
73-
manifest = readJson(path.join(projectPath, './src/manifest.json'))
74-
} catch (err) {
75-
manifest = null
76-
}
77-
// 不存在分包
78-
if (manifest && manifest.router && (!manifest.subpackages || manifest.subpackages.length === 0)) {
79-
// 存在卡片
80-
if (manifest.router.widgets && Object.keys(manifest.router.widgets).length > 0) {
81-
useAppRpk = true
82-
}
83-
}
70+
useFullPackage = isNeedFullPackage(projectPath)
8471
}
85-
86-
if (platformVersion && platformVersion >= RPKS_SUPPORT_VERSION_FROM && !useAppRpk) {
72+
73+
if (platformVersion && platformVersion >= RPKS_SUPPORT_VERSION_FROM && !useFullPackage) {
8774
distFile = getDistFilePath(projectDist, projectName, projectVersion, 'rpks')
8875
}
8976
if (!distFile) {

packages/hap-shared-utils/src/index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,3 +435,28 @@ function getHash(compPath) {
435435
}
436436
return res
437437
}
438+
439+
export function isNeedFullPackage() {
440+
// 读取 manifest
441+
let manifest
442+
let needFullPackage = false
443+
try {
444+
manifest = readJson(path.join(globalConfig.projectPath, './src/manifest.json'))
445+
} catch (err) {
446+
manifest = null
447+
}
448+
// 快应用项目,不存在分包
449+
if (
450+
manifest &&
451+
manifest.router &&
452+
manifest.router.pages &&
453+
manifest.router.pages.length > 0 &&
454+
(!manifest.subpackages || manifest.subpackages.length === 0)
455+
) {
456+
// 存在卡片
457+
if (manifest.router.widgets && Object.keys(manifest.router.widgets).length > 0) {
458+
needFullPackage = true
459+
}
460+
}
461+
return needFullPackage
462+
}

0 commit comments

Comments
 (0)