import * as child_process from 'child_process'; import * as fs from "fs-extra-plus"; import simpleGit from 'simple-git'; import util from 'util'; /** * 导出api给生产优化使用,与ueapi不一样的是这里不导出绘制函数 */ const exec = util.promisify(child_process.exec); const REG_DEL = /\/\/del_exp_start(?:[\s\S])*?\/\/del_exp_end/g; //针对api单独移除绘制部分的代码 const REG_DEL2 = /\/\/del_exp2_start(?:[\s\S])*?\/\/del_exp2_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"]); for (let file of files) { let str = await fs.readFile(file, "utf-8"); let length = str.length; str = str.replaceAll(REG_DEL, ""); str = str.replaceAll(REG_DEL2, ""); if (length !== str.length) await fs.writeFile(file, str);//替换 } //清除不需要的依赖 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 ."); } catch (error) { console.log(error); } } main();