mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +01:00
Fix #5488 Support scoped plugin npm packages
This commit is contained in:
@@ -20,7 +20,7 @@ define('admin/extend/plugins', ['jqueryui', 'translator'], function (jqueryui, t
|
|||||||
pluginsList.on('click', 'button[data-action="toggleActive"]', function () {
|
pluginsList.on('click', 'button[data-action="toggleActive"]', function () {
|
||||||
var pluginEl = $(this).parents('li');
|
var pluginEl = $(this).parents('li');
|
||||||
pluginID = pluginEl.attr('data-plugin-id');
|
pluginID = pluginEl.attr('data-plugin-id');
|
||||||
var btn = $('#' + pluginID + ' [data-action="toggleActive"]');
|
var btn = $('[id="' + pluginID + '"] [data-action="toggleActive"]');
|
||||||
socket.emit('admin.plugins.toggleActive', pluginID, function (err, status) {
|
socket.emit('admin.plugins.toggleActive', pluginID, function (err, status) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return app.alertError(err);
|
return app.alertError(err);
|
||||||
@@ -30,7 +30,7 @@ define('admin/extend/plugins', ['jqueryui', 'translator'], function (jqueryui, t
|
|||||||
btn.toggleClass('btn-warning', status.active).toggleClass('btn-success', !status.active);
|
btn.toggleClass('btn-warning', status.active).toggleClass('btn-success', !status.active);
|
||||||
|
|
||||||
// clone it to active plugins tab
|
// clone it to active plugins tab
|
||||||
if (status.active && !$('#active #' + pluginID).length) {
|
if (status.active && !$('#active [id="' + pluginID + '"]').length) {
|
||||||
$('#active ul').prepend(pluginEl.clone(true));
|
$('#active ul').prepend(pluginEl.clone(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -298,38 +298,74 @@ Plugins.normalise = function (apiReturn, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Plugins.showInstalled = function (callback) {
|
Plugins.showInstalled = function (callback) {
|
||||||
var npmPluginPath = path.join(__dirname, '../node_modules');
|
var nodeModulesPath = path.join(__dirname, '../node_modules');
|
||||||
|
var pluginNamePattern = /^(@.*?\/)?nodebb-(theme|plugin|widget|rewards)-.*$/;
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
async.apply(fs.readdir, npmPluginPath),
|
function (next) {
|
||||||
|
fs.readdir(nodeModulesPath, next);
|
||||||
|
},
|
||||||
function (dirs, next) {
|
function (dirs, next) {
|
||||||
dirs = dirs.filter(function (dir) {
|
var pluginPaths = [];
|
||||||
return dir.startsWith('nodebb-plugin-') ||
|
|
||||||
dir.startsWith('nodebb-widget-') ||
|
|
||||||
dir.startsWith('nodebb-rewards-') ||
|
|
||||||
dir.startsWith('nodebb-theme-');
|
|
||||||
}).map(function (dir) {
|
|
||||||
return path.join(npmPluginPath, dir);
|
|
||||||
});
|
|
||||||
|
|
||||||
async.filter(dirs, function (dir, callback) {
|
async.each(dirs, function (dirname, next) {
|
||||||
fs.stat(dir, function (err, stats) {
|
var dirPath = path.join(nodeModulesPath, dirname);
|
||||||
if (err) {
|
|
||||||
if (err.code === 'ENOENT') {
|
async.waterfall([
|
||||||
return callback(null, false);
|
function (cb) {
|
||||||
|
fs.stat(dirPath, function (err, stats) {
|
||||||
|
if (err && err.code !== 'ENOENT') {
|
||||||
|
return next(err);
|
||||||
}
|
}
|
||||||
return callback(err);
|
if (err || !stats.isDirectory()) {
|
||||||
|
return next();
|
||||||
}
|
}
|
||||||
callback(null, stats.isDirectory());
|
|
||||||
|
if (pluginNamePattern.test(dirname)) {
|
||||||
|
pluginPaths.push(dirname);
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dirname[0] !== '@') {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
fs.readdir(dirPath, cb);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function (subdirs, cb) {
|
||||||
|
async.each(subdirs, function (subdir, next) {
|
||||||
|
if (!pluginNamePattern.test(subdir)) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
|
var subdirPath = path.join(dirPath, subdir);
|
||||||
|
fs.stat(subdirPath, function (err, stats) {
|
||||||
|
if (err && err.code !== 'ENOENT') {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err || !stats.isDirectory()) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
|
pluginPaths.push(dirname + '/' + subdir);
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
}, cb);
|
||||||
|
},
|
||||||
|
], next);
|
||||||
|
}, function (err) {
|
||||||
|
next(err, pluginPaths);
|
||||||
});
|
});
|
||||||
}, next);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
function (files, next) {
|
function (dirs, next) {
|
||||||
|
dirs = dirs.map(function (dir) {
|
||||||
|
return path.join(nodeModulesPath, dir);
|
||||||
|
});
|
||||||
var plugins = [];
|
var plugins = [];
|
||||||
|
|
||||||
async.each(files, function (file, next) {
|
async.each(dirs, function (file, next) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
Plugins.loadPluginInfo(file, next);
|
Plugins.loadPluginInfo(file, next);
|
||||||
|
|||||||
Reference in New Issue
Block a user