v1.18.x
psychobunny 9 years ago
parent 5e4ef52911
commit 42c0b973f1

2
.gitignore vendored

@ -31,6 +31,8 @@ pidfile
/public/admin.css /public/admin.css
/public/nodebb.min.js /public/nodebb.min.js
/public/nodebb.min.js.map /public/nodebb.min.js.map
/public/acp.min.js
/public/acp.min.js.map
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
*.iml *.iml

@ -62,7 +62,8 @@ var async = require('async'),
async.apply(plugins.reloadRoutes), async.apply(plugins.reloadRoutes),
function(next) { function(next) {
async.parallel([ async.parallel([
async.apply(Meta.js.minify), async.apply(Meta.js.minify, 'nodebb.min.js'),
async.apply(Meta.js.minify, 'acp.min.js'),
async.apply(Meta.css.minify), async.apply(Meta.css.minify),
async.apply(Meta.sounds.init), async.apply(Meta.sounds.init),
async.apply(Meta.templates.compile), async.apply(Meta.templates.compile),

@ -15,8 +15,7 @@ var winston = require('winston'),
module.exports = function(Meta) { module.exports = function(Meta) {
Meta.js = { Meta.js = {
cache: '', target: {},
map: '',
scripts: { scripts: {
base: [ base: [
'public/vendor/jquery/js/jquery.js', 'public/vendor/jquery/js/jquery.js',
@ -82,7 +81,7 @@ module.exports = function(Meta) {
} }
}; };
Meta.js.minify = function(callback) { Meta.js.minify = function(target, callback) {
if (nconf.get('isPrimary') !== 'true') { if (nconf.get('isPrimary') !== 'true') {
if (typeof callback === 'function') { if (typeof callback === 'function') {
callback(); callback();
@ -94,31 +93,33 @@ module.exports = function(Meta) {
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() { Meta.js.target[target] = {};
Meta.js.prepare(target, function() {
minifier.send({ minifier.send({
action: 'js', action: 'js',
minify: global.env !== 'development', minify: global.env !== 'development',
scripts: Meta.js.scripts.all scripts: Meta.js.target[target].scripts
}); });
}); });
minifier.on('message', function(message) { minifier.on('message', function(message) {
switch(message.type) { switch(message.type) {
case 'end': case 'end':
Meta.js.cache = message.minified; Meta.js.target[target].cache = message.minified;
Meta.js.map = message.sourceMap; Meta.js.target[target].map = message.sourceMap;
winston.verbose('[meta/js] Minification complete'); winston.verbose('[meta/js] Minification complete');
minifier.kill(); minifier.kill();
if (process.send) { if (process.send) {
process.send({ process.send({
action: 'js-propagate', action: 'js-propagate',
cache: Meta.js.cache, cache: Meta.js.target[target].cache,
map: Meta.js.map map: Meta.js.target[target].map
}); });
} }
Meta.js.commitToFile(); Meta.js.commitToFile(target);
if (typeof callback === 'function') { if (typeof callback === 'function') {
callback(); callback();
@ -137,14 +138,22 @@ module.exports = function(Meta) {
}); });
}; };
Meta.js.prepare = function(callback) { Meta.js.prepare = function(target, callback) {
var pluginsScripts = [];
async.parallel([ async.parallel([
async.apply(getPluginScripts), // plugin scripts via filter:scripts.get function(next) {
function(next) { // client scripts via "scripts" config in plugin.json if (target === 'nodebb.min.js') {
var pluginsScripts = [], getPluginScripts(next);
pluginDirectories = []; } else {
next();
}
},
function(next) {
// client scripts via "scripts" config in plugin.json
var pluginDirectories = [];
pluginsScripts = plugins.clientScripts.filter(function(path) { pluginsScripts = plugins[target === 'nodebb.min.js' ? 'clientScripts' : 'acpScripts'].filter(function(path) {
if (path.endsWith('.js')) { if (path.endsWith('.js')) {
return true; return true;
} else { } else {
@ -153,13 +162,9 @@ module.exports = function(Meta) {
} }
}); });
// Add plugin scripts
Meta.js.scripts.client = pluginsScripts;
// Add plugin script directories
async.each(pluginDirectories, function(directory, next) { async.each(pluginDirectories, function(directory, next) {
utils.walk(directory, function(err, scripts) { utils.walk(directory, function(err, scripts) {
Meta.js.scripts.client = Meta.js.scripts.client.concat(scripts); pluginsScripts = pluginsScripts.concat(scripts);
next(err); next(err);
}); });
}, next); }, next);
@ -171,9 +176,17 @@ module.exports = function(Meta) {
// Convert all scripts to paths relative to the NodeBB base directory // Convert all scripts to paths relative to the NodeBB base directory
var basePath = path.resolve(__dirname, '../..'); 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) {
if (target === 'nodebb.min.js') {
Meta.js.target[target].scripts = Meta.js.scripts.base.concat(pluginsScripts, Meta.js.scripts.rjs, Meta.js.scripts.plugin);
} else {
Meta.js.target[target].scripts = pluginsScripts;
}
Meta.js.target[target].scripts = Meta.js.target[target].scripts.map(function(script) {
return path.relative(basePath, script).replace(/\\/g, '/'); return path.relative(basePath, script).replace(/\\/g, '/');
}); });
callback(); callback();
}); });
}; };
@ -184,8 +197,8 @@ module.exports = function(Meta) {
} }
}; };
Meta.js.commitToFile = function() { Meta.js.commitToFile = function(target) {
fs.writeFile(path.join(__dirname, '../../public/nodebb.min.js'), Meta.js.cache, function (err) { fs.writeFile(path.join(__dirname, '../../public/' + target), Meta.js.target[target].cache, function (err) {
if (err) { if (err) {
winston.error('[meta/js] ' + err.message); winston.error('[meta/js] ' + err.message);
process.exit(0); process.exit(0);
@ -196,14 +209,15 @@ module.exports = function(Meta) {
}); });
}; };
Meta.js.getFromFile = function(callback) { Meta.js.getFromFile = function(target, callback) {
var scriptPath = path.join(__dirname, '../../public/nodebb.min.js'), var scriptPath = path.join(__dirname, '../../public/' + target),
mapPath = path.join(__dirname, '../../public/nodebb.min.js.map'), mapPath = path.join(__dirname, '../../public/' + target + '.map'),
paths = [scriptPath]; paths = [scriptPath];
file.exists(scriptPath, function(exists) { file.exists(scriptPath, function(exists) {
if (!exists) { if (!exists) {
winston.warn('[meta/js] No script file found on disk, re-minifying'); winston.warn('[meta/js] No script file found on disk, re-minifying');
Meta.js.minify(callback); Meta.js.minify(target, callback);
return; return;
} }
@ -218,8 +232,10 @@ module.exports = function(Meta) {
winston.verbose('[meta/js] Reading client-side scripts from file'); winston.verbose('[meta/js] Reading client-side scripts from file');
async.map(paths, fs.readFile, function(err, files) { async.map(paths, fs.readFile, function(err, files) {
Meta.js.cache = files[0]; Meta.js.target[target] = {
Meta.js.map = files[1] || ''; cache: files[0],
map: files[1] || ''
};
emitter.emit('meta:js.compiled'); emitter.emit('meta:js.compiled');
callback(); callback();

@ -30,6 +30,7 @@ var fs = require('fs'),
Plugins.cssFiles = []; Plugins.cssFiles = [];
Plugins.lessFiles = []; Plugins.lessFiles = [];
Plugins.clientScripts = []; Plugins.clientScripts = [];
Plugins.acpScripts = [];
Plugins.customLanguages = []; Plugins.customLanguages = [];
Plugins.customLanguageFallbacks = {}; Plugins.customLanguageFallbacks = {};
Plugins.libraryPaths = []; Plugins.libraryPaths = [];
@ -81,6 +82,7 @@ var fs = require('fs'),
Plugins.cssFiles.length = 0; Plugins.cssFiles.length = 0;
Plugins.lessFiles.length = 0; Plugins.lessFiles.length = 0;
Plugins.clientScripts.length = 0; Plugins.clientScripts.length = 0;
Plugins.acpScripts.length = 0;
Plugins.libraryPaths.length = 0; Plugins.libraryPaths.length = 0;
Plugins.registerHook('core', { Plugins.registerHook('core', {

@ -152,6 +152,16 @@ module.exports = function(Plugins) {
})); }));
} }
if (Array.isArray(pluginData.acpScripts)) {
if (global.env === 'development') {
winston.verbose('[plugins] Found ' + pluginData.acpScripts.length + ' js file(s) for plugin ' + pluginData.id);
}
Plugins.acpScripts = Plugins.acpScripts.concat(pluginData.acpScripts.map(function(file) {
return path.join(__dirname, '../../node_modules/', pluginData.id, file);
}));
}
callback(); callback();
} }

@ -5,7 +5,7 @@ var meta = require('../meta'),
function sendMinifiedJS(req, res, next) { function sendMinifiedJS(req, res, next) {
res.type('text/javascript').send(meta.js.cache); res.type('text/javascript').send(meta.js.target['nodebb.min.js'].cache);
} }
// The portions of code involving the source map are commented out as they're broken in UglifyJS2 // The portions of code involving the source map are commented out as they're broken in UglifyJS2

@ -31,6 +31,7 @@
<script type="text/javascript" src="{relative_path}/vendor/hammer/hammer.min.js?{cache-buster}"></script> <script type="text/javascript" src="{relative_path}/vendor/hammer/hammer.min.js?{cache-buster}"></script>
<script type="text/javascript" src="{relative_path}/vendor/jquery/sortable/Sortable.js?{cache-buster}"></script> <script type="text/javascript" src="{relative_path}/vendor/jquery/sortable/Sortable.js?{cache-buster}"></script>
<script type="text/javascript" src="{relative_path}/nodebb.min.js?{cache-buster}"></script> <script type="text/javascript" src="{relative_path}/nodebb.min.js?{cache-buster}"></script>
<script type="text/javascript" src="{relative_path}/acp.min.js?{cache-buster}"></script>
<script> <script>
require.config({ require.config({
baseUrl: "{relative_path}/src/modules", baseUrl: "{relative_path}/src/modules",

@ -92,7 +92,8 @@ function initializeNodeBB(callback) {
function(next) { function(next) {
async.parallel([ async.parallel([
async.apply(meta.templates.compile), async.apply(meta.templates.compile),
async.apply(!skipJS ? meta.js.minify : meta.js.getFromFile), async.apply(!skipJS ? meta.js.minify : meta.js.getFromFile, 'nodebb.min.js'),
async.apply(!skipJS ? meta.js.minify : meta.js.getFromFile, 'acp.min.js'),
async.apply(!skipLess ? meta.css.minify : meta.css.getFromFile), async.apply(!skipLess ? meta.css.minify : meta.css.getFromFile),
async.apply(meta.sounds.init) async.apply(meta.sounds.init)
], next); ], next);

Loading…
Cancel
Save