From 74cb224344ddf2d012157962009f7b6e48b75bec Mon Sep 17 00:00:00 2001 From: oplik0 Date: Sat, 15 Apr 2023 01:16:40 +0200 Subject: [PATCH] feat: add option to autoinstall plugins on setup --- src/install.js | 12 ++++++++++++ src/plugins/install.js | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/install.js b/src/install.js index 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.js index 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) {