feat: add force flag to plugin install in cli (#11089)

isekai-main
Opliko 2 years ago committed by GitHub
parent 14091de8fe
commit d447236b70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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();
}

@ -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);

Loading…
Cancel
Save