ethers.js/testcases/test-env/test-tsc/prepare.cjs
2023-04-28 21:10:09 +09:00

21 lines
628 B
JavaScript

const fs = require("fs");
function replace(filename, key, value) {
let data = fs.readFileSync(filename).toString();
data = data.replace(key, value);
fs.writeFileSync(filename, data);
}
// moduleResolution: node, node16, nodenext
replace("tsconfig.json", "${TS_MODULE_RESOLUTION}", process.argv[2]);
// module: commonjs, es2020
replace("tsconfig.json", "${TS_MODULE}", process.argv[3]);
// type: commonjs, module
const type = (process.argv[3] === "commonjs") ? "commonjs": "module";
replace("package.json", "${PKG_TYPE}", type);
// JavaScript
fs.writeFileSync("index.ts", fs.readFileSync("js-" + type + ".ts"));