From a79413824414d1cda8341900becec1ea2b9d8617 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Fri, 13 Jul 2018 11:00:47 +0300 Subject: Allow user to dequeue a package installation and list packages --- cli.js | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) (limited to 'cli.js') diff --git a/cli.js b/cli.js index 348c092..0435317 100755 --- a/cli.js +++ b/cli.js @@ -279,7 +279,7 @@ vorpal }); vorpal - .command('package install ', `Install an NPM package on the host.`) + .command('package add ', `Enqueue an NPM package installation on the host.`) .action(async function (args, callback) { try { await checkConnection(mongoURL, this); @@ -298,6 +298,7 @@ vorpal name: args.package }); this.log(chalk.green(`Package "${args.package}" added successfully to list of packages to install.`)); + this.log(`NOTE: Packages might take a while to be installed. The default refresh period for fetching new packages is 1 minute.`); } catch (err) { this.log(chalk.red(`Failed to add package ${args.package} to list of packages to install!`)); this.log(chalk.red(String(err))); @@ -305,6 +306,58 @@ vorpal callback(); }); +vorpal + .command('package remove ', `Dequeue an NPM package installation on the host. NOTE: Does not uninstall already installed packages.`) + .action(async function (args, callback) { + try { + await checkConnection(mongoURL, this); + } catch (err) { + showMongoNotSetError(vorpal); + return callback(); + } + + if (!args.package) { + this.log('Please provide the "package" argument.'); + return callback(); + } + + try { + await models.packages.remove({ + name: args.package + }); + const cmd = chalk.yellow(`npm uninstall ${args.package}`); + this.log(chalk.green(`Package "${args.package}" removed successfully from the list of packages to install.`)); + this.log(`NOTE: Packages already installed are not uninstalled by this command.`); + this.log(`To completely uninstall this package from the host, run ${cmd} in the project directory on the host server.`); + } catch (err) { + this.log(chalk.red(`Failed to remove package ${args.package} from the list of packages to install!`)); + this.log(chalk.red(String(err))); + } + callback(); + }); + +vorpal + .command('package list', `List NPM packages in the installation queue.`) + .action(async function (args, callback) { + try { + await checkConnection(mongoURL, this); + } catch (err) { + showMongoNotSetError(vorpal); + return callback(); + } + + try { + const packages = await models.packages.find({}); + packages.forEach(pkg => { + this.log(pkg.name); + }); + } catch (err) { + this.log(chalk.red(`Failed to get a list of packages.`)); + this.log(chalk.red(String(err))); + } + callback(); + }); + vorpal .command('info', 'Show information about the session') .action(async function (args, callback) { -- cgit v1.3