mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 17:16:14 +01:00
feat: add ./nodebb install <plugin_name>
will install the suggested version for current nodebb closes #11060
This commit is contained in:
@@ -173,11 +173,16 @@ program
|
|||||||
});
|
});
|
||||||
|
|
||||||
program
|
program
|
||||||
.command('install')
|
.command('install [plugin]')
|
||||||
.description('Launch the NodeBB web installer for configuration setup')
|
.description('Launch the NodeBB web installer for configuration setup or install a plugin')
|
||||||
.action(() => {
|
.action((plugin) => {
|
||||||
|
if (plugin) {
|
||||||
|
require('./manage').install(plugin);
|
||||||
|
} else {
|
||||||
require('./setup').webInstall();
|
require('./setup').webInstall();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
program
|
program
|
||||||
.command('build [targets...]')
|
.command('build [targets...]')
|
||||||
.description(`Compile static assets ${chalk.red('(JS, CSS, templates, languages)')}`)
|
.description(`Compile static assets ${chalk.red('(JS, CSS, templates, languages)')}`)
|
||||||
|
|||||||
@@ -12,7 +12,36 @@ const plugins = require('../plugins');
|
|||||||
const events = require('../events');
|
const events = require('../events');
|
||||||
const analytics = require('../analytics');
|
const analytics = require('../analytics');
|
||||||
const reset = require('./reset');
|
const reset = require('./reset');
|
||||||
const { pluginNamePattern, themeNamePattern } = require('../constants');
|
const { pluginNamePattern, themeNamePattern, paths } = require('../constants');
|
||||||
|
|
||||||
|
async function install(plugin) {
|
||||||
|
try {
|
||||||
|
await db.init();
|
||||||
|
if (!pluginNamePattern.test(plugin)) {
|
||||||
|
// Allow omission of `nodebb-plugin-`
|
||||||
|
plugin = `nodebb-plugin-${plugin}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin = await plugins.autocomplete(plugin);
|
||||||
|
|
||||||
|
const isInstalled = await plugins.isInstalled(plugin);
|
||||||
|
if (isInstalled) {
|
||||||
|
throw new Error('plugin already installed');
|
||||||
|
}
|
||||||
|
const nbbVersion = require(paths.currentPackage).version;
|
||||||
|
const suggested = await plugins.suggest(plugin, nbbVersion);
|
||||||
|
if (!suggested.version) {
|
||||||
|
throw new Error(suggested.message);
|
||||||
|
}
|
||||||
|
winston.info('Installing Plugin `%s@%s`', plugin, suggested.version);
|
||||||
|
await plugins.toggleInstall(plugin, suggested.version);
|
||||||
|
|
||||||
|
process.exit(0);
|
||||||
|
} catch (err) {
|
||||||
|
winston.error(`An error occurred during plugin installation\n${err.stack}`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function activate(plugin) {
|
async function activate(plugin) {
|
||||||
if (themeNamePattern.test(plugin)) {
|
if (themeNamePattern.test(plugin)) {
|
||||||
@@ -166,6 +195,7 @@ async function buildWrapper(targets, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exports.build = buildWrapper;
|
exports.build = buildWrapper;
|
||||||
|
exports.install = install;
|
||||||
exports.activate = activate;
|
exports.activate = activate;
|
||||||
exports.listPlugins = listPlugins;
|
exports.listPlugins = listPlugins;
|
||||||
exports.listEvents = listEvents;
|
exports.listEvents = listEvents;
|
||||||
|
|||||||
@@ -87,6 +87,15 @@ module.exports = function (Plugins) {
|
|||||||
throw new Error('[[error:plugin-not-whitelisted]]');
|
throw new Error('[[error:plugin-not-whitelisted]]');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Plugins.suggest = async function (pluginId, nbbVersion) {
|
||||||
|
const body = await request({
|
||||||
|
method: 'GET',
|
||||||
|
url: `https://packages.nodebb.org/api/v1/suggest?package=${encodeURIComponent(pluginId)}&version=${encodeURIComponent(nbbVersion)}`,
|
||||||
|
json: true,
|
||||||
|
});
|
||||||
|
return body;
|
||||||
|
};
|
||||||
|
|
||||||
Plugins.toggleInstall = async function (id, version) {
|
Plugins.toggleInstall = async function (id, version) {
|
||||||
pubsub.publish('plugins:toggleInstall', { hostname: os.hostname(), id: id, version: version });
|
pubsub.publish('plugins:toggleInstall', { hostname: os.hostname(), id: id, version: version });
|
||||||
return await toggleInstall(id, version);
|
return await toggleInstall(id, version);
|
||||||
|
|||||||
Reference in New Issue
Block a user