#!/usr/bin/env node // WXML 结构检查 CLI // // node scripts/check-wxml-structure.mjs miniapp // node scripts/check-wxml-structure.mjs <某个.wxml> [...] // // 退出码:0 = 全部通过;1 = 存在结构错误;2 = 用法/路径错误。 // // 由来:2026-09-19 微信开发者工具报 // `[ WXML 文件编译错误] ./pages/service-history/service-history.wxml get tag end without start` // 而当时 UI 契约门禁 14/14 全绿 —— 说明门禁覆盖不到「WXML 是否可编译」这一层。 // 本脚本 + ui-tests/wxml-structure-contracts.mjs 补上该层。 // // 扫描逻辑见 scripts/lib/wxml-structure.mjs(共用实现,含「为什么不能用正则」的说明)。 import { relative } from 'node:path'; import { checkWxml, isFile, readFileSync, walkWxml } from './lib/wxml-structure.mjs'; const roots = process.argv.slice(2); if (roots.length === 0) { console.error('用法:node scripts/check-wxml-structure.mjs <目录或文件> [...]'); process.exit(2); } const files = []; for (const r of roots) { if (isFile(r)) { files.push(r); continue; } const found = walkWxml(r); if (found.length === 0) { console.error(`未找到 .wxml(路径不存在或目录为空):${r}`); process.exit(2); } files.push(...found); } let failed = 0; for (const f of files) { const errors = checkWxml(readFileSync(f, 'utf8')); if (errors.length) { failed++; console.log(`✗ ${relative(process.cwd(), f)}`); for (const e of errors) console.log(` ${e}`); } } console.log(`\n检查 ${files.length} 个 WXML 文件,结构异常 ${failed} 个`); process.exit(failed ? 1 : 0);