some more cleanup

v1.18.x
psychobunny 9 years ago
parent 3cc5e1473f
commit 5e4ef52911

@ -82,58 +82,31 @@ module.exports = function(Meta) {
} }
}; };
Meta.js.prepare = function (callback) { Meta.js.minify = function(callback) {
async.parallel([ if (nconf.get('isPrimary') !== 'true') {
async.apply(getPluginScripts), // plugin scripts via filter:scripts.get if (typeof callback === 'function') {
function(next) { // client scripts via "scripts" config in plugin.json callback();
var pluginsScripts = [],
pluginDirectories = [];
pluginsScripts = plugins.clientScripts.filter(function(path) {
if (path.endsWith('.js')) {
return true;
} else {
pluginDirectories.push(path);
return false;
} }
});
// Add plugin scripts
Meta.js.scripts.client = pluginsScripts;
// Add plugin script directories return;
async.each(pluginDirectories, function(directory, next) {
utils.walk(directory, function(err, scripts) {
Meta.js.scripts.client = Meta.js.scripts.client.concat(scripts);
next(err);
});
}, next);
}
], function(err) {
if (err) {
return callback(err);
} }
// Convert all scripts to paths relative to the NodeBB base directory
var basePath = path.resolve(__dirname, '../..');
Meta.js.scripts.all = Meta.js.scripts.base.concat(Meta.js.scripts.rjs, Meta.js.scripts.plugin, Meta.js.scripts.client).map(function(script) {
return path.relative(basePath, script).replace(/\\/g, '/');
});
callback();
});
};
Meta.js.minify = function(callback) {
if (nconf.get('isPrimary') === 'true') {
var forkProcessParams = setupDebugging(); var forkProcessParams = setupDebugging();
var minifier = Meta.js.minifierProc = fork('minifier.js', [], forkProcessParams);
var minifier = Meta.js.minifierProc = fork('minifier.js', [], forkProcessParams), Meta.js.prepare(function() {
onComplete = function(err) { minifier.send({
if (err) { action: 'js',
winston.error('[meta/js] Minification failed: ' + err.message); minify: global.env !== 'development',
process.exit(0); 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'); winston.verbose('[meta/js] Minification complete');
minifier.kill(); minifier.kill();
@ -150,14 +123,6 @@ module.exports = function(Meta) {
if (typeof callback === 'function') { if (typeof callback === 'function') {
callback(); callback();
} }
};
minifier.on('message', function(message) {
switch(message.type) {
case 'end':
Meta.js.cache = message.minified;
Meta.js.map = message.sourceMap;
onComplete();
break; break;
case 'error': case 'error':
winston.error('[meta/js] Could not compile client-side scripts! ' + message.payload.message); winston.error('[meta/js] Could not compile client-side scripts! ' + message.payload.message);
@ -170,19 +135,47 @@ module.exports = function(Meta) {
break; break;
} }
}); });
};
Meta.js.prepare(function() { Meta.js.prepare = function(callback) {
minifier.send({ async.parallel([
action: 'js', async.apply(getPluginScripts), // plugin scripts via filter:scripts.get
minify: global.env !== 'development', function(next) { // client scripts via "scripts" config in plugin.json
scripts: Meta.js.scripts.all var pluginsScripts = [],
pluginDirectories = [];
pluginsScripts = plugins.clientScripts.filter(function(path) {
if (path.endsWith('.js')) {
return true;
} else {
pluginDirectories.push(path);
return false;
}
}); });
// Add plugin scripts
Meta.js.scripts.client = pluginsScripts;
// Add plugin script directories
async.each(pluginDirectories, function(directory, next) {
utils.walk(directory, function(err, scripts) {
Meta.js.scripts.client = Meta.js.scripts.client.concat(scripts);
next(err);
}); });
} else { }, next);
if (typeof callback === 'function') {
callback();
} }
], function(err) {
if (err) {
return callback(err);
} }
// Convert all scripts to paths relative to the NodeBB base directory
var basePath = path.resolve(__dirname, '../..');
Meta.js.scripts.all = Meta.js.scripts.base.concat(Meta.js.scripts.rjs, Meta.js.scripts.plugin, Meta.js.scripts.client).map(function(script) {
return path.relative(basePath, script).replace(/\\/g, '/');
});
callback();
});
}; };
Meta.js.killMinifier = function() { Meta.js.killMinifier = function() {

Loading…
Cancel
Save