UNPKG

@stoked-cenv/cli

Version:

A well considered cli and Node.js library for helping manage application, infrastructure, and configuration management.

129 lines 5.7 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ExecCommand = void 0; const nest_commander_1 = require("nest-commander"); const path = __importStar(require("path")); const lib_1 = require("@stoked-cenv/lib"); const base_command_1 = require("./base.command"); let ExecCommand = class ExecCommand extends base_command_1.BaseCommand { constructor() { super(); } parseLogLevel(val) { return val; } parseEnvironment(val) { return val; } parseModule(val) { return val; } parseSubCommand(val, val2) { return val; } async runCommand(params, options, packages) { try { let vars = {}; await Promise.all(packages.map(async (p) => { var _a; const pkgPath = lib_1.CenvFiles.packagePath(p.packageName); if (pkgPath) { const relative = path.relative(process.cwd(), pkgPath); if (relative !== '') { process.chdir(path.relative(process.cwd(), pkgPath)); } if (p.params) { vars = await (0, lib_1.getConfigVars)(p.packageName, false, true, true); } //Object.entries(options.args).forEach(([key, value]) => { // console.log(`export ${CenvLog.colors.stdHighlight(key)}=${CenvLog.colors.stdHighlight(value)}`) //}); options.module = (_a = options.module) === null || _a === void 0 ? void 0 : _a.toLowerCase(); if (options.module) { const pkgModule = p.packageModules[options.module]; const modulePath = path.relative(process.cwd(), pkgModule.path); if (modulePath !== process.cwd()) { process.chdir(path.relative(process.cwd(), pkgModule.path)); } } } await (0, lib_1.spawnCmd)('./', params.join(' '), params.join(' '), { envVars: vars }, p); })); } catch (e) { console.log(lib_1.CenvLog.colors.error(e)); } } }; exports.ExecCommand = ExecCommand; __decorate([ (0, nest_commander_1.Option)({ flags: '-ll, --log-level, <logLevel>', description: `Logging mode`, }), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", String) ], ExecCommand.prototype, "parseLogLevel", null); __decorate([ (0, nest_commander_1.Option)({ flags: '--profile <string>', description: `Profile to use for aws commands a.k.a. "AWS_PROFILE"` }), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", String) ], ExecCommand.prototype, "parseEnvironment", null); __decorate([ (0, nest_commander_1.Option)({ flags: '-m, --module [application]', description: 'Provide the module directory to run the command from', }), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", String) ], ExecCommand.prototype, "parseModule", null); __decorate([ (0, nest_commander_1.Option)({ name: 'double-dash', flags: '--', description: 'Cenv application to run the command on', }), __metadata("design:type", Function), __metadata("design:paramtypes", [String, String]), __metadata("design:returntype", String) ], ExecCommand.prototype, "parseSubCommand", null); exports.ExecCommand = ExecCommand = __decorate([ (0, nest_commander_1.Command)({ name: 'exec', description: 'Execute command using cenv context', }), __metadata("design:paramtypes", []) ], ExecCommand); //# sourceMappingURL=exec.command.js.map