101 lines
3.8 KiB
JavaScript
101 lines
3.8 KiB
JavaScript
/**
|
||
* NAC Admin - 生产部署清理脚本
|
||
* 清除dist目录中所有Manus内联引用,确保中国用户可正常访问
|
||
*
|
||
* 清除内容:
|
||
* 1. __manus__ debug-collector 脚本注入
|
||
* 2. manus-analytics.com umami 统计脚本
|
||
* 3. manus.im OAuth 相关引用(已由NAC原生认证替代)
|
||
*/
|
||
|
||
import fs from "fs";
|
||
import path from "path";
|
||
import { fileURLToPath } from "url";
|
||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||
const distDir = path.resolve(__dirname, "../dist");
|
||
|
||
let totalCleaned = 0;
|
||
|
||
function cleanFile(filePath) {
|
||
let content = fs.readFileSync(filePath, "utf-8");
|
||
const original = content;
|
||
|
||
// 0. 清除 manus-runtime 内联脚本(Manus开发平台注入,中国无法访问)
|
||
content = content.replace(/<script id="manus-runtime"[^>]*>[\s\S]*?<\/script>/g, "");
|
||
content = content.replace(/<script id="manus-previewer"[^>]*>[\s\S]*?<\/script>/g, "");
|
||
content = content.replace(/<script id="manus-debug[^"]*"[^>]*>[\s\S]*?<\/script>/g, "");
|
||
|
||
// 1. 清除 __manus__ debug-collector 脚本标签
|
||
content = content.replace(/<script[^>]*src="[^"]*__manus__[^"]*"[^>]*><\/script>/g, "");
|
||
content = content.replace(/<script[^>]*src="[^"]*__manus__[^"]*"[^>]*\/>/g, "");
|
||
content = content.replace(/<script[^>]*defer[^>]*src="[^"]*__manus__[^"]*"[^>]*><\/script>/g, "");
|
||
|
||
// 2. 清除 manus-analytics.com umami 统计脚本
|
||
content = content.replace(/<script[^>]*src="[^"]*manus-analytics\.com[^"]*"[^>]*><\/script>/g, "");
|
||
content = content.replace(/<script[^>]*src="[^"]*manus-analytics\.com[^"]*"[^>]*/g, "");
|
||
|
||
// 3. 清除内联的 debug-collector 注入代码(JS bundle中)
|
||
content = content.replace(/\{tag:"script",attrs:\{src:"[^"]*__manus__[^"]*",defer:!0\},injectTo:"head"\}/g, "{}");
|
||
|
||
// 4. 清除 manus.computer allowedHosts(JS bundle中)
|
||
content = content.replace(/"\.manus\.computer",?/g, "");
|
||
content = content.replace(/"\.manuspre\.computer",?/g, "");
|
||
content = content.replace(/"\.manus-asia\.computer",?/g, "");
|
||
content = content.replace(/"\.manuscomputer\.ai",?/g, "");
|
||
content = content.replace(/"\.manusvm\.computer",?/g, "");
|
||
|
||
if (content !== original) {
|
||
fs.writeFileSync(filePath, content, "utf-8");
|
||
console.log(`✓ 已清理: ${path.relative(distDir, filePath)}`);
|
||
totalCleaned++;
|
||
}
|
||
}
|
||
|
||
function walkDir(dir) {
|
||
if (!fs.existsSync(dir)) {
|
||
console.error(`✗ dist目录不存在: ${dir}`);
|
||
process.exit(1);
|
||
}
|
||
|
||
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
||
for (const entry of entries) {
|
||
const fullPath = path.join(dir, entry.name);
|
||
if (entry.isDirectory()) {
|
||
walkDir(fullPath);
|
||
} else if (entry.isFile() && (entry.name.endsWith(".html") || entry.name.endsWith(".js") || entry.name.endsWith(".css"))) {
|
||
cleanFile(fullPath);
|
||
}
|
||
}
|
||
}
|
||
|
||
// 删除 __manus__ 调试目录
|
||
const manusDir = path.join(distDir, "public/__manus__");
|
||
if (fs.existsSync(manusDir)) {
|
||
fs.rmSync(manusDir, { recursive: true, force: true });
|
||
console.log("✓ 已删除: public/__manus__/ 目录");
|
||
totalCleaned++;
|
||
}
|
||
|
||
console.log("=== NAC Admin 生产部署清理 ===");
|
||
console.log(`目标目录: ${distDir}`);
|
||
console.log("");
|
||
|
||
walkDir(distDir);
|
||
|
||
console.log("");
|
||
console.log(`=== 清理完成:共处理 ${totalCleaned} 个文件 ===`);
|
||
|
||
// 验证清理结果
|
||
const indexHtml = path.join(distDir, "public/index.html");
|
||
if (fs.existsSync(indexHtml)) {
|
||
const html = fs.readFileSync(indexHtml, "utf-8");
|
||
const hasManusRef = html.includes("__manus__") || html.includes("manus-analytics") || html.includes("manus.im") || html.includes('id="manus-runtime"') || html.includes('id="manus-previewer"');
|
||
if (hasManusRef) {
|
||
console.error("✗ 警告:index.html中仍存在Manus引用,请检查!");
|
||
process.exit(1);
|
||
} else {
|
||
console.log("✓ 验证通过:index.html中无Manus内联引用");
|
||
}
|
||
}
|