mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-13 01:15:47 +01:00
refactor: get rid of async.waterfall/each
This commit is contained in:
@@ -3,7 +3,6 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const async = require('async');
|
|
||||||
const winston = require('winston');
|
const winston = require('winston');
|
||||||
const semver = require('semver');
|
const semver = require('semver');
|
||||||
const nconf = require('nconf');
|
const nconf = require('nconf');
|
||||||
@@ -283,54 +282,45 @@ Plugins.showInstalled = async function () {
|
|||||||
|
|
||||||
async function findNodeBBModules(dirs) {
|
async function findNodeBBModules(dirs) {
|
||||||
const pluginPaths = [];
|
const pluginPaths = [];
|
||||||
await async.each(dirs, (dirname, next) => {
|
await Promise.all(dirs.map(async (dirname) => {
|
||||||
const dirPath = path.join(Plugins.nodeModulesPath, dirname);
|
const dirPath = path.join(Plugins.nodeModulesPath, dirname);
|
||||||
|
const isDir = await isDirectory(dirPath);
|
||||||
|
if (!isDir) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (pluginNamePattern.test(dirname)) {
|
||||||
|
pluginPaths.push(dirname);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
async.waterfall([
|
if (dirname[0] === '@') {
|
||||||
function (cb) {
|
const subdirs = await fs.promises.readdir(dirPath);
|
||||||
fs.stat(dirPath, (err, stats) => {
|
await Promise.all(subdirs.map(async (subdir) => {
|
||||||
if (err && err.code !== 'ENOENT') {
|
if (!pluginNamePattern.test(subdir)) {
|
||||||
return cb(err);
|
return;
|
||||||
}
|
}
|
||||||
if (err || !stats.isDirectory()) {
|
|
||||||
return next();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pluginNamePattern.test(dirname)) {
|
const subdirPath = path.join(dirPath, subdir);
|
||||||
pluginPaths.push(dirname);
|
const isDir = await isDirectory(subdirPath);
|
||||||
return next();
|
if (isDir) {
|
||||||
}
|
pluginPaths.push(`${dirname}/${subdir}`);
|
||||||
|
}
|
||||||
if (dirname[0] !== '@') {
|
}));
|
||||||
return next();
|
}
|
||||||
}
|
}));
|
||||||
fs.readdir(dirPath, cb);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
function (subdirs, cb) {
|
|
||||||
async.each(subdirs, (subdir, next) => {
|
|
||||||
if (!pluginNamePattern.test(subdir)) {
|
|
||||||
return next();
|
|
||||||
}
|
|
||||||
|
|
||||||
const subdirPath = path.join(dirPath, subdir);
|
|
||||||
fs.stat(subdirPath, (err, stats) => {
|
|
||||||
if (err && err.code !== 'ENOENT') {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (err || !stats.isDirectory()) {
|
|
||||||
return next();
|
|
||||||
}
|
|
||||||
|
|
||||||
pluginPaths.push(`${dirname}/${subdir}`);
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
}, cb);
|
|
||||||
},
|
|
||||||
], next);
|
|
||||||
});
|
|
||||||
return pluginPaths;
|
return pluginPaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function isDirectory(dirPath) {
|
||||||
|
try {
|
||||||
|
const stats = await fs.promises.stat(dirPath);
|
||||||
|
return stats.isDirectory();
|
||||||
|
} catch (err) {
|
||||||
|
if (err.code !== 'ENOENT') {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
require('../promisify')(Plugins);
|
require('../promisify')(Plugins);
|
||||||
|
|||||||
Reference in New Issue
Block a user