diff --git a/compiler/main.js b/compiler/main.js index fe52a7825d6ba5650ea1f53fc1f99f08f3c6b0a2..8141bc58099af7b5d7368a5bca6f56ab36de9eb3 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) { 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 0000000000000000000000000000000000000000..25d85fa5a4b0ffa278be5905a8e5f2b45d570afa --- /dev/null +++ b/compiler/src/fast_build/system_api/api_check_utils_new.ts @@ -0,0 +1,105 @@ +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') { + let src = form.src.replace(/^\.\/ets/, ''); + srcPaths.push(projectConfig.projectPath + 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.aceProfilePath + "\form_config.json"; + + 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); + + +}