Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify elif and else expression result, add path when missing for lite card #77

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 3 additions & 23 deletions packages/hap-compiler/src/template/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -1626,9 +1626,7 @@ function checkIf(value, output, not, locationInfo, conditionList) {
value = exp.addExprffix(value)
const isLite = output.isLite
if (not) {
value = isLite
? buildLiteConditionExp(conditionList)
: '{{' + buildConditionExp(conditionList) + '}}'
value = '{{' + buildConditionExp(conditionList) + '}}'
} else {
// if动作前需要清除conditionList之前的结构
conditionList.length > 0 && (conditionList.length = 0)
Expand Down Expand Up @@ -1673,13 +1671,8 @@ function checkElif(value, cond, output, locationInfo, conditionList) {
value = exp.addExprffix(value)
cond = exp.addExprffix(cond)
const isLite = output.isLite
newcond = isLite
? '{{' + value.substr(2, value.length - 4) + '}}&&' + buildLiteConditionExp(conditionList)
: '{{(' +
value.substr(2, value.length - 4) +
') && ' +
buildConditionExp(conditionList) +
'}}'
newcond =
'{{(' + value.substr(2, value.length - 4) + ') && ' + buildConditionExp(conditionList) + '}}'

// 将表达式转换为function
output.result.shown = isLite ? newcond : exp(newcond)
Expand Down Expand Up @@ -1964,19 +1957,6 @@ function buildConditionExp(list) {
.join(' && ')
}

/**
* 输出轻卡条件取反的字符串表示
* @param list
* @return {string}
*/
function buildLiteConditionExp(list) {
return list
.map((exp) => {
return `!{{${exp}}}`
})
.join('&&')
}

/**
* 检查节点中是否含有指令 if 或者 for
* @param {Array} nodes
Expand Down
2 changes: 1 addition & 1 deletion packages/hap-packager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"babel.tree.config.js"
],
"dependencies": {
"@aiot-toolkit/card-expression": "^1.0.11",
"@aiot-toolkit/card-expression": "^1.0.12",
"@babel/core": "^7.9.6",
"@babel/generator": "^7.9.6",
"@babel/parser": "^7.9.6",
Expand Down
14 changes: 10 additions & 4 deletions packages/hap-packager/src/plugins/resource-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ function getWidgetI18nJSONFiles(sourceDir) {
}
let filesArray = []
for (let key in widgetsOption) {
if (!widgetsOption[key].path) {
widgetsOption[key].path = key
}
const widgetPath = widgetsOption[key].path
const dir = path.join(sourceDir, widgetPath, 'i18n')
// const jsonPath = onlyRoot ? '*.json' : '**/**.json'
Expand All @@ -122,24 +125,27 @@ function minifyWidgetI18nJSONFiles(targetDir) {
}
let arr = []
for (let key in widgetsOption) {
if (!widgetsOption[key].path) {
widgetsOption[key].path = key
}
const widgetPath = widgetsOption[key].path
const isLite = widgetsOption[key].type === 'lite'
const needFlatten = widgetsOption[key].type === 'lite'
const dir = path.join(targetDir, widgetPath, 'i18n')
if (fs.existsSync(dir)) {
const jsonFiles = getFiles('*.json', dir)
jsonFiles.forEach((filePath) => {
arr.push(filePath)
minifyJson(filePath, filePath, isLite)
minifyJson(filePath, filePath, needFlatten)
})
}
}
}

function minifyJson(source, target, isLite) {
function minifyJson(source, target, needFlatten) {
try {
const contentStr = fs.readFileSync(source, 'utf8')
let content = JSON.parse(contentStr)
if (isLite) {
if (needFlatten) {
content = flatten.flatten(content)
}
const minifiedContent = JSON.stringify(content)
Expand Down
8 changes: 5 additions & 3 deletions packages/hap-toolkit/src/gen-webpack-conf/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ export function validateJson(jsonInfo, filePath) {
const ajv = new Ajv({ allErrors: true, jsonPointers: true })
AjvErrors(ajv)
ajv.addKeyword('requireError', {
validate: function (schema, data) {
if (!data || !data.widgets) {
validate: function (schema, router) {
// 纯快应用工程:router 字段下 entry/pages 必填
// 快应用、卡片混合工程:无需校验 entry/pages 必填性
// 纯卡片工程:无需校验 entry/pages 必填性
if (!router.widgets && (!router.entry || !router.pages)) {
const message = `快应用项目 manifest.json 中,router 字段下 ${JSON.stringify(
schema
)} 字段为必填`
colorconsole.error(message)
}
// 项目工程有卡片时无需校验 entry 和 pages 字段的必填性
return true
}
})
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# yarn lockfile v1


"@aiot-toolkit/card-expression@^1.0.11":
version "1.0.11"
resolved "https://registry.npmmirror.com/@aiot-toolkit/card-expression/-/card-expression-1.0.11.tgz#1f61389231310ea1ef6d887cc04171513740ed6d"
integrity sha512-FGP/3WUQQeZDl9WK0NNCfoBADsyhfJYDHaRFw/m4314kXvVuYRmLQABiFYCHgF5rZhYxar6kd3P4EywRpQRA0g==
"@aiot-toolkit/card-expression@^1.0.12":
version "1.0.12"
resolved "https://registry.npmmirror.com/@aiot-toolkit/card-expression/-/card-expression-1.0.12.tgz#6e734d372fd8dd1fae5ff643fe590cdca9a5d97a"
integrity sha512-fN/2L4JuStIvW30z5joCvhN+qtcDlGfkMdXGx6o3gMl2lmqqQVKmcnJq9vbe2uL8E1AMTm6f3/YhZ5AYmOk2pA==
dependencies:
"@babel/generator" "^7.25.6"
"@babel/parser" "^7.25.6"
Expand Down
Loading