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

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

* Don't break the installer
This commit is contained in:
Peter Jaszkowiak
2017-11-27 13:44:30 -07:00
committed by Barış Soner Uşaklı
parent 15c8693a23
commit dbdc05404d
13 changed files with 153 additions and 153 deletions

View File

@@ -12,15 +12,15 @@ 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');
console.warn('Dependencies not yet installed.');
console.log('Installing them now...\n');
packageInstall.updatePackageFile();
packageInstall.preserveExtraneousPlugins();
packageInstall.npmInstallProduction();
require('colors');
process.stdout.write('OK'.green + '\n'.reset);
console.log('OK'.green + '\n'.reset);
} else {
throw e;
}
@@ -182,7 +182,7 @@ resetCommand
return options[x];
});
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();
}
@@ -206,13 +206,12 @@ program
.option('-s, --schema', 'Update NodeBB data store schema', false)
.option('-b, --build', 'Rebuild assets', false)
.on('--help', function () {
process.stdout.write(
'\n' +
'When running particular upgrade scripts, options are ignored.\n' +
'By default all options are enabled. Passing any options disables that default.\n' +
'Only package and dependency updates: ' + './nodebb upgrade -mi\n'.yellow +
'Only database update: ' + './nodebb upgrade -d\n\n'.yellow
);
console.log('\n' + [
'When running particular upgrade scripts, options are ignored.',
'By default all options are enabled. Passing any options disables that default.',
'Only package and dependency updates: ' + './nodebb upgrade -mi'.yellow,
'Only database update: ' + './nodebb upgrade -d'.yellow,
].join('\n'));
})
.action(function (scripts, options) {
require('./upgrade').upgrade(scripts.length ? scripts : true, options);
@@ -229,7 +228,7 @@ program
if (err) {
throw err;
}
process.stdout.write('OK\n'.green);
console.log('OK'.green);
process.exit();
});
});

View File

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

View File

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

View File

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

View File

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

View File

@@ -105,7 +105,7 @@ function getCurrentVersion(callback) {
function checkPlugins(standalone, callback) {
if (standalone) {
process.stdout.write('Checking installed plugins and themes for updates... ');
console.log('Checking installed plugins and themes for updates... ');
}
async.waterfall([
@@ -117,7 +117,7 @@ function checkPlugins(standalone, callback) {
var toCheck = Object.keys(payload.plugins);
if (!toCheck.length) {
process.stdout.write('OK'.green + '\n'.reset);
console.log('OK'.green + ''.reset);
return next(null, []); // no extraneous plugins installed
}
@@ -127,10 +127,10 @@ function checkPlugins(standalone, callback) {
json: true,
}, function (err, res, body) {
if (err) {
process.stdout.write('error'.red + '\n'.reset);
console.log('error'.red + ''.reset);
return next(err);
}
process.stdout.write('OK'.green + '\n'.reset);
console.log('OK'.green + ''.reset);
if (!Array.isArray(body) && toCheck.length === 1) {
body = [body];
@@ -167,19 +167,19 @@ function upgradePlugins(callback) {
checkPlugins(standalone, function (err, found) {
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);
}
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) {
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 {
if (standalone) {
process.stdout.write('\nAll packages up-to-date!'.green + '\n'.reset);
console.log('\nAll packages up-to-date!'.green + ''.reset);
}
return callback();
}
@@ -198,7 +198,7 @@ function upgradePlugins(callback) {
}
if (['y', 'Y', 'yes', 'YES'].indexOf(result.upgrade) !== -1) {
process.stdout.write('\nUpgrading packages...');
console.log('\nUpgrading packages...');
var args = ['i'];
found.forEach(function (suggestObj) {
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);
} 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();
}
});

View File

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