From 5e4ef5291128d95043d0c2e16672e1a34b4b4c6e Mon Sep 17 00:00:00 2001 From: psychobunny Date: Mon, 18 Jan 2016 14:18:17 -0500 Subject: [PATCH] some more cleanup --- src/meta/js.js | 119 +++++++++++++++++++++++-------------------------- 1 file changed, 56 insertions(+), 63 deletions(-) diff --git a/src/meta/js.js b/src/meta/js.js index b0e4a7afad..421d14b096 100644 --- a/src/meta/js.js +++ b/src/meta/js.js @@ -82,7 +82,62 @@ module.exports = function(Meta) { } }; - Meta.js.prepare = function (callback) { + Meta.js.minify = function(callback) { + if (nconf.get('isPrimary') !== 'true') { + if (typeof callback === 'function') { + callback(); + } + + return; + } + + var forkProcessParams = setupDebugging(); + var minifier = Meta.js.minifierProc = fork('minifier.js', [], forkProcessParams); + + Meta.js.prepare(function() { + minifier.send({ + action: 'js', + minify: global.env !== 'development', + scripts: Meta.js.scripts.all + }); + }); + + minifier.on('message', function(message) { + switch(message.type) { + case 'end': + Meta.js.cache = message.minified; + Meta.js.map = message.sourceMap; + winston.verbose('[meta/js] Minification complete'); + minifier.kill(); + + if (process.send) { + process.send({ + action: 'js-propagate', + cache: Meta.js.cache, + map: Meta.js.map + }); + } + + Meta.js.commitToFile(); + + if (typeof callback === 'function') { + callback(); + } + break; + case 'error': + winston.error('[meta/js] Could not compile client-side scripts! ' + message.payload.message); + minifier.kill(); + if (typeof callback === 'function') { + callback(new Error(message.payload.message)); + } else { + process.exit(0); + } + break; + } + }); + }; + + Meta.js.prepare = function(callback) { async.parallel([ async.apply(getPluginScripts), // plugin scripts via filter:scripts.get function(next) { // client scripts via "scripts" config in plugin.json @@ -123,68 +178,6 @@ module.exports = function(Meta) { }); }; - Meta.js.minify = function(callback) { - if (nconf.get('isPrimary') === 'true') { - var forkProcessParams = setupDebugging(); - - var minifier = Meta.js.minifierProc = fork('minifier.js', [], forkProcessParams), - onComplete = function(err) { - if (err) { - winston.error('[meta/js] Minification failed: ' + err.message); - process.exit(0); - } - - winston.verbose('[meta/js] Minification complete'); - minifier.kill(); - - if (process.send) { - process.send({ - action: 'js-propagate', - cache: Meta.js.cache, - map: Meta.js.map - }); - } - - Meta.js.commitToFile(); - - if (typeof callback === 'function') { - callback(); - } - }; - - minifier.on('message', function(message) { - switch(message.type) { - case 'end': - Meta.js.cache = message.minified; - Meta.js.map = message.sourceMap; - onComplete(); - break; - case 'error': - winston.error('[meta/js] Could not compile client-side scripts! ' + message.payload.message); - minifier.kill(); - if (typeof callback === 'function') { - callback(new Error(message.payload.message)); - } else { - process.exit(0); - } - break; - } - }); - - Meta.js.prepare(function() { - minifier.send({ - action: 'js', - minify: global.env !== 'development', - scripts: Meta.js.scripts.all - }); - }); - } else { - if (typeof callback === 'function') { - callback(); - } - } - }; - Meta.js.killMinifier = function() { if (Meta.js.minifierProc) { Meta.js.minifierProc.kill('SIGTERM');