mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 06:25:50 +01:00
Refactor nodebb, move build.js, add --dev
This commit is contained in:
8
app.js
8
app.js
@@ -75,7 +75,7 @@ if (nconf.get('setup') || nconf.get('install')) {
|
||||
} else if (nconf.get('reset')) {
|
||||
async.waterfall([
|
||||
async.apply(require('./src/reset').reset),
|
||||
async.apply(require('./build').buildAll)
|
||||
async.apply(require('./src/meta/build').buildAll)
|
||||
], function (err) {
|
||||
process.exit(err ? 1 : 0);
|
||||
});
|
||||
@@ -84,7 +84,7 @@ if (nconf.get('setup') || nconf.get('install')) {
|
||||
} else if (nconf.get('plugins')) {
|
||||
listPlugins();
|
||||
} else if (nconf.get('build')) {
|
||||
require('./build').build(nconf.get('build'));
|
||||
require('./src/meta/build').build(nconf.get('build'));
|
||||
} else {
|
||||
require('./src/start').start();
|
||||
}
|
||||
@@ -126,7 +126,7 @@ function setup() {
|
||||
winston.info('NodeBB Setup Triggered via Command Line');
|
||||
|
||||
var install = require('./src/install');
|
||||
var build = require('./build');
|
||||
var build = require('./src/meta/build');
|
||||
|
||||
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');
|
||||
@@ -174,7 +174,7 @@ function upgrade() {
|
||||
var db = require('./src/database');
|
||||
var meta = require('./src/meta');
|
||||
var upgrade = require('./src/upgrade');
|
||||
var build = require('./build');
|
||||
var build = require('./src/meta/build');
|
||||
|
||||
async.series([
|
||||
async.apply(db.init),
|
||||
|
||||
339
nodebb
339
nodebb
@@ -1,15 +1,17 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
try {
|
||||
var colors = require('colors'),
|
||||
cproc = require('child_process'),
|
||||
argv = require('minimist')(process.argv.slice(2)),
|
||||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
request = require('request'),
|
||||
semver = require('semver'),
|
||||
prompt = require('prompt'),
|
||||
async = require('async');
|
||||
require('colors');
|
||||
var cproc = require('child_process');
|
||||
var args = require('minimist')(process.argv.slice(2));
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var request = require('request');
|
||||
var semver = require('semver');
|
||||
var prompt = require('prompt');
|
||||
var 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');
|
||||
@@ -21,7 +23,11 @@ try {
|
||||
}
|
||||
}
|
||||
|
||||
var getRunningPid = function (callback) {
|
||||
if (args.dev) {
|
||||
process.env.NODE_ENV = 'development';
|
||||
}
|
||||
|
||||
function getRunningPid(callback) {
|
||||
fs.readFile(__dirname + '/pidfile', {
|
||||
encoding: 'utf-8'
|
||||
}, function (err, pid) {
|
||||
@@ -36,8 +42,8 @@ var getRunningPid = function (callback) {
|
||||
callback(e);
|
||||
}
|
||||
});
|
||||
},
|
||||
getCurrentVersion = function (callback) {
|
||||
}
|
||||
function getCurrentVersion(callback) {
|
||||
fs.readFile(path.join(__dirname, 'package.json'), { encoding: 'utf-8' }, function (err, pkg) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -50,14 +56,14 @@ var getRunningPid = function (callback) {
|
||||
return callback(err);
|
||||
}
|
||||
});
|
||||
},
|
||||
fork = function (args) {
|
||||
cproc.fork('app.js', args, {
|
||||
}
|
||||
function fork(args) {
|
||||
return cproc.fork('app.js', args, {
|
||||
cwd: __dirname,
|
||||
silent: false
|
||||
});
|
||||
},
|
||||
getInstalledPlugins = function (callback) {
|
||||
}
|
||||
function getInstalledPlugins(callback) {
|
||||
async.parallel({
|
||||
files: async.apply(fs.readdir, path.join(__dirname, 'node_modules')),
|
||||
deps: async.apply(fs.readFile, path.join(__dirname, 'package.json'), { encoding: 'utf-8' })
|
||||
@@ -97,10 +103,10 @@ var getRunningPid = function (callback) {
|
||||
}
|
||||
|
||||
if (
|
||||
payload.files.indexOf(moduleName) !== -1 // found in `node_modules/`
|
||||
&& payload.bundled.indexOf(moduleName) === -1 // not found in `package.json`
|
||||
&& !fs.lstatSync(path.join(__dirname, 'node_modules/' + moduleName)).isSymbolicLink() // is not a symlink
|
||||
&& !isGitRepo // .git/ does not exist, so it is not a git repository
|
||||
payload.files.indexOf(moduleName) !== -1 && // found in `node_modules/`
|
||||
payload.bundled.indexOf(moduleName) === -1 && // not found in `package.json`
|
||||
!fs.lstatSync(path.join(__dirname, 'node_modules/' + moduleName)).isSymbolicLink() && // is not a symlink
|
||||
!isGitRepo // .git/ does not exist, so it is not a git repository
|
||||
) {
|
||||
payload.installed.push(moduleName);
|
||||
}
|
||||
@@ -108,8 +114,8 @@ var getRunningPid = function (callback) {
|
||||
|
||||
getModuleVersions(payload.installed, callback);
|
||||
});
|
||||
},
|
||||
getModuleVersions = function (modules, callback) {
|
||||
}
|
||||
function getModuleVersions(modules, callback) {
|
||||
var versionHash = {};
|
||||
|
||||
async.eachLimit(modules, 50, function (module, next) {
|
||||
@@ -129,8 +135,8 @@ var getRunningPid = function (callback) {
|
||||
}, function (err) {
|
||||
callback(err, versionHash);
|
||||
});
|
||||
},
|
||||
checkPlugins = function (standalone, callback) {
|
||||
}
|
||||
function checkPlugins(standalone, callback) {
|
||||
if (standalone) {
|
||||
process.stdout.write('Checking installed plugins and themes for updates... ');
|
||||
}
|
||||
@@ -183,13 +189,13 @@ var getRunningPid = function (callback) {
|
||||
});
|
||||
}
|
||||
], callback);
|
||||
},
|
||||
upgradePlugins = function (callback) {
|
||||
}
|
||||
function upgradePlugins(callback) {
|
||||
var standalone = false;
|
||||
if (typeof callback !== 'function') {
|
||||
callback = function () {};
|
||||
standalone = true;
|
||||
};
|
||||
}
|
||||
|
||||
checkPlugins(standalone, function (err, found) {
|
||||
if (err) {
|
||||
@@ -243,10 +249,13 @@ var getRunningPid = function (callback) {
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
switch(process.argv[2]) {
|
||||
case 'status':
|
||||
var commands = {
|
||||
status: {
|
||||
description: 'View the status of the NodeBB server',
|
||||
usage: 'Usage: ' + './nodebb status'.yellow,
|
||||
handler: function () {
|
||||
getRunningPid(function (err, pid) {
|
||||
if (!err) {
|
||||
process.stdout.write('\nNodeBB Running '.bold + '(pid '.cyan + pid.toString().cyan + ')\n'.cyan);
|
||||
@@ -258,9 +267,12 @@ switch(process.argv[2]) {
|
||||
process.stdout.write('\t"' + './nodebb start'.yellow + '" to launch the NodeBB server\n\n'.reset);
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
case 'start':
|
||||
},
|
||||
},
|
||||
start: {
|
||||
description: 'Start the NodeBB server',
|
||||
usage: 'Usage: ' + './nodebb start'.yellow,
|
||||
handler: function () {
|
||||
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');
|
||||
@@ -270,9 +282,52 @@ switch(process.argv[2]) {
|
||||
cproc.fork(__dirname + '/loader.js', {
|
||||
env: process.env
|
||||
});
|
||||
break;
|
||||
|
||||
case 'slog':
|
||||
},
|
||||
},
|
||||
stop: {
|
||||
description: 'Stop the NodeBB server',
|
||||
usage: 'Usage: ' + './nodebb stop'.yellow,
|
||||
handler: function () {
|
||||
getRunningPid(function (err, pid) {
|
||||
if (!err) {
|
||||
process.kill(pid, 'SIGTERM');
|
||||
process.stdout.write('Stopping NodeBB. Goodbye!\n');
|
||||
} else {
|
||||
process.stdout.write('NodeBB is already stopped.\n');
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
restart: {
|
||||
description: 'Restart the NodeBB server',
|
||||
usage: 'Usage: ' + './nodebb restart'.yellow,
|
||||
handler: function () {
|
||||
getRunningPid(function (err, pid) {
|
||||
if (!err) {
|
||||
process.kill(pid, 'SIGHUP');
|
||||
process.stdout.write('\nRestarting NodeBB\n'.bold);
|
||||
} else {
|
||||
process.stdout.write('NodeBB could not be restarted, as a running instance could not be found.\n');
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
log: {
|
||||
description: 'Open the output log (useful for debugging)',
|
||||
usage: 'Usage: ' + './nodebb log'.yellow,
|
||||
handler: function () {
|
||||
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,
|
||||
stdio: 'inherit'
|
||||
});
|
||||
},
|
||||
},
|
||||
slog: {
|
||||
description: 'Start the NodeBB server and view the live output log',
|
||||
usage: 'Usage: ' + './nodebb slog'.yellow,
|
||||
handler: function () {
|
||||
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);
|
||||
@@ -285,93 +340,72 @@ switch(process.argv[2]) {
|
||||
cwd: __dirname,
|
||||
stdio: 'inherit'
|
||||
});
|
||||
break;
|
||||
|
||||
case 'stop':
|
||||
getRunningPid(function (err, pid) {
|
||||
if (!err) {
|
||||
process.kill(pid, 'SIGTERM');
|
||||
process.stdout.write('Stopping NodeBB. Goodbye!\n');
|
||||
} else {
|
||||
process.stdout.write('NodeBB is already stopped.\n');
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
case 'restart':
|
||||
getRunningPid(function (err, pid) {
|
||||
if (!err) {
|
||||
process.kill(pid, 'SIGHUP');
|
||||
process.stdout.write('\nRestarting NodeBB\n'.bold);
|
||||
} else {
|
||||
process.stdout.write('NodeBB could not be restarted, as a running instance could not be found.\n');
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
case 'reload':
|
||||
getRunningPid(function (err, pid) {
|
||||
if (!err) {
|
||||
process.kill(pid, 'SIGUSR2');
|
||||
} else {
|
||||
process.stdout.write('NodeBB could not be reloaded, as a running instance could not be found.\n');
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
case 'dev':
|
||||
},
|
||||
},
|
||||
dev: {
|
||||
description: 'Start NodeBB in verbose development mode',
|
||||
usage: 'Usage: ' + './nodebb dev'.yellow,
|
||||
handler: function () {
|
||||
process.env.NODE_ENV = 'development';
|
||||
cproc.fork(__dirname + '/loader.js', ['--no-daemon', '--no-silent'], {
|
||||
env: process.env
|
||||
});
|
||||
break;
|
||||
|
||||
case 'log':
|
||||
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,
|
||||
stdio: 'inherit'
|
||||
});
|
||||
break;
|
||||
|
||||
case 'build':
|
||||
var args = process.argv.slice(0);
|
||||
args[2] = '--' + args[2];
|
||||
|
||||
fork(args);
|
||||
break;
|
||||
|
||||
case 'setup':
|
||||
cproc.fork('app.js', ['--setup'], {
|
||||
cwd: __dirname,
|
||||
silent: false
|
||||
});
|
||||
break;
|
||||
|
||||
case 'reset':
|
||||
var args = process.argv.slice(0);
|
||||
args.unshift('--reset');
|
||||
fork(args);
|
||||
break;
|
||||
|
||||
case 'activate':
|
||||
var args = process.argv.slice(0);
|
||||
args.unshift('--activate=' + process.argv[3]);
|
||||
fork(args);
|
||||
break;
|
||||
|
||||
case 'plugins':
|
||||
var args = process.argv.slice(0);
|
||||
args.unshift('--plugins');
|
||||
fork(args);
|
||||
break;
|
||||
|
||||
case 'upgrade-plugins':
|
||||
upgradePlugins();
|
||||
break;
|
||||
|
||||
case 'upgrade':
|
||||
},
|
||||
},
|
||||
build: {
|
||||
description: 'Compile static assets (CSS, Javascript, etc)',
|
||||
usage: 'Usage: ' + './nodebb build'.yellow + ' [js,clientCSS,acpCSS,tpl,lang]'.red + '\n' +
|
||||
' e.g. ' + './nodebb build js,tpl'.yellow + '\tbuilds JS and templates\n' +
|
||||
' ' + './nodebb build'.yellow + '\t\tbuilds all targets\n',
|
||||
handler: function () {
|
||||
var arr = ['--build'].concat(process.argv.slice(3));
|
||||
fork(arr);
|
||||
},
|
||||
},
|
||||
setup: {
|
||||
description: 'Run the NodeBB setup script',
|
||||
usage: 'Usage: ' + './nodebb setup'.yellow,
|
||||
handler: function () {
|
||||
var arr = ['--setup'].concat(process.argv.slice(3));
|
||||
fork(arr);
|
||||
},
|
||||
},
|
||||
reset: {
|
||||
description: 'Disable plugins and restore the default theme',
|
||||
usage: 'Usage: ' + './nodebb reset '.yellow + '{-t|-p|-w|-s|-a}'.red + '\n' +
|
||||
' -t <theme>\tuse specified theme\n' +
|
||||
' -p <plugin>\tdisable specified plugin\n' +
|
||||
'\n' +
|
||||
' -t\t\tuse default theme\n' +
|
||||
' -p\t\tdisable all but core plugins\n' +
|
||||
' -w\t\twidgets\n' +
|
||||
' -s\t\tsettings\n' +
|
||||
' -a\t\tall of the above\n',
|
||||
handler: function () {
|
||||
var arr = ['--reset'].concat(process.argv.slice(3));
|
||||
fork(arr);
|
||||
},
|
||||
},
|
||||
activate: {
|
||||
description: 'Activate a plugin for the next startup of NodeBB',
|
||||
usage: 'Usage: ' + './nodebb activate <plugin>'.yellow,
|
||||
handler: function () {
|
||||
var arr = ['--activate=' + args._[1]].concat(process.argv.slice(4));
|
||||
fork(arr);
|
||||
},
|
||||
},
|
||||
plugins: {
|
||||
description: 'List all installed plugins',
|
||||
usage: 'Usage: ' + './nodebb plugins'.yellow,
|
||||
handler: function () {
|
||||
var arr = ['--plugins'].concat(process.argv.slice(3));
|
||||
fork(arr);
|
||||
},
|
||||
},
|
||||
upgrade: {
|
||||
description: 'Run NodeBB upgrade scripts, ensure packages are up-to-date',
|
||||
usage: 'Usage: ' + './nodebb upgrade'.yellow,
|
||||
handler: function () {
|
||||
async.series([
|
||||
function (next) {
|
||||
process.stdout.write('1. '.bold + 'Bringing base dependencies up to date... '.yellow);
|
||||
@@ -384,10 +418,8 @@ switch(process.argv[2]) {
|
||||
},
|
||||
function (next) {
|
||||
process.stdout.write('3. '.bold + 'Updating NodeBB data store schema...\n'.yellow);
|
||||
var upgradeProc = cproc.fork('app.js', ['--upgrade'], {
|
||||
cwd: __dirname,
|
||||
silent: false
|
||||
});
|
||||
var arr = ['--upgrade'].concat(process.argv.slice(3));
|
||||
var upgradeProc = fork(arr);
|
||||
|
||||
upgradeProc.on('close', next);
|
||||
}
|
||||
@@ -404,24 +436,47 @@ switch(process.argv[2]) {
|
||||
process.stdout.write('\n' + spaces + message.green.bold + '\n\n'.reset);
|
||||
}
|
||||
});
|
||||
break;
|
||||
},
|
||||
},
|
||||
upgradePlugins: {
|
||||
hidden: true,
|
||||
description: '',
|
||||
handler: function () {
|
||||
upgradePlugins();
|
||||
},
|
||||
},
|
||||
help: {
|
||||
description: 'Display the help message for a given command',
|
||||
usage: 'Usage: ' + './nodebb help <command>'.yellow,
|
||||
handler: function () {
|
||||
var command = commands[args._[1]];
|
||||
if (command) {
|
||||
process.stdout.write(command.description + '\n'.reset);
|
||||
process.stdout.write(command.usage + '\n'.reset);
|
||||
|
||||
return;
|
||||
}
|
||||
var keys = Object.keys(commands).filter(function (key) {
|
||||
return !commands[key].hidden;
|
||||
});
|
||||
|
||||
default:
|
||||
process.stdout.write('\nWelcome to NodeBB\n\n'.bold);
|
||||
process.stdout.write('Usage: ./nodebb {start|slog|stop|reload|restart|log|build|setup|reset|upgrade|dev}\n\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' + 'build'.yellow + '\t\tCompiles javascript, css stylesheets, and templates\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;
|
||||
process.stdout.write('Usage: ./nodebb {' + keys.join('|') + '}\n\n');
|
||||
|
||||
var usage = keys.map(function (key) {
|
||||
var line = '\t' + key.yellow + (key.length < 8 ? '\t\t' : '\t');
|
||||
return line + commands[key].description;
|
||||
}).join('\n');
|
||||
|
||||
process.stdout.write(usage + '\n'.reset);
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
commands['upgrade-plugins'] = commands.upgradePlugins;
|
||||
|
||||
if (!commands[args._[0]]) {
|
||||
commands.help.handler();
|
||||
} else {
|
||||
commands[args._[0]].handler();
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
"scripts": {
|
||||
"start": "node loader.js",
|
||||
"lint": "eslint --cache .",
|
||||
"pretest": "npm run lint",
|
||||
"pretest": "npm run lint && node app --build",
|
||||
"test": "istanbul cover node_modules/mocha/bin/_mocha -- -R dot",
|
||||
"coveralls": "istanbul cover _mocha --report lcovonly -- -R dot && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
|
||||
},
|
||||
|
||||
@@ -14,9 +14,9 @@ exports.buildAll = function (callback) {
|
||||
exports.build = function build(targets, callback) {
|
||||
buildStart = Date.now();
|
||||
|
||||
var db = require('./src/database');
|
||||
var meta = require('./src/meta');
|
||||
var plugins = require('./src/plugins');
|
||||
var db = require('../database');
|
||||
var meta = require('../meta');
|
||||
var plugins = require('../plugins');
|
||||
|
||||
|
||||
targets = (targets === true ? valid : targets.split(',').filter(function (target) {
|
||||
@@ -43,7 +43,7 @@ exports.build = function build(targets, callback) {
|
||||
};
|
||||
|
||||
exports.buildTargets = function (targets, callback) {
|
||||
var meta = require('./src/meta');
|
||||
var meta = require('../meta');
|
||||
buildStart = buildStart || Date.now();
|
||||
|
||||
var step = function (startTime, target, next) {
|
||||
@@ -57,7 +57,7 @@ SocketAdmin.reload = function (socket, data, callback) {
|
||||
};
|
||||
|
||||
SocketAdmin.restart = function (socket, data, callback) {
|
||||
require('../../build').buildAll(function (err) {
|
||||
require('../meta/build').buildAll(function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@
|
||||
nconf.set('theme_config', path.join(nconf.get('themes_path'), 'nodebb-theme-persona', 'theme.json'));
|
||||
nconf.set('bcrypt_rounds', 1);
|
||||
|
||||
require('../../build').buildTargets(['js', 'clientCSS', 'acpCSS', 'tpl'], next);
|
||||
next();
|
||||
},
|
||||
function (next) {
|
||||
var webserver = require('../../src/webserver');
|
||||
|
||||
Reference in New Issue
Block a user