import * as fs from "fs-extra-plus"; import * as path from "path"; //生成eval的gen_code let eval_gen_code = fs.readFileSync("src\\Common\\eval.ts", "utf8"); const eval_gen_code_reg = /\/\/eval_gen_code(?:[\s\S])*?\/\/eval_gen_code/g; eval_gen_code = eval_gen_code.match(eval_gen_code_reg)[0]; //cjs的gen_code let eval_gen_code_cjs = eval_gen_code.replaceAll("MathUtils", "three.MathUtils"); function replace_api_file(filePath: string, isCjs = false): Promise { if (!fs.existsSync(filePath)) return; return new Promise((res, rej) => { fs.readFile(filePath, "utf8", (err, data) => { if (err) { console.log("读取失败" + err); res(); return; } data = data.replaceAll("require(\"../GLSL/GoodchSimple.vs\")", "\"\""); data = data.replaceAll("require(\"../GLSL/GoodchSimple.fs\")", "\"\""); data = data.replaceAll("require(\"../GLSL/GoodchSimple2.fs\")", "\"\""); data = data.replaceAll("require(\"../GLSL/GoodchSimpleLogBuf.vs\")", "\"\""); data = data.replaceAll("require(\"../GLSL/GoodchSimpleLogBuf.fs\")", "\"\""); data = data.replaceAll("require(\"./GoodchSimple.vs\")", "\"\""); data = data.replaceAll("require(\"./GoodchSimple.fs\")", "\"\""); data = data.replaceAll("import { iaop } from 'xaop';", "function iaop() { };"); data = data.replaceAll(/^import.*'mobx';\s*$/gm, "function observable() { };\r\nfunction toJS() { };"); data = data.replaceAll("//eval_gen_code", isCjs ? eval_gen_code_cjs : eval_gen_code); fs.writeFile(filePath, data, err => { if (err) console.error(filePath + "操作失败!"); res(); }); }); }); }; function TsIgnore(filePath: string) { if (!fs.existsSync(filePath)) return; let src = fs.readFileSync(filePath, "utf8"); src = src.replaceAll("export interface", "//@ts-ignore\r\nexport interface"); fs.writeFileSync(filePath, src); } async function main() { if (fs.existsSync("./api")) { await replace_api_file(path.resolve(__dirname, "../api/api.cjs.js"), true); await replace_api_file(path.resolve(__dirname, "../api/api.esm.js")); } if (fs.existsSync("./ue4_api")) { await replace_api_file(path.resolve(__dirname, "../ue4_api/api.cjs.js"), true); await replace_api_file(path.resolve(__dirname, "../ue4_api/api.esm.js")); fs.copy(path.resolve(__dirname, "../ue4_api"), path.resolve(__dirname, "../../webcad_ue4_api")); TsIgnore(path.resolve(__dirname, "../ue4_api/types/DatabaseServices/Room/Entity/Wall/RoomWallArc.d.ts")); TsIgnore(path.resolve(__dirname, "../ue4_api/types/DatabaseServices/Room/Entity/Wall/RoomWallBase.d.ts")); TsIgnore(path.resolve(__dirname, "../ue4_api/types/DatabaseServices/Room/Entity/Wall/RoomWallLine.d.ts")); TsIgnore(path.resolve(__dirname, "../ue4_api/types/DatabaseServices/Room/Entity/Wall/Hole/RoomHoleLine.d.ts")); } } main();