feat: add option to autoinstall plugins on setup

isekai-main
oplik0 2 years ago committed by Julian Lam
parent ce05e743e0
commit 74cb224344

@ -9,6 +9,7 @@ const nconf = require('nconf');
const _ = require('lodash'); const _ = require('lodash');
const utils = require('./utils'); const utils = require('./utils');
const { paths } = require('./constants');
const install = module.exports; const install = module.exports;
const questions = {}; 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 () { install.setup = async function () {
try { try {
checkSetupFlagEnv(); checkSetupFlagEnv();
@ -580,6 +591,7 @@ install.setup = async function () {
await enableDefaultPlugins(); await enableDefaultPlugins();
await setCopyrightWidget(); await setCopyrightWidget();
await copyFavicon(); await copyFavicon();
if (nconf.get('plugins:autoinstall')) await installPlugins();
await checkUpgrade(); await checkUpgrade();
const data = { const data = {

@ -109,7 +109,7 @@ module.exports = function (Plugins) {
Plugins.isActive(id), Plugins.isActive(id),
]); ]);
const type = installed ? 'uninstall' : 'install'; const type = installed ? 'uninstall' : 'install';
if (active) { if (active && !nconf.get('plugins:active')) {
await Plugins.toggleActive(id); await Plugins.toggleActive(id);
} }
await runPackageManagerCommandAsync(type, id, version || 'latest'); await runPackageManagerCommandAsync(type, id, version || 'latest');
@ -121,7 +121,7 @@ module.exports = function (Plugins) {
function runPackageManagerCommand(command, pkgName, version, callback) { function runPackageManagerCommand(command, pkgName, version, callback) {
cproc.execFile(packageManagerExecutable, [ cproc.execFile(packageManagerExecutable, [
packageManagerCommands[packageManager][command], packageManagerCommands[packageManager][command],
pkgName + (command === 'install' ? `@${version}` : ''), pkgName + (command === 'install' && version ? `@${version}` : ''),
'--save', '--save',
], (err, stdout) => { ], (err, stdout) => {
if (err) { if (err) {

Loading…
Cancel
Save