#!/usr/bin/env bun // 生成 src/domains/seal/linter/plaintext.generated.ts: // 把 manifest 中 plaintext: true 的官方校验器源码嵌入为字符串, // 供 syncOfficialLinters 写入 ~/.config/seal-use/linters/official/。 // 修改 checkers/ 下任一源码后运行 `bun run generate:linter-plaintext` 刷新。 import { readFileSync, writeFileSync } from "node:fs"; import { join } from "node:path"; const ROOT = join(import.meta.dirname, ".."); const manifestPath = join(ROOT, "src/domains/seal/linter/manifest.ts"); const generatedPath = join(ROOT, "src/domains/seal/linter/plaintext.generated.ts"); // 从 manifest.ts 提取 (name, file, plaintext) —— 保持与运行时同一份清单 const manifestSource = readFileSync(manifestPath, "utf8"); const entries = [...manifestSource.matchAll( /name: "([a-z0-9-]+)",\s*\n\s*file: "([a-z.]+)",\s*\n\s*plaintext: (true|false)/g )].map((m) => ({ name: m[1], file: m[2], plaintext: m[3] === "true" })); if (entries.length === 0) { console.error("❌ 未从 manifest.ts 解析到任何校验器条目"); process.exit(1); } const plaintext = {}; for (const entry of entries) { if (!entry.plaintext) continue; const filePath = join(ROOT, "src/domains/seal/linter/checkers", entry.file); plaintext[entry.file] = readFileSync(filePath, "utf8"); } const banner = "/**\n * 生成文件 —— 由 scripts/generate-linter-plaintext.mjs 从 linter/checkers/ 生成,勿手改。\n" + ` * 明文下发的官方校验器源码(manifest.ts 中 plaintext: true 的条目)。\n */\n`; const content = banner + `export const OFFICIAL_LINTER_PLAINTEXT: Record = ${JSON.stringify(plaintext, null, 2)};\n`; writeFileSync(generatedPath, content); console.log(`✓ 已生成 plaintext.generated.ts(${Object.keys(plaintext).length} 个明文校验器: ${Object.keys(plaintext).join(", ")})`);