mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 20:45:58 +01:00
refactor: shared constants (#8707)
define plugin name and theme name regexs in one location for consistency define various shared paths in one place for consistency
This commit is contained in:
@@ -10,6 +10,7 @@ const request = require('request-promise-native');
|
||||
|
||||
const user = require('../user');
|
||||
const posts = require('../posts');
|
||||
const { pluginNamePattern, themeNamePattern, paths } = require('../constants');
|
||||
|
||||
var app;
|
||||
var middleware;
|
||||
@@ -176,7 +177,7 @@ Plugins.list = async function (matching) {
|
||||
if (matching === undefined) {
|
||||
matching = true;
|
||||
}
|
||||
const version = require(path.join(nconf.get('base_dir'), 'package.json')).version;
|
||||
const version = require(paths.currentPackage).version;
|
||||
const url = (nconf.get('registry') || 'https://packages.nodebb.org') + '/api/v1/plugins' + (matching !== false ? '?version=' + version : '');
|
||||
try {
|
||||
const body = await request(url, {
|
||||
@@ -197,9 +198,8 @@ Plugins.listTrending = async () => {
|
||||
};
|
||||
|
||||
Plugins.normalise = async function (apiReturn) {
|
||||
const themeNamePattern = /^(@.*?\/)?nodebb-theme-.*$/;
|
||||
const pluginMap = {};
|
||||
const dependencies = require(path.join(nconf.get('base_dir'), 'package.json')).dependencies;
|
||||
const dependencies = require(paths.currentPackage).dependencies;
|
||||
apiReturn = Array.isArray(apiReturn) ? apiReturn : [];
|
||||
apiReturn.forEach(function (packageData) {
|
||||
packageData.id = packageData.name;
|
||||
@@ -263,7 +263,7 @@ Plugins.normalise = async function (apiReturn) {
|
||||
return pluginArray;
|
||||
};
|
||||
|
||||
Plugins.nodeModulesPath = path.join(__dirname, '../../node_modules');
|
||||
Plugins.nodeModulesPath = paths.nodeModules;
|
||||
|
||||
Plugins.showInstalled = async function () {
|
||||
const dirs = await fs.promises.readdir(Plugins.nodeModulesPath);
|
||||
@@ -290,7 +290,6 @@ Plugins.showInstalled = async function () {
|
||||
};
|
||||
|
||||
async function findNodeBBModules(dirs) {
|
||||
const pluginNamePattern = /^(@.*?\/)?nodebb-(theme|plugin|widget|rewards)-.*$/;
|
||||
const pluginPaths = [];
|
||||
await async.each(dirs, function (dirname, next) {
|
||||
var dirPath = path.join(Plugins.nodeModulesPath, dirname);
|
||||
|
||||
Reference in New Issue
Block a user