@boostercloud/cli
Version:
CLI of the Booster Framework, the next level of abstraction for cloud-native applications
40 lines (39 loc) • 1.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const process = require("process");
const logger_1 = require("../../services/logger");
const environment_1 = require("../../services/environment");
// Function to find and remove the `-e` argument and its accompanying value
const extractEnvironmentArg = () => {
const argv = process.argv;
const eIndex = argv.indexOf('-e'); // Find the index of `-e` in argv
let environment; // Variable to store the value found after `-e`
if (eIndex !== -1 && eIndex + 1 < argv.length) {
environment = argv[eIndex + 1]; // Save the value following `-e`
argv.splice(eIndex, 2); // Remove both `-e` and its value from argv
}
return environment;
};
const hook = async function (opts) {
var _a;
// ensure opts.argv is argv without the environment
process.env['BOOSTER_CLI_HOOK'] = 'true';
if (opts.id === '-e') {
opts.id = '';
opts.argv = ['-e', ...((_a = opts.argv) !== null && _a !== void 0 ? _a : [])];
}
const firstArgs = process.argv.filter((arg) => { var _a; return !((_a = opts.argv) === null || _a === void 0 ? void 0 : _a.includes(arg)); });
const environment = extractEnvironmentArg();
opts.argv = process.argv.filter((arg) => !firstArgs.includes(arg));
const cwd = process.cwd();
if ((0, environment_1.initializeEnvironment)(logger_1.logger, environment)) {
// to allow doing `boost -e <env>` and show the help
if (!opts.id && opts.argv.length === 0) {
;
process.argv = [...firstArgs, '--help'];
}
await Promise.resolve(`${path.join(cwd, 'dist', 'index.js')}`).then(s => require(s));
}
};
exports.default = hook;