diff --git a/packages/hap-compiler/src/template/validator.js b/packages/hap-compiler/src/template/validator.js index c0e073c..c167ffe 100644 --- a/packages/hap-compiler/src/template/validator.js +++ b/packages/hap-compiler/src/template/validator.js @@ -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) @@ -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) @@ -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 diff --git a/packages/hap-packager/package.json b/packages/hap-packager/package.json index 9ce5561..85dd63e 100644 --- a/packages/hap-packager/package.json +++ b/packages/hap-packager/package.json @@ -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", diff --git a/packages/hap-packager/src/plugins/resource-plugin.js b/packages/hap-packager/src/plugins/resource-plugin.js index 3eb123d..5347b21 100644 --- a/packages/hap-packager/src/plugins/resource-plugin.js +++ b/packages/hap-packager/src/plugins/resource-plugin.js @@ -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' @@ -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) diff --git a/packages/hap-toolkit/src/gen-webpack-conf/validate.js b/packages/hap-toolkit/src/gen-webpack-conf/validate.js index dcefb60..85d57f7 100644 --- a/packages/hap-toolkit/src/gen-webpack-conf/validate.js +++ b/packages/hap-toolkit/src/gen-webpack-conf/validate.js @@ -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 } }) diff --git a/yarn.lock b/yarn.lock index b5e6c3b..9fae784 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"