Node.js based forum software built for the modern web
feat: add option to autoinstall plugins on setup
oplik074cb224344dd
diff --git a/src/install.js b/src/install.jsindex d1229de531..ea59843f5b 100644--- a/src/install.js+++ b/src/install.js@@ -9,6 +9,7 @@ const nconf = require('nconf');const _ = require('lodash');const utils = require('./utils');+const { paths } = require('./constants');const install = module.exports;const questions = {};@@ -563,6 +564,16 @@ async function checkUpgrade() {}}+async function installPlugins() {+ const pluginInstall = require('./plugins');+ const nbbVersion = require(paths.currentPackage).version;+ await Promise.all((await pluginInstall.getActive()).map(async (id) => {+ if (await pluginInstall.isInstalled(id)) return;+ const version = await pluginInstall.suggest(id, nbbVersion);+ await pluginInstall.toggleInstall(id, version.version);+ }));+}+install.setup = async function () {try {checkSetupFlagEnv();@@ -580,6 +591,7 @@ install.setup = async function () {await enableDefaultPlugins();await setCopyrightWidget();await copyFavicon();+ if (nconf.get('plugins:autoinstall')) await installPlugins();await checkUpgrade();const data = {diff --git a/src/plugins/install.js b/src/plugins/install.jsindex d358c917a5..82b078403e 100644--- a/src/plugins/install.js+++ b/src/plugins/install.js@@ -109,7 +109,7 @@ module.exports = function (Plugins) {Plugins.isActive(id),]);const type = installed ? 'uninstall' : 'install';- if (active) {+ if (active && !nconf.get('plugins:active')) {await Plugins.toggleActive(id);}await runPackageManagerCommandAsync(type, id, version || 'latest');@@ -121,7 +121,7 @@ module.exports = function (Plugins) {function runPackageManagerCommand(command, pkgName, version, callback) {cproc.execFile(packageManagerExecutable, [packageManagerCommands[packageManager][command],- pkgName + (command === 'install' ? `@${version}` : ''),+ pkgName + (command === 'install' && version ? `@${version}` : ''),'--save',], (err, stdout) => {if (err) {