mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-05 23:30:36 +01:00
Merge pull request #5663 from NodeBB/sounds-fix
Fix soundpacks not working, auto install dependencies, defer logging in tests
This commit is contained in:
46
nodebb
46
nodebb
@@ -2,10 +2,28 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var cproc;
|
||||
var args;
|
||||
var fs;
|
||||
var path;
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var cproc = require('child_process');
|
||||
|
||||
// check to make sure dependencies are installed
|
||||
try {
|
||||
fs.readFileSync(path.join(__dirname, 'node_modules/async/package.json'));
|
||||
} catch (e) {
|
||||
if (e.code === 'ENOENT') {
|
||||
process.stdout.write('Dependencies not yet installed.\n');
|
||||
process.stdout.write('Installing them now...\n\n');
|
||||
|
||||
cproc.execSync('npm i --production', {
|
||||
cwd: __dirname,
|
||||
stdio: [0, 1, 2],
|
||||
});
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
var minimist;
|
||||
var request;
|
||||
var semver;
|
||||
var prompt;
|
||||
@@ -13,25 +31,23 @@ var async;
|
||||
|
||||
try {
|
||||
require('colors');
|
||||
cproc = require('child_process');
|
||||
args = require('minimist')(process.argv.slice(2));
|
||||
fs = require('fs');
|
||||
path = require('path');
|
||||
minimist = require('minimist');
|
||||
request = require('request');
|
||||
semver = require('semver');
|
||||
prompt = require('prompt');
|
||||
async = require('async');
|
||||
} catch (e) {
|
||||
if (e.code === 'MODULE_NOT_FOUND') {
|
||||
process.stdout.write('NodeBB could not be started because it\'s dependencies have not been installed.\n');
|
||||
process.stdout.write('Please ensure that you have executed "npm install --production" prior to running NodeBB.\n\n');
|
||||
process.stdout.write('For more information, please see: https://docs.nodebb.org/en/latest/installing/os.html\n\n');
|
||||
process.stdout.write('Could not start: ' + e.code + '\n');
|
||||
process.stdout.write(
|
||||
'\x1b[31mNodeBB could not be initialised because there was an error while loading dependencies.\n' +
|
||||
'Please run "\x1b[33mnpm install --production\x1b[31m" and try again.\x1b[0m\n\n' +
|
||||
'For more information, please see: https://docs.nodebb.org/en/latest/installing/os.html\n\n'
|
||||
);
|
||||
|
||||
process.exit(1);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
var args = minimist(process.argv.slice(2));
|
||||
|
||||
var loaderPath = path.join(__dirname, 'loader.js');
|
||||
var appPath = path.join(__dirname, 'app.js');
|
||||
|
||||
|
||||
@@ -263,12 +263,12 @@ module.exports = function (Plugins) {
|
||||
soundpack.id = pluginData.id;
|
||||
soundpack.dir = path.join(pluginData.path, soundpack.dir);
|
||||
async.each(Object.keys(soundpack.sounds), function (key, next) {
|
||||
file.exists(path.join(soundpack.dir, soundpack.sounds[key]), function (exists) {
|
||||
file.exists(path.join(soundpack.dir, soundpack.sounds[key]), function (err, exists) {
|
||||
if (!exists) {
|
||||
delete soundpack.sounds[key];
|
||||
}
|
||||
|
||||
next();
|
||||
next(err);
|
||||
});
|
||||
}, function (err) {
|
||||
if (err) {
|
||||
|
||||
40
test/defer-logger.js
Normal file
40
test/defer-logger.js
Normal file
@@ -0,0 +1,40 @@
|
||||
'use strict';
|
||||
|
||||
var util = require('util');
|
||||
var winston = require('winston');
|
||||
|
||||
function DeferLogger(options) {
|
||||
options = options || {};
|
||||
|
||||
this.name = 'DeferLogger';
|
||||
this.level = options.level || 'info';
|
||||
|
||||
this.logged = options.logged;
|
||||
}
|
||||
|
||||
util.inherits(DeferLogger, winston.Transport);
|
||||
|
||||
DeferLogger.prototype.log = function log(level, msg, meta, callback) {
|
||||
this.logged.push([level, msg, meta]);
|
||||
callback(null, true);
|
||||
};
|
||||
|
||||
var winstonLogged = [];
|
||||
|
||||
before(function () {
|
||||
// defer winston logs until the end
|
||||
winston.remove(winston.transports.Console);
|
||||
|
||||
winston.add(DeferLogger, {
|
||||
logged: winstonLogged,
|
||||
});
|
||||
});
|
||||
|
||||
after(function () {
|
||||
console.log('\n\n');
|
||||
|
||||
var con = new winston.transports.Console();
|
||||
winstonLogged.forEach(function (args) {
|
||||
con.log(args[0], args[1], args[2], function () {});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user