UNPKG

nx-helper-cli

Version:

This is a helper cli which helps get things done fast in a monorepo. mainly it's used with [nx.dev](http://google.com) tool but has many tools that may benefit anybody working in a monorepo architecture.

74 lines 3.32 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()); }); }; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const path = __importStar(require("path")); const fs = __importStar(require("fs")); exports.getCurrentDirectory = () => { return path.basename(process.cwd()); }; exports.directoryExists = (filePath) => { return fs.existsSync(filePath); }; exports.getRandomChalkColor = () => { let colors = ['green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'gray']; return colors[Math.floor(Math.random() * colors.length)]; }; exports.configToConcurrentlyAdapter = (filePath) => __awaiter(void 0, void 0, void 0, function* () { let extension = filePath.split('.').pop(); if (extension === 'json') { // directly require the file then use it let json = yield importModule(filePath); return parseToConcurrent(json); } if (extension === 'js' || extension === 'ts') { // remove the extension from the path then require it then use it let mod = yield importModule(filePath); return parseToConcurrent(mod); } // error message that the extension is not a valid extension throw Error('This file extension is not supported only json , js , ts are the supported file extensions'); }); let parseToConcurrent = (module) => { let concurrentlyCmds = []; let commandObject = {}; // deleting the default value in the object delete module['default']; for (let [key, commandValue] of Object.entries(module)) { commandObject = { command: commandValue.command, name: getCommandName(commandValue, key), prefixColor: getCommandPrefixColor(commandValue) }; concurrentlyCmds.push(commandObject); } return concurrentlyCmds; }; let importModule = (filePath) => __awaiter(void 0, void 0, void 0, function* () { return yield Promise.resolve().then(() => __importStar(require(`${path.join(process.cwd(), filePath)}`))); }); let getCommandName = (moduleObject, commandName) => { if (moduleObject.options && moduleObject.options.name) return moduleObject.options.name; return commandName; }; let getCommandPrefixColor = (moduleObject) => { if (moduleObject.options && moduleObject.options.color) return moduleObject.options.color; return exports.getRandomChalkColor(); }; //# sourceMappingURL=utils.js.map