UNPKG

hardhat-forta

Version:
45 lines 1.54 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.chooseAgent = void 0; const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const prompts_1 = __importDefault(require("prompts")); function getAgentChoices(rootPath) { return fs_1.default .readdirSync(rootPath) .filter((file) => { const fullPath = path_1.default.join(rootPath, file); return (file !== "node_modules" && fs_1.default.existsSync(path_1.default.join(fullPath, "package.json"))); }) .map((file) => ({ title: file, value: path_1.default.join(rootPath, file), })); } async function chooseAgent(rootPath) { if (fs_1.default.existsSync(path_1.default.join(rootPath, "package.json"))) { return rootPath; } else { const agentChoices = getAgentChoices(rootPath); if (agentChoices.length === 0) { throw new Error("No agents inside folder"); } if (agentChoices.length === 1) { return agentChoices[0].value; } const agent = await (0, prompts_1.default)({ type: "select", name: "path", message: "Agent:", choices: getAgentChoices(rootPath), }); return agent.path; } } exports.chooseAgent = chooseAgent; //# sourceMappingURL=agents.js.map