You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
WebCAD/utils/GenEntityExp.ts

67 lines
1.9 KiB

import * as child_process from 'child_process';
import * as fs from "fs-extra-plus";
import simpleGit from 'simple-git';
import util from 'util';
const exec = util.promisify(child_process.exec);
const REG_DEL = /\/\/del_exp_start(?:[\s\S])*?\/\/del_exp_end/g;
async function main()
{
console.log("我们将临时修改源代码,请注意回滚代码");
let status = await simpleGit().status();
if (status.files.length)
{
console.error("文件未提交,请保持git是清洁的,正常的!");
return;
}
let files = await fs.glob(["./src/**/*.ts"]);
let containerEntityFiles: string[] = [];
for (let file of files)
{
let str = await fs.readFile(file, "utf-8");
let length = str.length;
str = str.replaceAll(REG_DEL, "");
if (length !== str.length)
await fs.writeFile(file, str);//替换
if (str.includes("@Factory"))
containerEntityFiles.push(`export * from "./${file.substring(6, file.length - 3)}"`);
}
console.log("正在写出导入");
await fs.writeFile("./src/entitys.exp.ts", containerEntityFiles.join("\r\n"));
{
let str = await fs.readFile("./src/ueapi.ts", "utf-8");
str += "\r\nexport * from \"./entitys.exp\";";
str += "\r\nexport * from \"./DatabaseServices/CADFiler\";";
str += "\r\nexport * from \"./DatabaseServices/Database\";";
str += "\r\nexport * from \"./GraphicsSystem/CameraUpdate\";";
await fs.writeFile("./src/ueapi.ts", str);
}
console.log("正在删除导入");
//清除不需要的依赖 https://wesleygrimes.com/angular/2019/02/14/how-to-use-tslint-to-autoremove-all-unused-imports-in-a-typescript-project.html
try
{
await exec("tslint --config ./utils/tslint-clear-no-unused-imports.json --fix --project apitsconfig.json");
} catch (error)
{
console.log(error);
}
}
main();