From d447236b7041a2b4251f57eca085f72691eab724 Mon Sep 17 00:00:00 2001 From: Opliko Date: Fri, 16 Dec 2022 21:47:03 +0100 Subject: [PATCH] feat: add force flag to plugin install in cli (#11089) --- src/cli/index.js | 5 +++-- src/cli/manage.js | 11 +++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/cli/index.js b/src/cli/index.js index cad46b4609..938f588701 100644 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -175,9 +175,10 @@ program program .command('install [plugin]') .description('Launch the NodeBB web installer for configuration setup or install a plugin') - .action((plugin) => { + .option('-f, --force', 'Force plugin installation even if it may be incompatible with currently installed NodeBB version') + .action((plugin, options) => { if (plugin) { - require('./manage').install(plugin); + require('./manage').install(plugin, options); } else { require('./setup').webInstall(); } diff --git a/src/cli/manage.js b/src/cli/manage.js index 45480e735f..d67126270c 100644 --- a/src/cli/manage.js +++ b/src/cli/manage.js @@ -14,7 +14,10 @@ const analytics = require('../analytics'); const reset = require('./reset'); const { pluginNamePattern, themeNamePattern, paths } = require('../constants'); -async function install(plugin) { +async function install(plugin, options) { + if (!options) { + options = {}; + } try { await db.init(); if (!pluginNamePattern.test(plugin)) { @@ -31,7 +34,11 @@ async function install(plugin) { const nbbVersion = require(paths.currentPackage).version; const suggested = await plugins.suggest(plugin, nbbVersion); if (!suggested.version) { - throw new Error(suggested.message); + if (!options.force) { + throw new Error(suggested.message); + } + winston.warn(`${suggested.message} Proceeding with installation anyway due to force option being provided`); + suggested.version = 'latest'; } winston.info('Installing Plugin `%s@%s`', plugin, suggested.version); await plugins.toggleInstall(plugin, suggested.version);