ethers.js/testcases/test-env/test-tsc/prepare.cjs

32 lines
958 B
JavaScript
Raw Normal View History

2023-04-28 14:11:35 +03:00
const fs = require("fs");
function replace(filename, key, value) {
2023-04-28 14:14:46 +03:00
let data = fs.readFileSync(filename).toString();
2023-04-28 14:11:35 +03:00
data = data.replace(key, value);
fs.writeFileSync(filename, data);
}
// TypeScript moduleResolution: node, node16, nodenext
const tsModuleResolution = process.argv[2];
2023-04-28 14:11:35 +03:00
// Package module: commonjs, es2020
const pModule = process.argv[3];
2023-04-28 14:11:35 +03:00
// TypeScript module: node=pModule, otherwise=pModuleResolution
const tsModule = ({
node16: "node16",
nodenext: "nodenext"
2023-10-11 09:12:06 +03:00
})[tsModuleResolution] || pModule;
// Package type: commonjs, module
const pType = (pModule === "commonjs") ? "commonjs": "module";
// Replace necessary properties in tsconfig.json and package.json
replace("tsconfig.json", "${TS_MODULE_RESOLUTION}", tsModuleResolution);
replace("tsconfig.json", "${TS_MODULE}", tsModule);
replace("package.json", "${PKG_TYPE}", pType);
2023-04-28 14:11:35 +03:00
// JavaScript
fs.writeFileSync("index.ts", fs.readFileSync("js-" + pType + ".ts"));