@biconomy/ecosystem
Version:
Testing infrastructure for abstractjs with ephemeral networks
81 lines (80 loc) • 2.74 kB
JavaScript
import fs from 'node:fs';
import path from 'node:path';
import { exit, argv } from 'node:process';
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var getArgValue = /* @__PURE__ */ __name((argName) => {
const args = argv;
const arg = args.find((arg2) => arg2.startsWith(`--${argName}=`));
if (arg) {
return arg.split("=")[1];
}
return null;
}, "getArgValue");
var newChainIdString = getArgValue("chainId");
var templateDir = getArgValue("templateDir");
var outputDir = getArgValue("outputDir");
if (!newChainIdString) {
console.error(
"Error: --chainId argument is missing. Please provide it like --chainId=12345"
);
exit(1);
}
if (!templateDir) {
console.error(
"Error: --templateDir argument is missing. Please provide it like --templateDir=/path/to/templates"
);
exit(1);
}
if (!outputDir) {
console.error(
"Error: --outputDir argument is missing. Please provide it like --outputDir=/path/to/output"
);
exit(1);
}
var newChainIdNum = Number.parseInt(newChainIdString, 10);
if (Number.isNaN(newChainIdNum)) {
console.error("Error: --chainId must be a number.");
exit(1);
}
var sourceFilePath = path.join(templateDir, "84532.json");
var targetFilePath = path.join(outputDir, `${newChainIdString}.json`);
async function main() {
try {
await fs.promises.mkdir(outputDir, { recursive: true });
const sourceContent = await fs.promises.readFile(sourceFilePath, "utf-8");
const chainConfig = JSON.parse(sourceContent);
const originalRpcFromTemplate = chainConfig.rpc;
chainConfig.name = newChainIdString;
chainConfig.chainId = newChainIdString;
const placeholderRpc = "<YOUR RPC URL (debug_traceCall enabled)>";
if (chainConfig.rpc === placeholderRpc) {
chainConfig.rpc = `http://host.docker.internal:${newChainIdString}`;
}
const newJsonContent = JSON.stringify(chainConfig, null, 4);
await fs.promises.writeFile(targetFilePath, newJsonContent);
console.log(
`Successfully duplicated and updated chain config to ${targetFilePath}`
);
if (originalRpcFromTemplate !== chainConfig.rpc) {
console.log(
`RPC in new file: ${chainConfig.rpc} (changed from: ${originalRpcFromTemplate})`
);
} else {
console.log(
`RPC in new file: ${chainConfig.rpc} (unchanged from template)`
);
}
} catch (error) {
if (error instanceof Error) {
console.error(`An error occurred: ${error.message}`);
} else {
console.error("An unknown error occurred.");
}
exit(1);
}
}
__name(main, "main");
main();
//# sourceMappingURL=duplicate-chain.mjs.map
//# sourceMappingURL=duplicate-chain.mjs.map