Update gruntfile to build on initialization

v1.18.x
pichalite 8 years ago
parent aa64ec7db1
commit 5ca931a52c

@ -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 = [];
@ -136,10 +140,18 @@ module.exports = function (grunt) {
} else { } else {
grunt.registerTask('default', ['watch']); grunt.registerTask('default', ['watch']);
} }
env.NODE_ENV = 'development'; env.NODE_ENV = 'development';
worker = fork('app.js', args, { env: env }); initWorker = fork('app.js', initArgs, {
env: env
});
initWorker.on('exit', function () {
worker = fork('app.js', args, {
env: env
});
});
grunt.event.on('watch', update); grunt.event.on('watch', update);
}; };

Loading…
Cancel
Save