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