UNPKG

@vechain/vebetterdao-contracts

Version:

Open-source repository that houses the smart contracts powering the decentralized VeBetterDAO on the VeChain Thor blockchain.

53 lines (52 loc) 2.38 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const inquirer_1 = __importDefault(require("inquirer")); const child_process_1 = require("child_process"); const functionsConfig_1 = require("./functionsConfig"); const config_1 = require("@repo/config"); async function runFunction() { try { const env = process.env.NEXT_PUBLIC_APP_ENV; if (!env) throw new Error("Environment variable NEXT_PUBLIC_APP_ENV is not set."); const config = (0, config_1.getConfig)(env); // Prompt user to select a function const { functionName } = await inquirer_1.default.prompt({ type: "list", name: "functionName", message: "Which function do you want to run?", choices: Object.keys(functionsConfig_1.functionConfig), }); const selectedFunction = functionsConfig_1.functionConfig[functionName]; console.log(`You are about to run:`); console.log(`\nFunction: ${selectedFunction.name}`); console.log(`Contract name: ${selectedFunction.contractName}`); console.log(`Contract address: ${config[selectedFunction.configAddressField]}`); console.log(`Function description: ${selectedFunction.description}`); console.log(`Environment: ${env}\n`); const { confirmRun } = await inquirer_1.default.prompt({ type: "confirm", name: "confirmRun", message: `Do you want to proceed with running ${selectedFunction.name} on environment ${env}?`, default: false, }); if (!confirmRun) { console.log("Execution aborted."); process.exit(0); } // Set environment variables to be picked up by Turbo task process.env.FUNCTION_TO_CALL = selectedFunction.file; console.log(`\nStarting function ${selectedFunction.file} on ${env}...`); // Kick off the right turbo run task (0, child_process_1.execSync)(`turbo run call:contract:${env}`, { stdio: "inherit" }); console.log("\nFunction executed successfully!"); } catch (error) { console.error("Function execution failed:", error); process.exit(1); } } runFunction();