Files
NodeBB/Gruntfile.js

146 lines
3.3 KiB
JavaScript
Raw Normal View History

2017-02-18 01:56:23 -07:00
'use strict';
2017-02-17 20:20:42 -07:00
var fork = require('child_process').fork;
var env = process.env;
var worker;
var updateWorker;
var incomplete = [];
var running = 0;
module.exports = function (grunt) {
2016-04-18 10:59:55 -04:00
var args = [];
if (!grunt.option('verbose')) {
args.push('--log-level=info');
}
2015-02-24 18:16:51 -05:00
function update(action, filepath, target) {
2017-02-17 20:20:42 -07:00
var updateArgs = args.slice();
var compiling = '';
var time = Date.now();
2017-02-18 01:27:46 -07:00
if (target === 'lessUpdated_Client') {
compiling = 'clientCSS';
} else if (target === 'lessUpdated_Admin') {
compiling = 'acpCSS';
2015-02-24 15:34:05 -05:00
} else if (target === 'clientUpdated') {
compiling = 'js';
2015-02-24 15:46:37 -05:00
} else if (target === 'templatesUpdated') {
compiling = 'tpl';
2017-01-17 20:22:38 -07:00
} else if (target === 'langUpdated') {
compiling = 'lang';
2015-02-24 15:34:05 -05:00
} else if (target === 'serverUpdated') {
// Do nothing, just restart
2015-02-24 15:34:05 -05:00
}
if (incomplete.indexOf(compiling) === -1) {
incomplete.push(compiling);
}
updateArgs.push('--build');
updateArgs.push(incomplete.join(','));
2015-02-24 15:34:05 -05:00
worker.kill();
if (updateWorker) {
updateWorker.kill('SIGKILL');
}
updateWorker = fork('app.js', updateArgs, { env: env });
running += 1;
updateWorker.on('exit', function () {
running -= 1;
if (running === 0) {
worker = fork('app.js', args, { env: env });
worker.on('message', function () {
if (incomplete.length) {
incomplete = [];
2015-02-24 18:22:38 -05:00
if (grunt.option('verbose')) {
grunt.log.writeln('NodeBB restarted in ' + (Date.now() - time) + ' ms');
}
}
});
2015-02-24 18:05:00 -05:00
}
2015-02-24 15:34:05 -05:00
});
2015-02-24 18:16:51 -05:00
}
grunt.initConfig({
watch: {
lessUpdated_Client: {
files: [
'public/*.less',
'node_modules/nodebb-*/*.less', 'node_modules/nodebb-*/**/*.less',
2016-03-29 14:37:40 -04:00
'!node_modules/nodebb-*/node_modules/**',
2017-02-17 19:31:21 -07:00
'!node_modules/nodebb-*/.git/**',
],
options: {
2017-02-17 19:31:21 -07:00
interval: 1000,
},
},
lessUpdated_Admin: {
files: ['public/**/*.less'],
options: {
2017-02-17 19:31:21 -07:00
interval: 1000,
},
2015-02-24 18:16:51 -05:00
},
clientUpdated: {
files: [
'public/src/**/*.js',
'node_modules/nodebb-*/*.js', 'node_modules/nodebb-*/**/*.js',
'!node_modules/nodebb-*/node_modules/**',
2016-03-29 14:37:40 -04:00
'node_modules/templates.js/lib/templates.js',
2017-02-17 19:31:21 -07:00
'!node_modules/nodebb-*/.git/**',
],
options: {
2017-02-17 19:31:21 -07:00
interval: 1000,
},
2015-02-24 18:16:51 -05:00
},
serverUpdated: {
files: ['*.js', 'install/*.js', 'src/**/*.js'],
options: {
2017-02-17 19:31:21 -07:00
interval: 1000,
},
2015-02-24 18:16:51 -05:00
},
templatesUpdated: {
files: [
'src/views/**/*.tpl',
'node_modules/nodebb-*/*.tpl', 'node_modules/nodebb-*/**/*.tpl',
2016-03-29 14:37:40 -04:00
'!node_modules/nodebb-*/node_modules/**',
2017-02-17 19:31:21 -07:00
'!node_modules/nodebb-*/.git/**',
],
options: {
2017-02-17 19:31:21 -07:00
interval: 1000,
},
2017-01-17 20:22:38 -07:00
},
langUpdated: {
files: [
'public/language/en-GB/*.json',
'public/language/en-GB/**/*.json',
2017-01-17 20:22:38 -07:00
'node_modules/nodebb-*/**/*.json',
'!node_modules/nodebb-*/node_modules/**',
'!node_modules/nodebb-*/.git/**',
2017-01-19 10:53:25 -07:00
'!node_modules/nodebb-*/plugin.json',
'!node_modules/nodebb-*/package.json',
'!node_modules/nodebb-*/theme.json',
2017-01-17 20:22:38 -07:00
],
options: {
2017-02-17 19:31:21 -07:00
interval: 1000,
},
2017-01-17 20:22:38 -07:00
},
2017-02-17 19:31:21 -07:00
},
2015-02-24 15:34:05 -05:00
});
2015-02-24 18:16:51 -05:00
grunt.loadNpmTasks('grunt-contrib-watch');
if (grunt.option('skip')) {
grunt.registerTask('default', ['watch:serverUpdated']);
} else {
grunt.registerTask('default', ['watch']);
}
2017-02-18 01:27:46 -07:00
2015-02-24 18:16:51 -05:00
env.NODE_ENV = 'development';
2016-04-18 10:59:55 -04:00
worker = fork('app.js', args, { env: env });
2015-02-24 18:16:51 -05:00
grunt.event.on('watch', update);
2017-02-18 02:30:48 -07:00
};