mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	feat: add force flag to plugin install in cli (#11089)
This commit is contained in:
		| @@ -175,9 +175,10 @@ program | |||||||
| program | program | ||||||
| 	.command('install [plugin]') | 	.command('install [plugin]') | ||||||
| 	.description('Launch the NodeBB web installer for configuration setup or install a 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) { | 		if (plugin) { | ||||||
| 			require('./manage').install(plugin); | 			require('./manage').install(plugin, options); | ||||||
| 		} else { | 		} else { | ||||||
| 			require('./setup').webInstall(); | 			require('./setup').webInstall(); | ||||||
| 		} | 		} | ||||||
|   | |||||||
| @@ -14,7 +14,10 @@ const analytics = require('../analytics'); | |||||||
| const reset = require('./reset'); | const reset = require('./reset'); | ||||||
| const { pluginNamePattern, themeNamePattern, paths } = require('../constants'); | const { pluginNamePattern, themeNamePattern, paths } = require('../constants'); | ||||||
|  |  | ||||||
| async function install(plugin) { | async function install(plugin, options) { | ||||||
|  | 	if (!options) { | ||||||
|  | 		options = {}; | ||||||
|  | 	} | ||||||
| 	try { | 	try { | ||||||
| 		await db.init(); | 		await db.init(); | ||||||
| 		if (!pluginNamePattern.test(plugin)) { | 		if (!pluginNamePattern.test(plugin)) { | ||||||
| @@ -31,7 +34,11 @@ async function install(plugin) { | |||||||
| 		const nbbVersion = require(paths.currentPackage).version; | 		const nbbVersion = require(paths.currentPackage).version; | ||||||
| 		const suggested = await plugins.suggest(plugin, nbbVersion); | 		const suggested = await plugins.suggest(plugin, nbbVersion); | ||||||
| 		if (!suggested.version) { | 		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); | 		winston.info('Installing Plugin `%s@%s`', plugin, suggested.version); | ||||||
| 		await plugins.toggleInstall(plugin, suggested.version); | 		await plugins.toggleInstall(plugin, suggested.version); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user