|
|
@ -7,6 +7,7 @@ var winston = require('winston'),
|
|
|
|
_ = require('underscore'),
|
|
|
|
_ = require('underscore'),
|
|
|
|
os = require('os'),
|
|
|
|
os = require('os'),
|
|
|
|
nconf = require('nconf'),
|
|
|
|
nconf = require('nconf'),
|
|
|
|
|
|
|
|
cluster = require('cluster'),
|
|
|
|
|
|
|
|
|
|
|
|
plugins = require('../plugins'),
|
|
|
|
plugins = require('../plugins'),
|
|
|
|
emitter = require('../emitter'),
|
|
|
|
emitter = require('../emitter'),
|
|
|
@ -120,70 +121,85 @@ module.exports = function(Meta) {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Meta.js.minify = function(minify, callback) {
|
|
|
|
Meta.js.minify = function(minify, callback) {
|
|
|
|
var minifier = Meta.js.minifierProc = fork('minifier.js', {
|
|
|
|
if (!cluster.isWorker || process.env.cluster_setup === 'true') {
|
|
|
|
silent: true
|
|
|
|
var minifier = Meta.js.minifierProc = fork('minifier.js', {
|
|
|
|
}),
|
|
|
|
silent: true
|
|
|
|
minifiedStream = minifier.stdio[1],
|
|
|
|
}),
|
|
|
|
minifiedString = '',
|
|
|
|
minifiedStream = minifier.stdio[1],
|
|
|
|
mapStream = minifier.stdio[2],
|
|
|
|
minifiedString = '',
|
|
|
|
mapString = '',
|
|
|
|
mapStream = minifier.stdio[2],
|
|
|
|
step = 0,
|
|
|
|
mapString = '',
|
|
|
|
onComplete = function() {
|
|
|
|
step = 0,
|
|
|
|
if (step === 0) {
|
|
|
|
onComplete = function() {
|
|
|
|
return step++;
|
|
|
|
if (step === 0) {
|
|
|
|
}
|
|
|
|
return step++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Meta.js.cache = minifiedString;
|
|
|
|
Meta.js.cache = minifiedString;
|
|
|
|
Meta.js.map = mapString;
|
|
|
|
Meta.js.map = mapString;
|
|
|
|
winston.info('[meta/js] Compilation complete');
|
|
|
|
winston.info('[meta/js] Compilation complete');
|
|
|
|
emitter.emit('meta:js.compiled');
|
|
|
|
emitter.emit('meta:js.compiled');
|
|
|
|
minifier.kill();
|
|
|
|
minifier.kill();
|
|
|
|
if (typeof callback === 'function') {
|
|
|
|
|
|
|
|
callback();
|
|
|
|
if (cluster.isWorker) {
|
|
|
|
}
|
|
|
|
process.send({
|
|
|
|
};
|
|
|
|
action: 'js-propagate',
|
|
|
|
|
|
|
|
cache: minifiedString,
|
|
|
|
|
|
|
|
map: mapString
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
minifiedStream.on('data', function(buffer) {
|
|
|
|
if (typeof callback === 'function') {
|
|
|
|
minifiedString += buffer.toString();
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
mapStream.on('data', function(buffer) {
|
|
|
|
};
|
|
|
|
mapString += buffer.toString();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
minifier.on('message', function(message) {
|
|
|
|
minifiedStream.on('data', function(buffer) {
|
|
|
|
switch(message.type) {
|
|
|
|
minifiedString += buffer.toString();
|
|
|
|
case 'end':
|
|
|
|
});
|
|
|
|
if (message.payload === 'script') {
|
|
|
|
mapStream.on('data', function(buffer) {
|
|
|
|
winston.info('[meta/js] Successfully minified.');
|
|
|
|
mapString += buffer.toString();
|
|
|
|
onComplete();
|
|
|
|
});
|
|
|
|
} else if (message.payload === 'mapping') {
|
|
|
|
|
|
|
|
winston.info('[meta/js] Retrieved Mapping.');
|
|
|
|
minifier.on('message', function(message) {
|
|
|
|
onComplete();
|
|
|
|
switch(message.type) {
|
|
|
|
}
|
|
|
|
case 'end':
|
|
|
|
break;
|
|
|
|
if (message.payload === 'script') {
|
|
|
|
case 'hash':
|
|
|
|
winston.info('[meta/js] Successfully minified.');
|
|
|
|
Meta.js.hash = message.payload;
|
|
|
|
onComplete();
|
|
|
|
break;
|
|
|
|
} else if (message.payload === 'mapping') {
|
|
|
|
case 'error':
|
|
|
|
winston.info('[meta/js] Retrieved Mapping.');
|
|
|
|
winston.error('[meta/js] Could not compile client-side scripts! ' + message.payload.message);
|
|
|
|
onComplete();
|
|
|
|
minifier.kill();
|
|
|
|
}
|
|
|
|
if (typeof callback === 'function') {
|
|
|
|
break;
|
|
|
|
callback(new Error(message.payload.message));
|
|
|
|
case 'hash':
|
|
|
|
} else {
|
|
|
|
Meta.js.hash = message.payload;
|
|
|
|
process.exit(0);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Meta.js.prepare(function() {
|
|
|
|
Meta.js.prepare(function() {
|
|
|
|
minifier.send({
|
|
|
|
minifier.send({
|
|
|
|
action: 'js',
|
|
|
|
action: 'js',
|
|
|
|
relativePath: nconf.get('url') + '/',
|
|
|
|
relativePath: nconf.get('url') + '/',
|
|
|
|
minify: minify,
|
|
|
|
minify: minify,
|
|
|
|
scripts: Meta.js.scripts.all
|
|
|
|
scripts: Meta.js.scripts.all
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (typeof callback === 'function') {
|
|
|
|
|
|
|
|
callback();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Meta.js.killMinifier = function(callback) {
|
|
|
|
Meta.js.killMinifier = function(callback) {
|
|
|
|