claude-code/scripts/remove-sourcemaps.mjs
weiqianpu cf1707bbb0 feat: 开源发布 — 完整 README、MIT 许可证、22+ 大模型厂商支持
- 重写 README.md:项目简介、快速开始、22+ 厂商列表、功能特性、架构说明、配置指南、FAQ、贡献指南
- 新增 MIT LICENSE
- 包含全部源码与文档
2026-04-02 02:34:24 +00:00

41 lines
1.2 KiB
JavaScript
Executable File

#!/usr/bin/env node
/**
* 清除 src/ 下所有 .ts/.tsx 文件中的 //# sourceMappingURL= 行
* 用法: node scripts/remove-sourcemaps.mjs [--dry-run]
*/
import { readdir, readFile, writeFile } from "fs/promises";
import { join, extname } from "path";
const SRC_DIR = new URL("../src", import.meta.url).pathname;
const DRY_RUN = process.argv.includes("--dry-run");
const EXTENSIONS = new Set([".ts", ".tsx"]);
const PATTERN = /^\s*\/\/# sourceMappingURL=.*$/gm;
async function* walk(dir) {
for (const entry of await readdir(dir, { withFileTypes: true })) {
const full = join(dir, entry.name);
if (entry.isDirectory()) {
yield* walk(full);
} else if (EXTENSIONS.has(extname(entry.name))) {
yield full;
}
}
}
let total = 0;
for await (const file of walk(SRC_DIR)) {
const content = await readFile(file, "utf8");
if (!PATTERN.test(content)) continue;
// reset lastIndex after test
PATTERN.lastIndex = 0;
const cleaned = content.replace(PATTERN, "").replace(/\n{3,}/g, "\n\n");
if (DRY_RUN) {
console.log(`[dry-run] ${file}`);
} else {
await writeFile(file, cleaned, "utf8");
}
total++;
}
console.log(`\n${DRY_RUN ? "[dry-run] " : ""}Processed ${total} files.`);