UNPKG

@decaf-ts/utils

Version:

module management utils for decaf-ts

78 lines 2.94 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.RunAllCommand = void 0; const node_fs_1 = __importDefault(require("node:fs")); const node_path_1 = __importDefault(require("node:path")); const node_child_process_1 = require("node:child_process"); const command_js_1 = require("./../command.cjs"); const modules_command_js_1 = require("./modules.command.cjs"); const help_command_js_1 = require("./help.command.cjs"); const options = { basePath: { type: "string", default: process.cwd(), }, command: { type: "string", default: undefined, }, }; class RunAllCommand extends command_js_1.Command { constructor() { super("RunAllCommand", options); } help() { (0, help_command_js_1.printCommandHelp)(this.log, "run-all", "Run a shell command in every module listed in .gitmodules.", "run-all [options] --command <cmd>", [ { flag: "--base-path <path>", description: "Directory to read .gitmodules from", defaultValue: "current working directory", }, { flag: "--command <cmd>", description: "Shell command to execute in each module", }, { flag: "-h, --help", description: "Show this help text and exit", }, ], [ "The command fails fast if any module invocation fails.", ], [ "run-all --command npm test", "run-all --base-path ../repo --command npm run lint", ]); } async run(answers) { const basePath = typeof answers.basePath === "string" && answers.basePath.trim().length > 0 ? answers.basePath.trim() : process.cwd(); const command = typeof answers.command === "string" ? answers.command.trim() : ""; if (command.length === 0) { throw new Error("run-all requires a command to execute"); } const modules = (0, modules_command_js_1.readGitModules)(basePath); for (const moduleName of modules) { const moduleRoot = node_path_1.default.join(basePath, moduleName); if (!node_fs_1.default.existsSync(moduleRoot)) continue; console.log(`running ${command} ${moduleName}`); try { (0, node_child_process_1.execSync)(command, { cwd: moduleRoot, env: process.env, stdio: "inherit", }); } catch { process.exit(1); } } } } exports.RunAllCommand = RunAllCommand; //# sourceMappingURL=run-all.command.js.map //# sourceMappingURL=run-all.command.cjs.map