import * as fs from "fs-extra-plus"; import * as path from "path"; function replace_api_file(filePath: string): Promise { 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() { };"); fs.writeFile(filePath, data, err => { if (err) console.error(filePath + "操作失败!"); res(); }); }); }); } function TsIgnore(filePath: string) { let src = fs.readFileSync(filePath, "utf8"); src = src.replaceAll("export interface", "//@ts-ignore\r\nexport interface"); fs.writeFileSync(filePath, src); } async function main() { await replace_api_file(path.resolve(__dirname, "../ue4_api/api.cjs.js")); await replace_api_file(path.resolve(__dirname, "../ue4_api/api.esm.js")); await replace_api_file(path.resolve(__dirname, "../api/api.cjs.js")); await replace_api_file(path.resolve(__dirname, "../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();