Files
NodeBB/Gruntfile.js
Julian Lam e1323c0295 Updated js code so vendors can be added to the modules folder, so
they can be required properly and we can finally get rid of that
really annoying "mismatched anonymous" error in Require.js.

First module to make the transition: Chart.js
2016-02-26 11:29:17 -05:00

84 lines
2.2 KiB
JavaScript

"use strict";
var fork = require('child_process').fork,
env = process.env,
worker,
incomplete = [];
module.exports = function(grunt) {
function update(action, filepath, target) {
var args = [],
fromFile = '',
compiling = '',
time = Date.now();
if (!grunt.option('verbose')) {
args.push('--log-level=info');
}
if (target === 'lessUpdated') {
fromFile = ['js','tpl'];
compiling = 'less';
} else if (target === 'clientUpdated') {
fromFile = ['less','tpl'];
compiling = 'js';
} else if (target === 'templatesUpdated') {
fromFile = ['js','less'];
compiling = 'tpl';
} else if (target === 'serverUpdated') {
fromFile = ['less','js','tpl'];
}
fromFile = fromFile.filter(function(ext) {
return incomplete.indexOf(ext) === -1;
});
args.push('--from-file=' + fromFile.join(','));
incomplete.push(compiling);
worker.kill();
worker = fork('app.js', args, { env: env });
worker.on('message', function() {
if (incomplete.length) {
incomplete = [];
if (grunt.option('verbose')) {
grunt.log.writeln('NodeBB restarted in ' + (Date.now() - time) + ' ms');
}
}
});
}
grunt.initConfig({
watch: {
lessUpdated: {
files: ['public/**/*.less', 'node_modules/nodebb-*/*.less', 'node_modules/nodebb-*/*/*.less', 'node_modules/nodebb-*/*/*/*.less', 'node_modules/nodebb-*/*/*/*/*.less']
},
clientUpdated: {
files: ['public/src/**/*.js', '!public/src/modules/*.js', 'node_modules/nodebb-*/*.js', 'node_modules/nodebb-*/*/*.js', 'node_modules/nodebb-*/*/*/*.js', 'node_modules/nodebb-*/*/*/*/*.js', 'node_modules/templates.js/lib/templates.js']
},
serverUpdated: {
files: ['*.js', 'install/*.js', 'src/**/*.js']
},
templatesUpdated: {
files: ['src/views/**/*.tpl', 'node_modules/nodebb-*/*.tpl', 'node_modules/nodebb-*/*/*.tpl', 'node_modules/nodebb-*/*/*/*.tpl', 'node_modules/nodebb-*/*/*/*/*.tpl', 'node_modules/nodebb-*/*/*/*/*/*.tpl']
}
}
});
grunt.loadNpmTasks('grunt-contrib-watch');
if (grunt.option('skip')) {
grunt.registerTask('default', ['watch:serverUpdated']);
} else {
grunt.registerTask('default', ['watch']);
}
env.NODE_ENV = 'development';
worker = fork('app.js', [], { env: env });
grunt.event.on('watch', update);
};