Use console.log instead of process.stdout.write (#6123)

* Use console.log instead of process.stdout.write

* Don't break the installer
v1.18.x
Peter Jaszkowiak 7 years ago committed by Barış Soner Uşaklı
parent 15c8693a23
commit dbdc05404d

@ -12,8 +12,7 @@ var questions = {
module.exports = function (config, callback) { module.exports = function (config, callback) {
async.waterfall([ async.waterfall([
function (next) { function (next) {
process.stdout.write('\n'); winston.info('\nNow configuring ' + config.database + ' database:');
winston.info('Now configuring ' + config.database + ' database:');
getDatabaseConfig(config, next); getDatabaseConfig(config, next);
}, },
function (databaseConfig, next) { function (databaseConfig, next) {

@ -5,6 +5,7 @@ var express = require('express');
var bodyParser = require('body-parser'); var bodyParser = require('body-parser');
var fs = require('fs'); var fs = require('fs');
var path = require('path'); var path = require('path');
var childProcess = require('child_process');
var less = require('less'); var less = require('less');
var async = require('async'); var async = require('async');
var uglify = require('uglify-js'); var uglify = require('uglify-js');
@ -127,15 +128,15 @@ function launch(req, res) {
res.json({}); res.json({});
server.close(); server.close();
var child = require('child_process').spawn('node', ['loader.js'], { var child = childProcess.spawn('node', ['loader.js'], {
detached: true, detached: true,
stdio: ['ignore', 'ignore', 'ignore'], stdio: ['ignore', 'ignore', 'ignore'],
}); });
process.stdout.write('\nStarting NodeBB\n'); console.log('\nStarting NodeBB');
process.stdout.write(' "./nodebb stop" to stop the NodeBB server\n'); console.log(' "./nodebb stop" to stop the NodeBB server');
process.stdout.write(' "./nodebb log" to view server output\n'); console.log(' "./nodebb log" to view server output');
process.stdout.write(' "./nodebb restart" to restart NodeBB\n'); console.log(' "./nodebb restart" to restart NodeBB');
var filesToDelete = [ var filesToDelete = [
'installer.css', 'installer.css',

@ -12,15 +12,15 @@ try {
fs.readFileSync(path.join(dirname, 'node_modules/async/package.json')); fs.readFileSync(path.join(dirname, 'node_modules/async/package.json'));
} catch (e) { } catch (e) {
if (e.code === 'ENOENT') { if (e.code === 'ENOENT') {
process.stdout.write('Dependencies not yet installed.\n'); console.warn('Dependencies not yet installed.');
process.stdout.write('Installing them now...\n\n'); console.log('Installing them now...\n');
packageInstall.updatePackageFile(); packageInstall.updatePackageFile();
packageInstall.preserveExtraneousPlugins(); packageInstall.preserveExtraneousPlugins();
packageInstall.npmInstallProduction(); packageInstall.npmInstallProduction();
require('colors'); require('colors');
process.stdout.write('OK'.green + '\n'.reset); console.log('OK'.green + '\n'.reset);
} else { } else {
throw e; throw e;
} }
@ -182,7 +182,7 @@ resetCommand
return options[x]; return options[x];
}); });
if (!valid) { if (!valid) {
process.stdout.write('\n No valid options passed in, so nothing was reset.\n'.red); console.warn('\n No valid options passed in, so nothing was reset.'.red);
resetCommand.help(); resetCommand.help();
} }
@ -206,13 +206,12 @@ program
.option('-s, --schema', 'Update NodeBB data store schema', false) .option('-s, --schema', 'Update NodeBB data store schema', false)
.option('-b, --build', 'Rebuild assets', false) .option('-b, --build', 'Rebuild assets', false)
.on('--help', function () { .on('--help', function () {
process.stdout.write( console.log('\n' + [
'\n' + 'When running particular upgrade scripts, options are ignored.',
'When running particular upgrade scripts, options are ignored.\n' + 'By default all options are enabled. Passing any options disables that default.',
'By default all options are enabled. Passing any options disables that default.\n' + 'Only package and dependency updates: ' + './nodebb upgrade -mi'.yellow,
'Only package and dependency updates: ' + './nodebb upgrade -mi\n'.yellow + 'Only database update: ' + './nodebb upgrade -d'.yellow,
'Only database update: ' + './nodebb upgrade -d\n\n'.yellow ].join('\n'));
);
}) })
.action(function (scripts, options) { .action(function (scripts, options) {
require('./upgrade').upgrade(scripts.length ? scripts : true, options); require('./upgrade').upgrade(scripts.length ? scripts : true, options);
@ -229,7 +228,7 @@ program
if (err) { if (err) {
throw err; throw err;
} }
process.stdout.write('OK\n'.green); console.log('OK'.green);
process.exit(); process.exit();
}); });
}); });

@ -24,11 +24,11 @@ function buildTargets() {
}).map(function (tuple) { }).map(function (tuple) {
return ' ' + _.padEnd('"' + tuple[0] + '"', length + 2).magenta + ' | ' + tuple[1]; return ' ' + _.padEnd('"' + tuple[0] + '"', length + 2).magenta + ' | ' + tuple[1];
}).join('\n'); }).join('\n');
process.stdout.write( console.log(
'\n\n Build targets:\n' + '\n\n Build targets:\n' +
('\n ' + _.padEnd('Target', length + 2) + ' | Aliases').green + ('\n ' + _.padEnd('Target', length + 2) + ' | Aliases').green +
'\n ------------------------------------------------------\n'.blue + '\n ------------------------------------------------------\n'.blue +
output + '\n\n' output + '\n'
); );
} }
@ -100,24 +100,23 @@ function listEvents() {
} }
function info() { function info() {
console.log('');
async.waterfall([ async.waterfall([
function (next) { function (next) {
var version = require('../../package.json').version; var version = require('../../package.json').version;
process.stdout.write('\n version: ' + version); console.log(' version: ' + version);
process.stdout.write('\n Node ver: ' + process.version); console.log(' Node ver: ' + process.version);
next(); next();
}, },
function (next) { function (next) {
process.stdout.write('\n git hash: '); var hash = childProcess.execSync('git rev-parse HEAD');
childProcess.execSync('git rev-parse HEAD', { console.log(' git hash: ' + hash);
stdio: 'inherit',
});
next(); next();
}, },
function (next) { function (next) {
var config = require('../../config.json'); var config = require('../../config.json');
process.stdout.write('\n database: ' + config.database); console.log(' database: ' + config.database);
next(); next();
}, },
db.init, db.init,
@ -125,8 +124,8 @@ function info() {
db.info(db.client, next); db.info(db.client, next);
}, },
function (info, next) { function (info, next) {
process.stdout.write('\n version: ' + info.version); console.log(' version: ' + info.version);
process.stdout.write('\n engine: ' + info.storageEngine); console.log(' engine: ' + info.storageEngine);
next(); next();
}, },
], function (err) { ], function (err) {

@ -54,18 +54,19 @@ exports.reset = function (options, callback) {
.map(function (x) { return map[x]; }); .map(function (x) { return map[x]; });
if (!tasks.length) { if (!tasks.length) {
process.stdout.write('\nNodeBB Reset\n'.bold); console.log([
process.stdout.write('No arguments passed in, so nothing was reset.\n\n'.yellow); 'No arguments passed in, so nothing was reset.\n'.yellow,
process.stdout.write('Use ./nodebb reset ' + '{-t|-p|-w|-s|-a}\n'.red); 'Use ./nodebb reset ' + '{-t|-p|-w|-s|-a}'.red,
process.stdout.write(' -t\tthemes\n'); ' -t\tthemes',
process.stdout.write(' -p\tplugins\n'); ' -p\tplugins',
process.stdout.write(' -w\twidgets\n'); ' -w\twidgets',
process.stdout.write(' -s\tsettings\n'); ' -s\tsettings',
process.stdout.write(' -a\tall of the above\n'); ' -a\tall of the above',
'',
process.stdout.write('\nPlugin and theme reset flags (-p & -t) can take a single argument\n'); 'Plugin and theme reset flags (-p & -t) can take a single argument',
process.stdout.write(' e.g. ./nodebb reset -p nodebb-plugin-mentions, ./nodebb reset -t nodebb-theme-persona\n'); ' e.g. ./nodebb reset -p nodebb-plugin-mentions, ./nodebb reset -t nodebb-theme-persona',
process.stdout.write(' Prefix is optional, e.g. ./nodebb reset -p markdown, ./nodebb reset -t persona\n'); ' Prefix is optional, e.g. ./nodebb reset -p markdown, ./nodebb reset -t persona',
].join('\n'));
process.exit(0); process.exit(0);
} }

@ -38,21 +38,23 @@ function start(options) {
return; return;
} }
if (options.log) { if (options.log) {
process.stdout.write('\nStarting NodeBB with logging output\n'.bold); console.log('\n' + [
process.stdout.write('\nHit '.red + 'Ctrl-C '.bold + 'to exit'.red); 'Starting NodeBB with logging output'.bold,
'Hit '.red + 'Ctrl-C '.bold + 'to exit'.red,
process.stdout.write('\nThe NodeBB process will continue to run in the background'); 'The NodeBB process will continue to run in the background',
process.stdout.write('\nUse "' + './nodebb stop'.yellow + '" to stop the NodeBB server\n'); 'Use "' + './nodebb stop'.yellow + '" to stop the NodeBB server',
process.stdout.write('\n\n'.reset); ].join('\n'));
} else if (!options.silent) { } else if (!options.silent) {
process.stdout.write('\nStarting NodeBB\n'.bold); console.log('\n' + [
process.stdout.write(' "' + './nodebb stop'.yellow + '" to stop the NodeBB server\n'); 'Starting NodeBB'.bold,
process.stdout.write(' "' + './nodebb log'.yellow + '" to view server output\n'); ' "' + './nodebb stop'.yellow + '" to stop the NodeBB server',
process.stdout.write(' "' + './nodebb restart'.yellow + '" to restart NodeBB\n\n'.reset); ' "' + './nodebb log'.yellow + '" to view server output',
' "' + './nodebb help'.yellow + '" for more commands\n'.reset,
].join('\n'));
} }
// Spawn a new NodeBB process // Spawn a new NodeBB process
fork(paths.loader, process.argv.slice(3), { var child = fork(paths.loader, process.argv.slice(3), {
env: process.env, env: process.env,
cwd: dirname, cwd: dirname,
}); });
@ -62,15 +64,17 @@ function start(options) {
stdio: 'inherit', stdio: 'inherit',
}); });
} }
return child;
} }
function stop() { function stop() {
getRunningPid(function (err, pid) { getRunningPid(function (err, pid) {
if (!err) { if (!err) {
process.kill(pid, 'SIGTERM'); process.kill(pid, 'SIGTERM');
process.stdout.write('Stopping NodeBB. Goodbye!\n'); console.log('Stopping NodeBB. Goodbye!');
} else { } else {
process.stdout.write('NodeBB is already stopped.\n'); console.log('NodeBB is already stopped.');
} }
}); });
} }
@ -78,13 +82,13 @@ function stop() {
function restart(options) { function restart(options) {
getRunningPid(function (err, pid) { getRunningPid(function (err, pid) {
if (!err) { if (!err) {
process.stdout.write('\nRestarting NodeBB\n'.bold); console.log('\nRestarting NodeBB'.bold);
process.kill(pid, 'SIGTERM'); process.kill(pid, 'SIGTERM');
options.silent = true; options.silent = true;
start(options); start(options);
} else { } else {
process.stdout.write('NodeBB could not be restarted, as a running instance could not be found.\n'); console.warn('NodeBB could not be restarted, as a running instance could not be found.');
} }
}); });
} }
@ -92,20 +96,21 @@ function restart(options) {
function status() { function status() {
getRunningPid(function (err, pid) { getRunningPid(function (err, pid) {
if (!err) { if (!err) {
process.stdout.write('\nNodeBB Running '.bold + '(pid '.cyan + pid.toString().cyan + ')\n'.cyan); console.log('\n' + [
process.stdout.write('\t"' + './nodebb stop'.yellow + '" to stop the NodeBB server\n'); 'NodeBB Running '.bold + ('(pid ' + pid.toString() + ')').cyan,
process.stdout.write('\t"' + './nodebb log'.yellow + '" to view server output\n'); '\t"' + './nodebb stop'.yellow + '" to stop the NodeBB server',
process.stdout.write('\t"' + './nodebb restart'.yellow + '" to restart NodeBB\n\n'); '\t"' + './nodebb log'.yellow + '" to view server output',
'\t"' + './nodebb restart'.yellow + '" to restart NodeBB\n',
].join('\n'));
} else { } else {
process.stdout.write('\nNodeBB is not running\n'.bold); console.log('\nNodeBB is not running'.bold);
process.stdout.write('\t"' + './nodebb start'.yellow + '" to launch the NodeBB server\n\n'.reset); console.log('\t"' + './nodebb start'.yellow + '" to launch the NodeBB server\n'.reset);
} }
}); });
} }
function log() { function log() {
process.stdout.write('\nHit '.red + 'Ctrl-C '.bold + 'to exit'.red); console.log('\nHit '.red + 'Ctrl-C '.bold + 'to exit\n'.red + '\n'.reset);
process.stdout.write('\n\n'.reset);
childProcess.spawn('tail', ['-F', './logs/output.log'], { childProcess.spawn('tail', ['-F', './logs/output.log'], {
cwd: dirname, cwd: dirname,
stdio: 'inherit', stdio: 'inherit',

@ -12,9 +12,9 @@ function setup() {
winston.info('NodeBB Setup Triggered via Command Line'); winston.info('NodeBB Setup Triggered via Command Line');
process.stdout.write('\nWelcome to NodeBB!\n'); console.log('\nWelcome to NodeBB!');
process.stdout.write('\nThis looks like a new installation, so you\'ll have to answer a few questions about your environment before we can proceed.\n'); console.log('\nThis looks like a new installation, so you\'ll have to answer a few questions about your environment before we can proceed.');
process.stdout.write('Press enter to accept the default setting (shown in brackets).\n'); console.log('Press enter to accept the default setting (shown in brackets).');
async.series([ async.series([
install.setup, install.setup,
@ -30,19 +30,19 @@ function setup() {
separator += '='; separator += '=';
} }
} }
process.stdout.write('\n' + separator + '\n\n'); console.log('\n' + separator + '\n');
if (err) { if (err) {
winston.error('There was a problem completing NodeBB setup', err); winston.error('There was a problem completing NodeBB setup', err);
throw err; throw err;
} else { } else {
if (data.hasOwnProperty('password')) { if (data.hasOwnProperty('password')) {
process.stdout.write('An administrative user was automatically created for you:\n'); console.log('An administrative user was automatically created for you:');
process.stdout.write(' Username: ' + data.username + '\n'); console.log(' Username: ' + data.username + '');
process.stdout.write(' Password: ' + data.password + '\n'); console.log(' Password: ' + data.password + '');
process.stdout.write('\n'); console.log('');
} }
process.stdout.write('NodeBB Setup Completed. Run \'./nodebb start\' to manually start your NodeBB server.\n'); console.log('NodeBB Setup Completed. Run "./nodebb start" to manually start your NodeBB server.');
// If I am a child process, notify the parent of the returned data before exiting (useful for notifying // If I am a child process, notify the parent of the returned data before exiting (useful for notifying
// hosts of auto-generated username/password during headless setups) // hosts of auto-generated username/password during headless setups)

@ -105,7 +105,7 @@ function getCurrentVersion(callback) {
function checkPlugins(standalone, callback) { function checkPlugins(standalone, callback) {
if (standalone) { if (standalone) {
process.stdout.write('Checking installed plugins and themes for updates... '); console.log('Checking installed plugins and themes for updates... ');
} }
async.waterfall([ async.waterfall([
@ -117,7 +117,7 @@ function checkPlugins(standalone, callback) {
var toCheck = Object.keys(payload.plugins); var toCheck = Object.keys(payload.plugins);
if (!toCheck.length) { if (!toCheck.length) {
process.stdout.write('OK'.green + '\n'.reset); console.log('OK'.green + ''.reset);
return next(null, []); // no extraneous plugins installed return next(null, []); // no extraneous plugins installed
} }
@ -127,10 +127,10 @@ function checkPlugins(standalone, callback) {
json: true, json: true,
}, function (err, res, body) { }, function (err, res, body) {
if (err) { if (err) {
process.stdout.write('error'.red + '\n'.reset); console.log('error'.red + ''.reset);
return next(err); return next(err);
} }
process.stdout.write('OK'.green + '\n'.reset); console.log('OK'.green + ''.reset);
if (!Array.isArray(body) && toCheck.length === 1) { if (!Array.isArray(body) && toCheck.length === 1) {
body = [body]; body = [body];
@ -167,19 +167,19 @@ function upgradePlugins(callback) {
checkPlugins(standalone, function (err, found) { checkPlugins(standalone, function (err, found) {
if (err) { if (err) {
process.stdout.write('Warning'.yellow + ': An unexpected error occured when attempting to verify plugin upgradability\n'.reset); console.log('Warning'.yellow + ': An unexpected error occured when attempting to verify plugin upgradability'.reset);
return callback(err); return callback(err);
} }
if (found && found.length) { if (found && found.length) {
process.stdout.write('\nA total of ' + String(found.length).bold + ' package(s) can be upgraded:\n'); console.log('\nA total of ' + String(found.length).bold + ' package(s) can be upgraded:');
found.forEach(function (suggestObj) { found.forEach(function (suggestObj) {
process.stdout.write(' * '.yellow + suggestObj.name.reset + ' (' + suggestObj.current.yellow + ' -> '.reset + suggestObj.suggested.green + ')\n'.reset); console.log(' * '.yellow + suggestObj.name.reset + ' (' + suggestObj.current.yellow + ' -> '.reset + suggestObj.suggested.green + ')\n'.reset);
}); });
process.stdout.write('\n'); console.log('');
} else { } else {
if (standalone) { if (standalone) {
process.stdout.write('\nAll packages up-to-date!'.green + '\n'.reset); console.log('\nAll packages up-to-date!'.green + ''.reset);
} }
return callback(); return callback();
} }
@ -198,7 +198,7 @@ function upgradePlugins(callback) {
} }
if (['y', 'Y', 'yes', 'YES'].indexOf(result.upgrade) !== -1) { if (['y', 'Y', 'yes', 'YES'].indexOf(result.upgrade) !== -1) {
process.stdout.write('\nUpgrading packages...'); console.log('\nUpgrading packages...');
var args = ['i']; var args = ['i'];
found.forEach(function (suggestObj) { found.forEach(function (suggestObj) {
args.push(suggestObj.name + '@' + suggestObj.suggested); args.push(suggestObj.name + '@' + suggestObj.suggested);
@ -206,7 +206,7 @@ function upgradePlugins(callback) {
cproc.execFile((process.platform === 'win32') ? 'npm.cmd' : 'npm', args, { stdio: 'ignore' }, callback); cproc.execFile((process.platform === 'win32') ? 'npm.cmd' : 'npm', args, { stdio: 'ignore' }, callback);
} else { } else {
process.stdout.write('\nPackage upgrades skipped'.yellow + '. Check for upgrades at any time by running "'.reset + './nodebb upgrade-plugins'.green + '".\n'.reset); console.log('Package upgrades skipped'.yellow + '. Check for upgrades at any time by running "'.reset + './nodebb upgrade-plugins'.green + '".'.reset);
callback(); callback();
} }
}); });

@ -11,64 +11,60 @@ var meta = require('../meta');
var upgradePlugins = require('./upgrade-plugins').upgradePlugins; var upgradePlugins = require('./upgrade-plugins').upgradePlugins;
var steps = { var steps = {
package: function (next) { package: {
process.stdout.write('Updating package.json file with defaults... \n'.yellow); message: 'Updating package.json file with defaults...',
handler: function (next) {
packageInstall.updatePackageFile(); packageInstall.updatePackageFile();
packageInstall.preserveExtraneousPlugins(); packageInstall.preserveExtraneousPlugins();
process.stdout.write('OK\n'.green);
next(); next();
}, },
install: function (next) { },
process.stdout.write('Bringing base dependencies up to date... \n'.yellow); install: {
message: 'Bringing base dependencies up to date...',
handler: function (next) {
packageInstall.npmInstallProduction(); packageInstall.npmInstallProduction();
process.stdout.write('OK\n'.green);
next(); next();
}, },
plugins: function (next) { },
process.stdout.write('Checking installed plugins for updates... \n'.yellow); plugins: {
message: 'Checking installed plugins for updates...',
handler: function (next) {
async.series([ async.series([
db.init, db.init,
upgradePlugins, upgradePlugins,
function (next) {
process.stdout.write('OK\n'.green);
next();
},
], next); ], next);
}, },
schema: function (next) { },
process.stdout.write('Updating NodeBB data store schema...\n'.yellow); schema: {
message: 'Updating NodeBB data store schema...',
handler: function (next) {
async.series([ async.series([
db.init, db.init,
upgrade.run, upgrade.run,
function (next) {
process.stdout.write('OK\n'.green);
next();
},
], next); ], next);
}, },
build: function (next) {
process.stdout.write('Rebuilding assets...\n'.yellow);
async.series([
build.buildAll,
function (next) {
process.stdout.write('OK\n'.green);
next();
}, },
], next); build: {
message: 'Rebuilding assets...',
handler: build.buildAll,
}, },
}; };
function runSteps(tasks) { function runSteps(tasks) {
tasks = tasks.map(function (key, i) { tasks = tasks.map(function (key, i) {
return function (next) { return function (next) {
process.stdout.write(((i + 1) + '. ').bold); console.log(((i + 1) + '. ').bold + steps[key].message.yellow);
return steps[key](next); return steps[key].handler(function (err) {
if (err) { return next(err); }
console.log(' OK'.green);
next();
});
}; };
}); });
async.series(tasks, function (err) { async.series(tasks, function (err) {
if (err) { if (err) {
process.stdout.write('Error occurred during upgrade'); console.error('Error occurred during upgrade');
throw err; throw err;
} }
@ -77,14 +73,14 @@ function runSteps(tasks) {
var columns = process.stdout.columns; var columns = process.stdout.columns;
var spaces = columns ? new Array(Math.floor(columns / 2) - (message.length / 2) + 1).join(' ') : ' '; var spaces = columns ? new Array(Math.floor(columns / 2) - (message.length / 2) + 1).join(' ') : ' ';
process.stdout.write('\n' + spaces + message.green.bold + '\n\n'.reset); console.log('\n' + spaces + message.green.bold + '\n'.reset);
process.exit(); process.exit();
}); });
} }
function runUpgrade(upgrades, options) { function runUpgrade(upgrades, options) {
process.stdout.write('\nUpdating NodeBB...\n'.cyan); console.log('\nUpdating NodeBB...'.cyan);
// disable mongo timeouts during upgrade // disable mongo timeouts during upgrade
nconf.set('mongo:options:socketTimeoutMS', 0); nconf.set('mongo:options:socketTimeoutMS', 0);

@ -141,7 +141,7 @@ events.deleteAll = function (callback) {
}; };
events.output = function () { events.output = function () {
process.stdout.write('\nDisplaying last ten administrative events...\n'.bold); console.log('\nDisplaying last ten administrative events...'.bold);
events.getEvents(0, 9, function (err, events) { events.getEvents(0, 9, function (err, events) {
if (err) { if (err) {
winston.error('Error fetching events', err); winston.error('Error fetching events', err);
@ -149,7 +149,7 @@ events.output = function () {
} }
events.forEach(function (event) { events.forEach(function (event) {
process.stdout.write(' * ' + String(event.timestampISO).green + ' ' + String(event.type).yellow + (event.text ? ' ' + event.text : '') + ' (uid: '.reset + (event.uid ? event.uid : 0) + ')\n'); console.log(' * ' + String(event.timestampISO).green + ' ' + String(event.type).yellow + (event.text ? ' ' + event.text : '') + ' (uid: '.reset + (event.uid ? event.uid : 0) + ')');
}); });
process.exit(0); process.exit(0);

@ -174,7 +174,7 @@ function completeConfigSetup(config, next) {
} }
function setupDefaultConfigs(next) { function setupDefaultConfigs(next) {
process.stdout.write('Populating database with default configs, if not already set...\n'); console.log('Populating database with default configs, if not already set...');
var meta = require('./meta'); var meta = require('./meta');
var defaults = require(path.join(__dirname, '../', 'install/data/defaults.json')); var defaults = require(path.join(__dirname, '../', 'install/data/defaults.json'));
@ -192,11 +192,11 @@ function enableDefaultTheme(next) {
meta.configs.get('theme:id', function (err, id) { meta.configs.get('theme:id', function (err, id) {
if (err || id) { if (err || id) {
process.stdout.write('Previous theme detected, skipping enabling default theme\n'); console.log('Previous theme detected, skipping enabling default theme');
return next(err); return next(err);
} }
var defaultTheme = nconf.get('defaultTheme') || 'nodebb-theme-persona'; var defaultTheme = nconf.get('defaultTheme') || 'nodebb-theme-persona';
process.stdout.write('Enabling default theme: ' + defaultTheme + '\n'); console.log('Enabling default theme: ' + defaultTheme);
meta.themes.set({ meta.themes.set({
type: 'local', type: 'local',
id: defaultTheme, id: defaultTheme,
@ -211,7 +211,7 @@ function createAdministrator(next) {
return next(err); return next(err);
} }
if (memberCount > 0) { if (memberCount > 0) {
process.stdout.write('Administrator found, skipping Admin setup\n'); console.log('Administrator found, skipping Admin setup');
next(); next();
} else { } else {
createAdmin(next); createAdmin(next);
@ -315,7 +315,7 @@ function createAdmin(callback) {
} else { } else {
// If automated setup did not provide a user password, generate one, it will be shown to the user upon setup completion // If automated setup did not provide a user password, generate one, it will be shown to the user upon setup completion
if (!install.values.hasOwnProperty('admin:password') && !nconf.get('admin:password')) { if (!install.values.hasOwnProperty('admin:password') && !nconf.get('admin:password')) {
process.stdout.write('Password was not provided during automated setup, generating one...\n'); console.log('Password was not provided during automated setup, generating one...');
password = utils.generateUUID().slice(0, 8); password = utils.generateUUID().slice(0, 8);
} }
@ -365,11 +365,11 @@ function createCategories(next) {
} }
if (Array.isArray(categoryData) && categoryData.length) { if (Array.isArray(categoryData) && categoryData.length) {
process.stdout.write('Categories OK. Found ' + categoryData.length + ' categories.\n'); console.log('Categories OK. Found ' + categoryData.length + ' categories.');
return next(); return next();
} }
process.stdout.write('No categories found, populating instance with default categories\n'); console.log('No categories found, populating instance with default categories');
fs.readFile(path.join(__dirname, '../', 'install/data/categories.json'), 'utf8', function (err, default_categories) { fs.readFile(path.join(__dirname, '../', 'install/data/categories.json'), 'utf8', function (err, default_categories) {
if (err) { if (err) {
@ -416,7 +416,7 @@ function createWelcomePost(next) {
var numTopics = results[1]; var numTopics = results[1];
if (!parseInt(numTopics, 10)) { if (!parseInt(numTopics, 10)) {
process.stdout.write('Creating welcome post!\n'); console.log('Creating welcome post!');
Topics.post({ Topics.post({
uid: 1, uid: 1,
cid: 2, cid: 2,
@ -430,7 +430,7 @@ function createWelcomePost(next) {
} }
function enableDefaultPlugins(next) { function enableDefaultPlugins(next) {
process.stdout.write('Enabling default plugins\n'); console.log('Enabling default plugins');
var defaultEnabled = [ var defaultEnabled = [
'nodebb-plugin-composer-default', 'nodebb-plugin-composer-default',
@ -546,7 +546,7 @@ install.save = function (server_conf, callback) {
return callback(err); return callback(err);
} }
process.stdout.write('Configuration Saved OK\n'); console.log('Configuration Saved OK');
nconf.file({ nconf.file({
file: path.join(__dirname, '..', 'config.json'), file: path.join(__dirname, '..', 'config.json'),

@ -97,12 +97,12 @@ Plugins.reload = function (callback) {
function (next) { function (next) {
// If some plugins are incompatible, throw the warning here // If some plugins are incompatible, throw the warning here
if (Plugins.versionWarning.length && nconf.get('isPrimary') === 'true') { if (Plugins.versionWarning.length && nconf.get('isPrimary') === 'true') {
process.stdout.write('\n'); console.log('');
winston.warn('[plugins/load] The following plugins may not be compatible with your version of NodeBB. This may cause unintended behaviour or crashing. In the event of an unresponsive NodeBB caused by this plugin, run `./nodebb reset -p PLUGINNAME` to disable it.'); winston.warn('[plugins/load] The following plugins may not be compatible with your version of NodeBB. This may cause unintended behaviour or crashing. In the event of an unresponsive NodeBB caused by this plugin, run `./nodebb reset -p PLUGINNAME` to disable it.');
for (var x = 0, numPlugins = Plugins.versionWarning.length; x < numPlugins; x += 1) { for (var x = 0, numPlugins = Plugins.versionWarning.length; x < numPlugins; x += 1) {
process.stdout.write(' * '.yellow + Plugins.versionWarning[x] + '\n'); console.log(' * '.yellow + Plugins.versionWarning[x]);
} }
process.stdout.write('\n'); console.log('');
} }
Object.keys(Plugins.loadedHooks).forEach(function (hook) { Object.keys(Plugins.loadedHooks).forEach(function (hook) {

@ -91,7 +91,7 @@ Upgrade.check = function (callback) {
}; };
Upgrade.run = function (callback) { Upgrade.run = function (callback) {
process.stdout.write('\nParsing upgrade scripts... '); console.log('\nParsing upgrade scripts... ');
var queue = []; var queue = [];
var skipped = 0; var skipped = 0;
@ -120,7 +120,7 @@ Upgrade.run = function (callback) {
}; };
Upgrade.runParticular = function (names, callback) { Upgrade.runParticular = function (names, callback) {
process.stdout.write('\nParsing upgrade scripts... '); console.log('\nParsing upgrade scripts... ');
async.waterfall([ async.waterfall([
async.apply(file.walk, path.join(__dirname, './upgrades')), async.apply(file.walk, path.join(__dirname, './upgrades')),
@ -135,7 +135,7 @@ Upgrade.runParticular = function (names, callback) {
}; };
Upgrade.process = function (files, skipCount, callback) { Upgrade.process = function (files, skipCount, callback) {
process.stdout.write('OK'.green + ' | '.reset + String(files.length).cyan + ' script(s) found'.cyan + (skipCount > 0 ? ', '.cyan + String(skipCount).cyan + ' skipped'.cyan : '') + '\n'.reset); console.log('OK'.green + ' | '.reset + String(files.length).cyan + ' script(s) found'.cyan + (skipCount > 0 ? ', '.cyan + String(skipCount).cyan + ' skipped'.cyan : ''));
async.waterfall([ async.waterfall([
function (next) { function (next) {
@ -157,14 +157,14 @@ Upgrade.process = function (files, skipCount, callback) {
date: date, date: date,
}; };
process.stdout.write(' → '.white + String('[' + [date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate()].join('/') + '] ').gray + String(scriptExport.name).reset + '...\n'); console.log(' → '.white + String('[' + [date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate()].join('/') + '] ').gray + String(scriptExport.name).reset + '...');
// For backwards compatibility, cross-reference with schemaDate (if found). If a script's date is older, skip it // For backwards compatibility, cross-reference with schemaDate (if found). If a script's date is older, skip it
if ((!results.schemaDate && !results.schemaLogCount) || (scriptExport.timestamp <= results.schemaDate && semver.lt(version, '1.5.0'))) { if ((!results.schemaDate && !results.schemaLogCount) || (scriptExport.timestamp <= results.schemaDate && semver.lt(version, '1.5.0'))) {
readline.clearLine(process.stdout, 0); readline.clearLine(process.stdout, 0);
readline.cursorTo(process.stdout, 0); readline.cursorTo(process.stdout, 0);
readline.moveCursor(process.stdout, 0, -1); readline.moveCursor(process.stdout, 0, -1);
process.stdout.write(' → '.white + String('[' + [date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate()].join('/') + '] ').gray + String(scriptExport.name).reset + '... ' + 'skipped\n'.grey); console.log(' → '.white + String('[' + [date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate()].join('/') + '] ').gray + String(scriptExport.name).reset + '... ' + 'skipped'.grey);
db.sortedSetAdd('schemaLog', Date.now(), path.basename(file, '.js'), next); db.sortedSetAdd('schemaLog', Date.now(), path.basename(file, '.js'), next);
return; return;
} }
@ -174,14 +174,14 @@ Upgrade.process = function (files, skipCount, callback) {
progress: progress, progress: progress,
})(function (err) { })(function (err) {
if (err) { if (err) {
process.stdout.write('error\n'.red); console.error('Error occurred');
return next(err); return next(err);
} }
readline.clearLine(process.stdout, 0); readline.clearLine(process.stdout, 0);
readline.cursorTo(process.stdout, 0); readline.cursorTo(process.stdout, 0);
readline.moveCursor(process.stdout, 0, -1); readline.moveCursor(process.stdout, 0, -1);
process.stdout.write(' → '.white + String('[' + [date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate()].join('/') + '] ').gray + String(scriptExport.name).reset + '... ' + 'OK\n'.green); console.log(' → '.white + String('[' + [date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate()].join('/') + '] ').gray + String(scriptExport.name).reset + '... ' + 'OK'.green);
// Record success in schemaLog // Record success in schemaLog
db.sortedSetAdd('schemaLog', Date.now(), path.basename(file, '.js'), next); db.sortedSetAdd('schemaLog', Date.now(), path.basename(file, '.js'), next);
@ -189,7 +189,7 @@ Upgrade.process = function (files, skipCount, callback) {
}, next); }, next);
}, },
function (next) { function (next) {
process.stdout.write('Upgrade complete!\n\n'.green); console.log('Upgrade complete!\n'.green);
setImmediate(next); setImmediate(next);
}, },
], callback); ], callback);

Loading…
Cancel
Save