UNPKG

tenderly-wizard-v6

Version:

A tool for managing virtual testnets using Tenderly

63 lines (62 loc) 3.27 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.updatePackageJson = updatePackageJson; exports.stripAnsi = stripAnsi; const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const child_process_1 = require("child_process"); /** * Updates package.json with new scripts * @returns {void} */ // "save:vnet-snapshot": "hardhat run /Users/michaellungu/.nvm/versions/node/v20.13.0/bin/dist/scripts/save-vnet-snapshot.js --network virtual_mainnet" function updatePackageJson() { const tenderlyWizardPath = (0, child_process_1.execSync)("which tenderly-wizard-v6") .toString() .trim(); console.log("tenderlyWizardPath: ", tenderlyWizardPath); // Use fs.realpathSync instead of readlink -f for cross-platform compatibility const appPath = fs_1.default .realpathSync(tenderlyWizardPath) .replace(/(.*tenderly-wizard-v6).*/, "$1"); console.log("appPath: ", appPath); const scriptsToAdd = { "deploy:safes": `hardhat run $(npm root -g)/tenderly-wizard-v6/dist/scripts/deploy-vnet-safes.js --network virtual_mainnet`, "deploy:whitelist": `BYPASS_APPROVALS=true hardhat run $(npm root -g)/tenderly-wizard-v6/dist/scripts/whitelist-vnet-safes.js --network virtual_mainnet`, "execute:whitelist": `BYPASS_APPROVALS=true hardhat run $(npm root -g)/tenderly-wizard-v6/dist/scripts/execute-whitelist-v2-one.js --network virtual_mainnet`, "save:vnet-snapshot": `hardhat run $(npm root -g)/tenderly-wizard-v6/dist/scripts/save-vnet-snapshot.js --network virtual_mainnet`, }; const packageJsonPath = path_1.default.join(process.cwd(), "package.json"); if (fs_1.default.existsSync(packageJsonPath)) { const packageJson = JSON.parse(fs_1.default.readFileSync(packageJsonPath, "utf8")); if (!packageJson.scripts) { packageJson.scripts = {}; } Object.assign(packageJson.scripts, scriptsToAdd); fs_1.default.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2)); console.log("Scripts added to package.json successfully."); return scriptsToAdd; } else { console.error("package.json not found in the current working directory."); } } /** * Removes ANSI escape codes from a string * @param {string} str - The input string containing ANSI escape codes * @returns {string} The cleaned string with all ANSI escape codes removed * @description This function removes all ANSI escape sequences (color codes, cursor movements, etc.) * from a string, making it suitable for logging or processing without formatting characters. * Useful when working with terminal output that needs to be cleaned of formatting. */ function stripAnsi(str) { // Pattern to match all ANSI escape codes const pattern = [ "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)", "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))", ].join("|"); return str.replace(new RegExp(pattern, "g"), ""); }