mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
Use async v2
This commit is contained in:
14
minifier.js
14
minifier.js
@@ -17,13 +17,21 @@ Minifier.js.minify = function (scripts, minify, callback) {
|
||||
});
|
||||
|
||||
async.filter(scripts, function (script, next) {
|
||||
file.exists(script, function (exists) {
|
||||
file.exists(script, function (err, exists) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (!exists) {
|
||||
console.warn('[minifier] file not found, ' + script);
|
||||
}
|
||||
next(exists);
|
||||
next(null, exists);
|
||||
});
|
||||
}, function (scripts) {
|
||||
}, function (err, scripts) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (minify) {
|
||||
minifyScripts(scripts, callback);
|
||||
} else {
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
"coveralls": "istanbul cover _mocha --report lcovonly -- -R dot && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
|
||||
},
|
||||
"dependencies": {
|
||||
"async": "~1.5.0",
|
||||
"async": "^2.1.4",
|
||||
"autoprefixer": "^6.2.3",
|
||||
"bcryptjs": "~2.3.0",
|
||||
"body-parser": "^1.9.0",
|
||||
|
||||
20
src/file.js
20
src/file.js
@@ -87,19 +87,27 @@ file.allowedExtensions = function () {
|
||||
|
||||
file.exists = function (path, callback) {
|
||||
fs.stat(path, function (err, stat) {
|
||||
callback(!err && stat);
|
||||
if (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
return callback(null, false);
|
||||
}
|
||||
return callback(err);
|
||||
}
|
||||
return callback(null, true);
|
||||
});
|
||||
};
|
||||
|
||||
file.existsSync = function (path) {
|
||||
var exists = false;
|
||||
try {
|
||||
exists = fs.statSync(path);
|
||||
} catch(err) {
|
||||
exists = false;
|
||||
fs.statSync(path);
|
||||
} catch (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
return false;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
return !!exists;
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = file;
|
||||
|
||||
@@ -19,14 +19,17 @@ module.exports = function (Meta) {
|
||||
|
||||
winston.verbose('Checking dependencies for outdated modules');
|
||||
|
||||
async.every(modules, function (module, next) {
|
||||
async.each(modules, function (module, next) {
|
||||
fs.readFile(path.join(__dirname, '../../node_modules/', module, 'package.json'), {
|
||||
encoding: 'utf-8'
|
||||
}, function (err, pkgData) {
|
||||
// If a bundled plugin/theme is not present, skip the dep check (#3384)
|
||||
if (err && err.code === 'ENOENT' && (module === 'nodebb-rewards-essentials' || module.startsWith('nodebb-plugin') || module.startsWith('nodebb-theme'))) {
|
||||
winston.warn('[meta/dependencies] Bundled plugin ' + module + ' not found, skipping dependency check.');
|
||||
return next(true);
|
||||
if (err) {
|
||||
// If a bundled plugin/theme is not present, skip the dep check (#3384)
|
||||
if (err.code === 'ENOENT' && (module === 'nodebb-rewards-essentials' || module.startsWith('nodebb-plugin') || module.startsWith('nodebb-theme'))) {
|
||||
winston.warn('[meta/dependencies] Bundled plugin ' + module + ' not found, skipping dependency check.');
|
||||
return next();
|
||||
}
|
||||
return next(err);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -34,20 +37,24 @@ module.exports = function (Meta) {
|
||||
} catch(e) {
|
||||
process.stdout.write('[' + 'missing'.red + '] ' + module.bold + ' is a required dependency but could not be found\n');
|
||||
depsMissing = true;
|
||||
return next(true);
|
||||
return next();
|
||||
}
|
||||
|
||||
var ok = !semver.validRange(pkg.dependencies[module]) || semver.satisfies(pkgData.version, pkg.dependencies[module]);
|
||||
|
||||
if (ok || (pkgData._resolved && pkgData._resolved.indexOf('//github.com') !== -1)) {
|
||||
next(true);
|
||||
next();
|
||||
} else {
|
||||
process.stdout.write('[' + 'outdated'.yellow + '] ' + module.bold + ' installed v' + pkgData.version + ', package.json requires ' + pkg.dependencies[module] + '\n');
|
||||
depsOutdated = true;
|
||||
next(true);
|
||||
next();
|
||||
}
|
||||
});
|
||||
}, function (ok) {
|
||||
}, function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (depsMissing) {
|
||||
callback(new Error('dependencies-missing'));
|
||||
} else if (depsOutdated) {
|
||||
|
||||
@@ -27,18 +27,28 @@ module.exports = function (Meta) {
|
||||
async.filter(files, function (file, next) {
|
||||
fs.stat(path.join(themePath, file), function (err, fileStat) {
|
||||
if (err) {
|
||||
return next(false);
|
||||
if (err.code === 'ENOENT') {
|
||||
return next(null, false);
|
||||
}
|
||||
return next(err);
|
||||
}
|
||||
|
||||
next((fileStat.isDirectory() && file.slice(0, 13) === 'nodebb-theme-'));
|
||||
next(null, (fileStat.isDirectory() && file.slice(0, 13) === 'nodebb-theme-'));
|
||||
});
|
||||
}, function (themes) {
|
||||
}, function (err, themes) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
async.map(themes, function (theme, next) {
|
||||
var config = path.join(themePath, theme, 'theme.json');
|
||||
|
||||
fs.readFile(config, function (err, file) {
|
||||
if (err) {
|
||||
return next();
|
||||
if (err.code === 'ENOENT') {
|
||||
return next(null, null);
|
||||
}
|
||||
return next(err);
|
||||
}
|
||||
try {
|
||||
var configObj = JSON.parse(file.toString());
|
||||
|
||||
@@ -161,9 +161,7 @@ var middleware;
|
||||
});
|
||||
|
||||
// Filter out plugins with invalid paths
|
||||
async.filter(paths, file.exists, function (paths) {
|
||||
next(null, paths);
|
||||
});
|
||||
async.filter(paths, file.exists, next);
|
||||
},
|
||||
function (paths, next) {
|
||||
async.map(paths, Plugins.loadPluginInfo, next);
|
||||
@@ -346,7 +344,13 @@ var middleware;
|
||||
|
||||
async.filter(dirs, function (dir, callback) {
|
||||
fs.stat(dir, function (err, stats) {
|
||||
callback(!err && stats.isDirectory());
|
||||
if (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
return callback(null, false);
|
||||
}
|
||||
return callback(err);
|
||||
}
|
||||
callback(null, stats.isDirectory());
|
||||
});
|
||||
}, function (plugins) {
|
||||
next(null, plugins);
|
||||
|
||||
@@ -31,9 +31,7 @@ module.exports = function (Plugins) {
|
||||
return path.join(__dirname, '../../node_modules/', plugin);
|
||||
});
|
||||
|
||||
async.filter(plugins, file.exists, function (plugins) {
|
||||
next(null, plugins);
|
||||
});
|
||||
async.filter(plugins, file.exists, next);
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -8,12 +8,8 @@ var helpers = {};
|
||||
|
||||
helpers.some = function (tasks, callback) {
|
||||
async.some(tasks, function (task, next) {
|
||||
task(function (err, result) {
|
||||
next(!err && result);
|
||||
});
|
||||
}, function (result) {
|
||||
callback(null, result);
|
||||
});
|
||||
task(next);
|
||||
}, callback);
|
||||
};
|
||||
|
||||
helpers.isUserAllowedTo = function (privilege, uid, cid, callback) {
|
||||
|
||||
@@ -37,12 +37,14 @@ rewards.checkConditionAndRewardUser = function (uid, condition, method, callback
|
||||
function (rewards, next) {
|
||||
async.filter(rewards, function (reward, next) {
|
||||
if (!reward) {
|
||||
return next(false);
|
||||
return next(null, false);
|
||||
}
|
||||
|
||||
checkCondition(reward, method, next);
|
||||
}, function (eligible) {
|
||||
if (!eligible) {
|
||||
checkCondition(reward, method, function (result) {
|
||||
next(null, result);
|
||||
});
|
||||
}, function (err, eligible) {
|
||||
if (err || !eligible) {
|
||||
return next(false);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user