UNPKG

eisd

Version:

Execute your favorite command in SubDirectories. Use it like: `eisd '[command]' [subdirs...]` (Example: `eisd 'yarn build' client server scripts`)

70 lines (69 loc) 3.61 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.eisd = void 0; const colors_1 = require("colors"); const cluster_1 = require("./cluster"); const yarnHelpers_1 = require("./yarnHelpers"); /** * This is a CLI tool helps you do execute cmds per given folder. If you try to do the same * with a normal cd command, it will do it in the wrong folder. So this tool simply * navigates to the proper folders and does `your command`. That's it. #ez #boring */ function eisd(config) { return __awaiter(this, void 0, void 0, function* () { // Prevent triggering eisd twice because the cluster-worker will rerun all the code if (process.env._runnedBefore) return; process.env._runnedBefore = "true"; if (!config.commandToExecute) { process.stdout.write(colors_1.red("ERROR: No command given..\n")); throw new Error("No command found."); } if (config.yarnWorkspaces) { yarnHelpers_1.checkYarnAvailability(); config.directoriesToUse.push(...yarnHelpers_1.getYarnWorkspaces()); } if (config.envVariable) { if (!process.env[config.envVariable]) { process.stdout.write(colors_1.red(`ERROR: No environment value found on "process.env.${config.envVariable}"..\n`)); throw new Error(`Invalid env variable given "${config.envVariable}".`); } const directories = process.env[config.envVariable].split(" "); config.directoriesToUse.push(...directories); } if (!config.directoriesToUse.length) { process.stdout.write(colors_1.red("ERROR: No directories given..\n")); throw new Error("No directories found."); } if (config.verbose) { console.log("Directories:", config.directoriesToUse); process.stdout.write("\n"); } const { directoriesSucces, directoriesFailed } = yield cluster_1.startMaster(config.commandToExecute, config.directoriesToUse, config.allowErrors, config.aSynchronous, config.verbose); if (config.verbose && directoriesSucces.length) { process.stdout.write(colors_1.green(`Done executing '${config.commandToExecute}' in the following directories:`)); process.stdout.write("\n"); process.stdout.write(directoriesSucces.join(", ")); process.stdout.write("\n"); } if (directoriesFailed.length) { process.stdout.write("\n"); process.stdout.write(colors_1.red(`Error(s) while executing '${config.commandToExecute}' in the following directories:`)); process.stdout.write("\n"); process.stdout.write(directoriesFailed.join(", ")); process.stdout.write("\n"); if (!config.allowErrors) process.exit(1); } }); } exports.eisd = eisd;