Skip to content

Node.js based forum software built for the modern web

#5211 run build step before tests

barisusaklie86db0463181
diff --git a/app.js b/app.js
index 57ba0e0000..b3fe8f0fc2 100644
--- a/app.js
+++ b/app.js
@@ -23,13 +23,12 @@
var nconf = require('nconf');
nconf.argv().env('__');
-var url = require('url'),
- async = require('async'),
- winston = require('winston'),
- colors = require('colors'),
- path = require('path'),
- pkg = require('./package.json'),
- file = require('./src/file');
+var url = require('url');
+var async = require('async');
+var winston = require('winston');
+var path = require('path');
+var pkg = require('./package.json');
+var file = require('./src/file');
global.env = process.env.NODE_ENV || 'production';
@@ -80,7 +79,7 @@ if (nconf.get('setup') || nconf.get('install')) {
} else if (nconf.get('plugins')) {
listPlugins();
} else if (nconf.get('build')) {
- build(nconf.get('build'));
+ require('./build').build(nconf.get('build'));
} else {
start();
}
@@ -159,7 +158,7 @@ function start() {
return;
}
var meta = require('./src/meta');
- var emitter = require('./src/emitter');
+
switch (message.action) {
case 'reload':
meta.reload();
@@ -239,6 +238,7 @@ function setup() {
winston.info('NodeBB Setup Triggered via Command Line');
var install = require('./src/install');
+ var build = require('./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');
@@ -247,7 +247,7 @@ function setup() {
async.series([
async.apply(install.setup),
async.apply(loadConfig),
- async.apply(build, true)
+ async.apply(build.build, true)
], function (err, data) {
// Disregard build step data
data = data[0];
@@ -280,100 +280,19 @@ function setup() {
process.exit();
});
-};
-
-function build(targets, callback) {
- var db = require('./src/database');
- var meta = require('./src/meta');
- var plugins = require('./src/plugins');
- var valid = ['js', 'clientCSS', 'acpCSS', 'tpl'];
- var step = function (target, next) {
- winston.info('[build] => Completed in ' + ((Date.now() - startTime) / 1000) + 's');
- next();
- };
- var startTime;
-
- targets = (targets === true ? valid : targets.split(',').filter(function (target) {
- return valid.indexOf(target) !== -1;
- }));
-
- if (!targets) {
- winston.error('[build] No valid build targets found. Aborting.');
- return process.exit(0);
- }
-
- async.series([
- async.apply(db.init),
- async.apply(meta.themes.setupPaths),
- async.apply(plugins.init, null, null)
- ], function (err) {
- if (err) {
- winston.error('[build] Encountered error preparing for build: ' + err.message);
- return process.exit(1);
- }
-
- // eachSeries because it potentially(tm) runs faster on Windows this way
- async.eachSeries(targets, function (target, next) {
- switch(target) {
- case 'js':
- winston.info('[build] Building javascript');
- startTime = Date.now();
- async.series([
- async.apply(meta.js.minify, 'nodebb.min.js'),
- async.apply(meta.js.minify, 'acp.min.js')
- ], step.bind(this, target, next));
- break;
-
- case 'clientCSS':
- winston.info('[build] Building client-side CSS');
- startTime = Date.now();
- meta.css.minify('stylesheet.css', step.bind(this, target, next));
- break;
-
- case 'acpCSS':
- winston.info('[build] Building admin control panel CSS');
- startTime = Date.now();
- meta.css.minify('admin.css', step.bind(this, target, next));
- break;
-
- case 'tpl':
- winston.info('[build] Building templates');
- startTime = Date.now();
- meta.templates.compile(step.bind(this, target, next));
- break;
-
- default:
- winston.warn('[build] Unknown build target: \'' + target + '\'');
- setImmediate(next);
- break;
- }
- }, function (err) {
- if (err) {
- winston.error('[build] Encountered error during build step: ' + err.message);
- return process.exit(1);
- }
-
- winston.info('[build] Asset compilation successful.');
-
- if (typeof callback === 'function') {
- callback();
- } else {
- process.exit(0);
- }
- });
- });
-};
+}
function upgrade() {
var db = require('./src/database');
var meta = require('./src/meta');
var upgrade = require('./src/upgrade');
+ var build = require('./build');
async.series([
async.apply(db.init),
async.apply(meta.configs.init),
async.apply(upgrade.upgrade),
- async.apply(build, true)
+ async.apply(build.build, true)
], function (err) {
if (err) {
winston.error(err.stack);
@@ -382,7 +301,7 @@ function upgrade() {
process.exit(0);
}
});
-};
+}
function activate() {
var db = require('./src/database');
diff --git a/build.js b/build.js
new file mode 100644
index 0000000000..96b7d7af26
--- /dev/null
+++ b/build.js
@@ -0,0 +1,91 @@
+'use strict';
+
+var async = require('async');
+var winston = require('winston');
+
+exports.build = function build(targets, callback) {
+ var db = require('./src/database');
+ var meta = require('./src/meta');
+ var plugins = require('./src/plugins');
+ var valid = ['js', 'clientCSS', 'acpCSS', 'tpl'];
+
+ targets = (targets === true ? valid : targets.split(',').filter(function (target) {
+ return valid.indexOf(target) !== -1;
+ }));
+
+ if (!targets) {
+ winston.error('[build] No valid build targets found. Aborting.');
+ return process.exit(0);
+ }
+
+ async.series([
+ async.apply(db.init),
+ async.apply(meta.themes.setupPaths),
+ async.apply(plugins.init, null, null)
+ ], function (err) {
+ if (err) {
+ winston.error('[build] Encountered error preparing for build: ' + err.message);
+ return process.exit(1);
+ }
+
+ exports.buildTargets(targets, callback);
+ });
+};
+
+exports.buildTargets = function (targets, callback) {
+ var meta = require('./src/meta');
+ var startTime;
+ var step = function (target, next) {
+ winston.info('[build] => Completed in ' + ((Date.now() - startTime) / 1000) + 's');
+ next();
+ };
+ // eachSeries because it potentially(tm) runs faster on Windows this way
+ async.eachSeries(targets, function (target, next) {
+ switch(target) {
+ case 'js':
+ winston.info('[build] Building javascript');
+ startTime = Date.now();
+ async.series([
+ async.apply(meta.js.minify, 'nodebb.min.js'),
+ async.apply(meta.js.minify, 'acp.min.js')
+ ], step.bind(this, target, next));
+ break;
+
+ case 'clientCSS':
+ winston.info('[build] Building client-side CSS');
+ startTime = Date.now();
+ meta.css.minify('stylesheet.css', step.bind(this, target, next));
+ break;
+
+ case 'acpCSS':
+ winston.info('[build] Building admin control panel CSS');
+ startTime = Date.now();
+ meta.css.minify('admin.css', step.bind(this, target, next));
+ break;
+
+ case 'tpl':
+ winston.info('[build] Building templates');
+ startTime = Date.now();
+ meta.templates.compile(step.bind(this, target, next));
+ break;
+
+ default:
+ winston.warn('[build] Unknown build target: \'' + target + '\'');
+ setImmediate(next);
+ break;
+ }
+ }, function (err) {
+ if (err) {
+ winston.error('[build] Encountered error during build step: ' + err.message);
+ return process.exit(1);
+ }
+
+ winston.info('[build] Asset compilation successful.');
+
+ if (typeof callback === 'function') {
+ callback();
+ } else {
+ process.exit(0);
+ }
+ });
+};
\ No newline at end of file
diff --git a/test/controllers.js b/test/controllers.js
index 5b5b1d7ce5..bdaa1e908d 100644
--- a/test/controllers.js
+++ b/test/controllers.js
@@ -553,7 +553,6 @@ describe('Controllers', function () {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert.equal(body, 'OK');
- console.log(err, res.statusCode, body);
done();
});
});
diff --git a/test/mocks/databasemock.js b/test/mocks/databasemock.js
index 1bc780a2cc..42c14ed2f7 100644
--- a/test/mocks/databasemock.js
+++ b/test/mocks/databasemock.js
@@ -126,9 +126,13 @@
nconf.set('upload_url', nconf.get('upload_path').replace(/^\/public/, ''));
nconf.set('core_templates_path', path.join(__dirname, '../../src/views'));
- nconf.set('base_templates_path', path.join(nconf.get('themes_path'), 'nodebb-theme-vanilla/templates'));
+ nconf.set('base_templates_path', path.join(nconf.get('themes_path'), 'nodebb-theme-persona/templates'));
nconf.set('theme_templates_path', meta.config['theme:templates'] ? path.join(nconf.get('themes_path'), meta.config['theme:id'], meta.config['theme:templates']) : nconf.get('base_templates_path'));
+ nconf.set('theme_config', path.join(nconf.get('themes_path'), 'nodebb-theme-persona', 'theme.json'));
+ require('../../build').buildTargets(['js', 'clientCSS', 'acpCSS', 'tpl'], next);
+ },
+ function (next) {
var webserver = require('../../src/webserver');
var sockets = require('../../src/socket.io');
sockets.init(webserver.server);