Files
NodeBB/Gruntfile.js

106 lines
2.5 KiB
JavaScript
Raw Normal View History

"use strict";
var fork = require('child_process').fork,
env = process.env,
2015-02-24 18:16:51 -05:00
worker,
incomplete = [];
2015-01-30 13:06:04 -05:00
module.exports = function(grunt) {
2015-02-24 18:16:51 -05:00
function update(action, filepath, target) {
2015-02-24 18:22:38 -05:00
var args = [],
fromFile = '',
2015-02-24 18:05:00 -05:00
compiling = '',
time = Date.now();
2015-02-24 18:22:38 -05:00
2015-02-24 18:24:00 -05:00
if (!grunt.option('verbose')) {
2015-02-24 18:22:38 -05:00
args.push('--log-level=info');
}
2015-02-24 15:34:05 -05:00
if (target === 'lessUpdated_Client') {
fromFile = ['js', 'tpl', 'acpLess'];
compiling = 'clientLess';
} else if (target === 'lessUpdated_Admin') {
fromFile = ['js', 'tpl', 'clientLess'];
compiling = 'acpLess';
2015-02-24 15:34:05 -05:00
} else if (target === 'clientUpdated') {
fromFile = ['clientLess', 'acpLess', 'tpl'];
compiling = 'js';
2015-02-24 15:46:37 -05:00
} else if (target === 'templatesUpdated') {
fromFile = ['js', 'clientLess', 'acpLess'];
compiling = 'tpl';
2015-02-24 15:34:05 -05:00
} else if (target === 'serverUpdated') {
fromFile = ['clientLess', 'acpLess', 'js', 'tpl'];
2015-02-24 15:34:05 -05:00
}
fromFile = fromFile.filter(function(ext) {
return incomplete.indexOf(ext) === -1;
});
args.push('--from-file=' + fromFile.join(','));
incomplete.push(compiling);
2015-02-24 15:34:05 -05:00
worker.kill();
worker = fork('app.js', args, { env: env });
worker.on('message', function() {
2015-02-24 18:05:00 -05:00
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/**',
'!node_modules/nodebb-*/.git/**'
]
},
lessUpdated_Admin: {
files: ['public/**/*.less']
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',
'!node_modules/nodebb-*/.git/**'
]
2015-02-24 18:16:51 -05:00
},
serverUpdated: {
2015-04-21 14:52:57 -04:00
files: ['*.js', 'install/*.js', 'src/**/*.js']
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/**',
'!node_modules/nodebb-*/.git/**'
]
2015-02-24 18:16:51 -05: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']);
}
2015-02-24 18:16:51 -05:00
env.NODE_ENV = 'development';
worker = fork('app.js', [], { env: env });
grunt.event.on('watch', update);
2015-01-30 13:06:04 -05:00
};