From 9498f06e42a60f4a1f3bd5a73bd4865dc88bdeee Mon Sep 17 00:00:00 2001 From: lixudong <3365582168@qq.com> Date: Sat, 14 Jun 2025 16:56:34 +0800 Subject: [PATCH 1/4] add card Signed-off-by: lixudong <3365582168@qq.com> --- .../system_api/api_check_utils_new.ts | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 compiler/src/fast_build/system_api/api_check_utils_new.ts diff --git a/compiler/src/fast_build/system_api/api_check_utils_new.ts b/compiler/src/fast_build/system_api/api_check_utils_new.ts new file mode 100644 index 000000000..67ed26b95 --- /dev/null +++ b/compiler/src/fast_build/system_api/api_check_utils_new.ts @@ -0,0 +1,104 @@ +import {projectConfig} from "../../../main"; + + +import * as fs from 'fs'; +import * as path from 'path'; + +// 定义 JSON 数据结构接口 +interface WindowConfig { + designWidth: number; + autoDesignWidth: boolean; +} + +interface FormConfig { + name: string; + displayName: string; + description: string; + src: string; // 目标字段 + uiSyntax: string; + window: WindowConfig; + colorMode: string; + isDynamic: boolean; + isDefault: boolean; + updateEnabled: boolean; + scheduledUpdateTime: string; + updateDuration: number; + defaultDimension: string; + supportDimensions: string[]; +} + +interface ConfigSchema { + forms: FormConfig[]; +} + +/** + * 从 JSON 文件中提取所有 src 字段到数组 + * @param filePath JSON 文件的绝对路径 + * @returns 包含所有 src 字段的字符串数组 + * @throws 文件不存在、JSON 解析错误或数据结构不符时抛出异常 + */ +export function extractSrcPaths(filePath: string): string[] { + // 1. 验证路径格式和存在性 + if (!path.isAbsolute(filePath)) { + throw new Error(`路径必须是绝对路径: ${filePath}`); + } + + if (!fs.existsSync(filePath)) { + throw new Error(`文件不存在: ${filePath}`); + } + + try { + // 2. 读取并解析 JSON 文件 + const rawData = fs.readFileSync(filePath, 'utf-8'); + const config: ConfigSchema = JSON.parse(rawData); + + // 3. 验证数据结构 + if (!config.forms || !Array.isArray(config.forms)) { + throw new Error('JSON 缺少 forms 数组'); + } + + // 4. 提取所有 src 字段 + const srcPaths: string[] = []; + for (const form of config.forms) { + if (form.src && typeof form.src === 'string') { + srcPaths.push(form.src); + } else { + console.warn(`跳过无效 src 字段的表单项: ${form.name}`); + } + } + + // 5. 返回结果数组 + return srcPaths; + } catch (error) { + // 6. 增强错误信息 + if (error instanceof SyntaxError) { + throw new SyntaxError(`JSON 解析错误: ${error.message}`); + } + throw new Error(`处理失败: ${error instanceof Error ? error.message : String(error)}`); + } +} + + +export function isCardFile(file: string): boolean { + + let path = projectConfig.projectPath + projectConfig.aceProfilePath + projectConfig.aceModuleJsonPath; + + let paths: string[] = null; + + if (projectConfig.hasReadForm) { + paths = projectConfig.cardPaths; + } else { + paths = extractSrcPaths(path); + } + + if (paths.length > 0) { + projectConfig.hasReadForm = true; + projectConfig.cardPaths = paths; + } else { + return false; + } + + return paths.includes(file); + + +} -- Gitee From ad28df0a9ba39ecead9beca447d7ea1305e3f9b1 Mon Sep 17 00:00:00 2001 From: lixudong <3365582168@qq.com> Date: Sat, 14 Jun 2025 16:58:48 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0card=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lixudong <3365582168@qq.com> --- compiler/main.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/main.js b/compiler/main.js index fe52a7825..8141bc580 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -112,6 +112,8 @@ function initProjectConfig(projectConfig) { projectConfig.allowEmptyBundleName = false; projectConfig.uiTransformOptimization = false; projectConfig.ignoreCrossplatformCheck = false; + projectConfig.hasReadForm = false; + projectConfig.cardPaths = []; } function initProjectPathConfig(projectConfig) { -- Gitee From d2cdaef37bc22ab027d926b4b31f538a9affeb98 Mon Sep 17 00:00:00 2001 From: lixudong <3365582168@qq.com> Date: Tue, 17 Jun 2025 14:13:06 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0card=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lixudong <3365582168@qq.com> --- compiler/src/fast_build/system_api/api_check_utils_new.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/fast_build/system_api/api_check_utils_new.ts b/compiler/src/fast_build/system_api/api_check_utils_new.ts index 67ed26b95..2b93f374d 100644 --- a/compiler/src/fast_build/system_api/api_check_utils_new.ts +++ b/compiler/src/fast_build/system_api/api_check_utils_new.ts @@ -81,7 +81,7 @@ export function extractSrcPaths(filePath: string): string[] { export function isCardFile(file: string): boolean { - let path = projectConfig.projectPath + projectConfig.aceProfilePath + projectConfig.aceModuleJsonPath; + let path = projectConfig.aceProfilePath + "\form_config.json"; let paths: string[] = null; -- Gitee From d1c4a88b544ab85cf37ed27f607cdb562ee28a45 Mon Sep 17 00:00:00 2001 From: lixudong <3365582168@qq.com> Date: Tue, 17 Jun 2025 15:46:47 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0card=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lixudong <3365582168@qq.com> --- compiler/src/fast_build/system_api/api_check_utils_new.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/src/fast_build/system_api/api_check_utils_new.ts b/compiler/src/fast_build/system_api/api_check_utils_new.ts index 2b93f374d..25d85fa5a 100644 --- a/compiler/src/fast_build/system_api/api_check_utils_new.ts +++ b/compiler/src/fast_build/system_api/api_check_utils_new.ts @@ -61,7 +61,8 @@ export function extractSrcPaths(filePath: string): string[] { const srcPaths: string[] = []; for (const form of config.forms) { if (form.src && typeof form.src === 'string') { - srcPaths.push(form.src); + let src = form.src.replace(/^\.\/ets/, ''); + srcPaths.push(projectConfig.projectPath + src); } else { console.warn(`跳过无效 src 字段的表单项: ${form.name}`); } -- Gitee