@ -39,13 +39,17 @@ var getRunningPid = function(callback) {
},
getCurrentVersion = function (callback) {
fs.readFile(path.join(__dirname, 'package.json'), { encoding: 'utf-8' }, function (err, pkg) {
if (err) {
return callback(err);
}
try {
pkg = JSON.parse(pkg);
return callback(null, pkg.version);
} catch(err) {
return callback(err);
}
})
});
},
fork = function (args) {
cproc.fork('app.js', args, {
@ -58,6 +62,10 @@ var getRunningPid = function(callback) {
files: async.apply(fs.readdir, path.join(__dirname, 'node_modules')),
deps: async.apply(fs.readFile, path.join(__dirname, 'package.json'), { encoding: 'utf-8' })
}, function (err, payload) {
if (err) {
return callback(err);
}
var isNbbModule = /^nodebb-(?:plugin|theme|widget|rewards)-[\w\-]+$/,
moduleName, isGitRepo;
@ -106,6 +114,10 @@ var getRunningPid = function(callback) {
async.eachLimit(modules, 50, function (module, next) {
fs.readFile(path.join(__dirname, 'node_modules/' + module + '/package.json'), { encoding: 'utf-8' }, function (err, pkg) {
if (err) {
return next(err);
}
try {
pkg = JSON.parse(pkg);
versionHash[module] = pkg.version;
@ -161,14 +173,14 @@ var getRunningPid = function(callback) {
name: suggestObj.package,
current: current,
suggested: suggested
}
};
} else {
return null;
}
}).filter(Boolean);
next(null, upgradable);
})
});
}
], callback);
},
@ -186,7 +198,7 @@ var getRunningPid = function(callback) {
}
if (found && found.length) {
process.stdout.write('\nA total of ' + new String(found.length).bold + ' package(s) can be upgraded:\n');
process.stdout.write('\nA total of ' + String(found.length).bold + ' package(s) can be upgraded:\n');
found.forEach(function (suggestObj) {
process.stdout.write(' * '.yellow + suggestObj.name.reset + ' (' + suggestObj.current.yellow + ' -> '.reset + suggestObj.suggested.green + ')\n'.reset);
});
@ -207,6 +219,10 @@ var getRunningPid = function(callback) {
description: 'Proceed with upgrade (y|n)?'.reset,
type: 'string'
}, function (err, result) {
if (err) {
return callback(err);
}
if (['y', 'Y', 'yes', 'YES'].indexOf(result.upgrade) !== -1) {
process.stdout.write('\nUpgrading packages...');
var args = ['npm', 'i'];
@ -225,7 +241,7 @@ var getRunningPid = function(callback) {
process.stdout.write('\nPackage upgrades skipped'.yellow + '. Check for upgrades at any time by running "'.reset + './nodebb upgrade-plugins'.green + '".\n'.reset);
callback();
}
})
});
});
};
@ -241,7 +257,7 @@ switch(process.argv[2]) {
process.stdout.write('\nNodeBB is not running\n'.bold);
process.stdout.write('\t"' + './nodebb start'.yellow + '" to launch the NodeBB server\n\n'.reset);
}
})
});
break;
case 'start':
@ -256,11 +272,26 @@ switch(process.argv[2]) {
});
break;
case 'slog':
process.stdout.write('\nStarting NodeBB with logging output\n'.bold);
process.stdout.write('\nHit '.red + 'Ctrl-C '.bold + 'to exit'.red);
process.stdout.write('\n\n'.reset);
// Spawn a new NodeBB process
cproc.fork(__dirname + '/loader.js', {
env: process.env
});
cproc.spawn('tail', ['-F', './logs/output.log'], {
cwd: __dirname,
stdio: 'inherit'
});
break;
case 'stop':
getRunningPid(function (err, pid) {
if (!err) {
process.kill(pid, 'SIGTERM');
process.stdout.write('Stopping NodeBB. Goodbye!\n')
process.stdout.write('Stopping NodeBB. Goodbye!\n');
} else {
process.stdout.write('NodeBB is already stopped.\n');
}
@ -296,7 +327,7 @@ switch(process.argv[2]) {
break;
case 'log':
process.stdout.write('\nType '.red + 'Ctrl-C '.bold + 'to exit'.red);
process.stdout.write('\nHit '.red + 'Ctrl-C '.bold + 'to exit'.red);
process.stdout.write('\n\n'.reset);
cproc.spawn('tail', ['-F', './logs/output.log'], {
cwd: __dirname,
@ -319,7 +350,7 @@ switch(process.argv[2]) {
case 'activate':
var args = process.argv.slice(0);
args.unshift('--activate');
args.unshift('--activate= ' + process.argv[3] );
fork(args);
break;
@ -351,7 +382,7 @@ switch(process.argv[2]) {
silent: false
});
upgradeProc.on('close', next)
upgradeProc.on('close', next);
}
], function (err) {
if (err) {
@ -371,17 +402,18 @@ switch(process.argv[2]) {
default:
process.stdout.write('\nWelcome to NodeBB\n\n'.bold);
process.stdout.write('Usage: ./nodebb {start|stop|reload|restart|log|setup|reset|upgrade|dev}\n\n');
process.stdout.write('\t' + 'start'.yellow + '\tStart the NodeBB server\n');
process.stdout.write('\t' + 'stop'.yellow + '\tStops the NodeBB server\n');
process.stdout.write('\t' + 'reload'.yellow + '\tRestarts NodeBB\n');
process.stdout.write('\t' + 'restart'.yellow + '\tRestarts NodeBB\n');
process.stdout.write('\t' + 'log'.yellow + '\tOpens the logging interface (useful for debugging)\n');
process.stdout.write('\t' + 'setup'.yellow + '\tRuns the NodeBB setup script\n');
process.stdout.write('\t' + 'reset'.yellow + '\tDisables all plugins, restores the default theme.\n');
process.stdout.write('\t' + 'activate'.yellow + '\tActivate a plugin on start up.\n');
process.stdout.write('\t' + 'plugins'.yellow + '\tList all plugins that have been installed.\n');
process.stdout.write('\t' + 'upgrade'.yellow + '\tRun NodeBB upgrade scripts, ensure packages are up-to-date\n');
process.stdout.write('\t' + 'dev'.yellow + '\tStart NodeBB in interactive development mode\n');
process.stdout.write('\t' + 'start'.yellow + '\t\tStart the NodeBB server\n');
process.stdout.write('\t' + 'slog'.yellow + '\t\tStarts the NodeBB server and displays the live output log\n');
process.stdout.write('\t' + 'stop'.yellow + '\t\tStops the NodeBB server\n');
process.stdout.write('\t' + 'reload'.yellow + '\t\tRestarts NodeBB\n');
process.stdout.write('\t' + 'restart'.yellow + '\t\tRestarts NodeBB\n');
process.stdout.write('\t' + 'log'.yellow + '\t\tOpens the logging interface (useful for debugging)\n');
process.stdout.write('\t' + 'setup'.yellow + '\t\tRuns the NodeBB setup script\n');
process.stdout.write('\t' + 'reset'.yellow + '\t\tDisables all plugins, restores the default theme.\n');
process.stdout.write('\t' + 'activate'.yellow + '\tActivates a plugin for the next startup of NodeBB.\n');
process.stdout.write('\t' + 'plugins'.yellow + '\t\tList all plugins that have been installed.\n');
process.stdout.write('\t' + 'upgrade'.yellow + '\t\tRun NodeBB upgrade scripts, ensure packages are up-to-date\n');
process.stdout.write('\t' + 'dev'.yellow + '\t\tStart NodeBB in interactive development mode\n');
process.stdout.write('\n'.reset);
break;
}