Update gruntfile to build on initialization (#5458)

* Update gruntfile to build on initialization

* Skip option skips build
v1.18.x
Anil Mandepudi 8 years ago committed by psychobunny
parent 2e27ce640c
commit f302c0d739

@ -1,24 +1,24 @@
"use strict"; "use strict";
var fork = require('child_process').fork, var fork = require('child_process').fork;
env = process.env, var env = process.env;
worker, updateWorker, var worker, updateWorker, initWorker;
incomplete = [], var incomplete = [];
running = 0; var running = 0;
module.exports = function (grunt) { module.exports = function (grunt) {
var args = []; var args = [];
var initArgs = ['--build'];
if (!grunt.option('verbose')) { if (!grunt.option('verbose')) {
args.push('--log-level=info'); args.push('--log-level=info');
initArgs.push('--log-level=info');
} }
function update(action, filepath, target) { function update(action, filepath, target) {
var updateArgs = args.slice(), var updateArgs = args.slice();
fromFile = '', var compiling = '';
compiling = '', var time = Date.now();
time = Date.now();
if (target === 'lessUpdated_Client') { if (target === 'lessUpdated_Client') {
compiling = 'clientCSS'; compiling = 'clientCSS';
} else if (target === 'lessUpdated_Admin') { } else if (target === 'lessUpdated_Admin') {
@ -44,12 +44,16 @@ module.exports = function (grunt) {
if (updateWorker) { if (updateWorker) {
updateWorker.kill('SIGKILL'); updateWorker.kill('SIGKILL');
} }
updateWorker = fork('app.js', updateArgs, { env: env }); updateWorker = fork('app.js', updateArgs, {
env: env
});
++running; ++running;
updateWorker.on('exit', function () { updateWorker.on('exit', function () {
--running; --running;
if (running === 0) { if (running === 0) {
worker = fork('app.js', args, { env: env }); worker = fork('app.js', args, {
env: env
});
worker.on('message', function () { worker.on('message', function () {
if (incomplete.length) { if (incomplete.length) {
incomplete = []; incomplete = [];
@ -131,15 +135,24 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['watch']);
env.NODE_ENV = 'development';
if (grunt.option('skip')) { if (grunt.option('skip')) {
grunt.registerTask('default', ['watch:serverUpdated']); worker = fork('app.js', args, {
env: env
});
} else { } else {
grunt.registerTask('default', ['watch']); initWorker = fork('app.js', initArgs, {
} env: env
});
env.NODE_ENV = 'development'; initWorker.on('exit', function () {
worker = fork('app.js', args, {
env: env
});
});
}
worker = fork('app.js', args, { env: env });
grunt.event.on('watch', update); grunt.event.on('watch', update);
}; };

Loading…
Cancel
Save