UNPKG

@leonardowlopes/bx-cli

Version:

A CLI tool used to configure projects for the Buildbox company.

67 lines 2.37 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.command = void 0; const node_child_process_1 = require("node:child_process"); const node_fs_1 = __importDefault(require("node:fs")); const node_path_1 = __importDefault(require("node:path")); const node_util_1 = __importDefault(require("node:util")); const chalk_1 = __importDefault(require("chalk")); const ora_1 = __importDefault(require("ora")); const command_1 = require("../enum/command"); const execAsync = node_util_1.default.promisify(node_child_process_1.exec); class Command { async getCommand() { const fileMatch = [ 'yarn.lock', 'pnpm-lock.yaml', 'package-lock.json', 'bun.lockb', ]; const commands = [ command_1.ECommandType.YARN, command_1.ECommandType.PNPM, command_1.ECommandType.NPM, command_1.ECommandType.BUN, ]; for (let i = 0; i < fileMatch.length; i++) { if (node_fs_1.default.existsSync(node_path_1.default.join('.', fileMatch[i]))) { return commands[i]; } } return command_1.ECommandType.NPM; } async exec(command) { try { const { stderr } = await execAsync(command); if (stderr) { console.error(stderr); return; } } catch (error) { const err = error; console.error(`error: ${err.message}`); } } async install() { const command = await this.getCommand(); const spinner = (0, ora_1.default)(`Installing dependencies using ${chalk_1.default.blue(command)} ...`).start(); try { await this.exec(`${command} install`); spinner.succeed(`Installation completed ${chalk_1.default.green('successfully')}`); } catch (error) { const err = error; spinner.fail(`Installation failed with error: ${err.message}`); } } async getCommandType() { const command = await this.getCommand(); return command; } } exports.command = new Command(); //# sourceMappingURL=commands.js.map