Skip to content

Node.js based forum software built for the modern web

plugins - filter:scripts.get hook lets a plugin add client-side JS to the header and queue up for minification on production

psychobunny5357ad61db6c
diff --git a/src/meta.js b/src/meta.js
index 572e17a606..792d213a84 100644
--- a/src/meta.js
+++ b/src/meta.js
@@ -1,5 +1,6 @@
var utils = require('./../public/src/utils.js'),
RDB = require('./redis.js'),
+ plugins = require('./plugins'),
async = require('async'),
path = require('path'),
fs = require('fs'),
@@ -207,44 +208,46 @@ var utils = require('./../public/src/utils.js'),
],
minFile: path.join(__dirname, '..', 'public/src/nodebb.min.js'),
get: function (callback) {
- var mtime,
- jsPaths = this.scripts.map(function (jsPath) {
- return path.join(__dirname, '..', '/public', jsPath);
- });
+ plugins.fireHook('filter:scripts.get', this.scripts, function(err, scripts) {
+ var mtime,
+ jsPaths = scripts.map(function (jsPath) {
+ return path.join(__dirname, '..', '/public', jsPath);
+ });
- if (process.env.NODE_ENV !== 'development') {
- async.parallel({
- mtime: function (next) {
- async.map(jsPaths, fs.stat, function (err, stats) {
- async.reduce(stats, 0, function (memo, item, callback) {
- mtime = +new Date(item.mtime);
- callback(null, mtime > memo ? mtime : memo);
- }, next);
- });
- },
- minFile: function (next) {
- if (!fs.existsSync(Meta.js.minFile)) {
- if (process.env.NODE_ENV === 'development') winston.warn('No minified client-side library found');
- return next(null, 0);
- }
+ if (process.env.NODE_ENV !== 'development') {
+ async.parallel({
+ mtime: function (next) {
+ async.map(jsPaths, fs.stat, function (err, stats) {
+ async.reduce(stats, 0, function (memo, item, callback) {
+ mtime = +new Date(item.mtime);
+ callback(null, mtime > memo ? mtime : memo);
+ }, next);
+ });
+ },
+ minFile: function (next) {
+ if (!fs.existsSync(Meta.js.minFile)) {
+ if (process.env.NODE_ENV === 'development') winston.warn('No minified client-side library found');
+ return next(null, 0);
+ }
- fs.stat(Meta.js.minFile, function (err, stat) {
- next(err, +new Date(stat.mtime));
- });
- }
- }, function (err, results) {
- if (results.minFile > results.mtime) {
- if (process.env.NODE_ENV === 'development') winston.info('No changes to client-side libraries -- skipping minification');
- callback(null, [path.relative(path.join(__dirname, '../public'), Meta.js.minFile)]);
- } else {
- Meta.js.minify(function () {
+ fs.stat(Meta.js.minFile, function (err, stat) {
+ next(err, +new Date(stat.mtime));
+ });
+ }
+ }, function (err, results) {
+ if (results.minFile > results.mtime) {
+ if (process.env.NODE_ENV === 'development') winston.info('No changes to client-side libraries -- skipping minification');
callback(null, [path.relative(path.join(__dirname, '../public'), Meta.js.minFile)]);
- });
- }
- });
- } else {
- callback(null, this.scripts);
- }
+ } else {
+ Meta.js.minify(function () {
+ callback(null, [path.relative(path.join(__dirname, '../public'), Meta.js.minFile)]);
+ });
+ }
+ });
+ } else {
+ callback(null, scripts);
+ }
+ });
},
minify: function (callback) {
var uglifyjs = require('uglify-js'),