mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-10 16:05:49 +01:00
Merge branch 'master' of https://github.com/designcreateplay/NodeBB
This commit is contained in:
53
src/meta.js
53
src/meta.js
@@ -223,6 +223,7 @@ var fs = require('fs'),
|
|||||||
};
|
};
|
||||||
|
|
||||||
Meta.js = {
|
Meta.js = {
|
||||||
|
cache: undefined,
|
||||||
scripts: [
|
scripts: [
|
||||||
'vendor/jquery/js/jquery.js',
|
'vendor/jquery/js/jquery.js',
|
||||||
'vendor/jquery/js/jquery-ui-1.10.4.custom.js',
|
'vendor/jquery/js/jquery-ui-1.10.4.custom.js',
|
||||||
@@ -240,7 +241,7 @@ var fs = require('fs'),
|
|||||||
'src/translator.js',
|
'src/translator.js',
|
||||||
'src/utils.js'
|
'src/utils.js'
|
||||||
],
|
],
|
||||||
minFile: path.join(__dirname, '..', 'public/src/nodebb.min.js'),
|
minFile: nconf.get('relative_path') + 'nodebb.min.js',
|
||||||
get: function (callback) {
|
get: function (callback) {
|
||||||
plugins.fireHook('filter:scripts.get', this.scripts, function(err, scripts) {
|
plugins.fireHook('filter:scripts.get', this.scripts, function(err, scripts) {
|
||||||
var ctime,
|
var ctime,
|
||||||
@@ -265,47 +266,10 @@ var fs = require('fs'),
|
|||||||
|
|
||||||
Meta.js.scripts = jsPaths.filter(function(path) { return path !== null });
|
Meta.js.scripts = jsPaths.filter(function(path) { return path !== null });
|
||||||
|
|
||||||
if (process.env.NODE_ENV !== 'development') {
|
|
||||||
async.parallel({
|
|
||||||
ctime: function (next) {
|
|
||||||
async.map(jsPaths, fs.stat, function (err, stats) {
|
|
||||||
async.reduce(stats, 0, function (memo, item, next) {
|
|
||||||
if(item) {
|
|
||||||
ctime = +new Date(item.ctime);
|
|
||||||
next(null, ctime > memo ? ctime : memo);
|
|
||||||
} else {
|
|
||||||
next(null, memo);
|
|
||||||
}
|
|
||||||
}, next);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
minFile: function (next) {
|
|
||||||
if (!fs.existsSync(Meta.js.minFile)) {
|
|
||||||
winston.info('No minified client-side library found');
|
|
||||||
return next(null, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.stat(Meta.js.minFile, function (err, stat) {
|
|
||||||
next(err, +new Date(stat.ctime));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, function (err, results) {
|
|
||||||
if (results.minFile > results.ctime) {
|
|
||||||
winston.info('No changes to client-side libraries -- skipping minification');
|
|
||||||
callback(null, [path.relative(path.join(__dirname, '../public'), Meta.js.minFile)]);
|
|
||||||
} else {
|
|
||||||
winston.info('Minifying client-side libraries -- please wait');
|
|
||||||
Meta.js.minify(function () {
|
|
||||||
callback(null, [
|
callback(null, [
|
||||||
path.relative(path.join(__dirname, '../public'), Meta.js.minFile)
|
Meta.js.minFile
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
callback(null, scripts);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
minify: function (callback) {
|
minify: function (callback) {
|
||||||
var uglifyjs = require('uglify-js'),
|
var uglifyjs = require('uglify-js'),
|
||||||
@@ -317,17 +281,8 @@ var fs = require('fs'),
|
|||||||
}
|
}
|
||||||
|
|
||||||
minified = uglifyjs.minify(jsPaths);
|
minified = uglifyjs.minify(jsPaths);
|
||||||
fs.writeFile(Meta.js.minFile, minified.code, function (err) {
|
this.cache = minified.code;
|
||||||
if (!err) {
|
|
||||||
if (process.env.NODE_ENV === 'development') {
|
|
||||||
winston.info('Minified client-side libraries');
|
|
||||||
}
|
|
||||||
callback();
|
callback();
|
||||||
} else {
|
|
||||||
winston.error('Problem minifying client-side libraries, exiting.');
|
|
||||||
process.exit();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -48,5 +48,15 @@ var path = require('path'),
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get('/nodebb.min.js', function(req, res) {
|
||||||
|
if (meta.js.cache) {
|
||||||
|
res.type('text/javascript').send(meta.js.cache);
|
||||||
|
} else {
|
||||||
|
meta.js.minify(function() {
|
||||||
|
res.type('text/javascript').send(meta.js.cache);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
})(exports);
|
})(exports);
|
||||||
@@ -33,7 +33,7 @@ var path = require('path'),
|
|||||||
userRoute = require('./routes/user'),
|
userRoute = require('./routes/user'),
|
||||||
apiRoute = require('./routes/api'),
|
apiRoute = require('./routes/api'),
|
||||||
feedsRoute = require('./routes/feeds'),
|
feedsRoute = require('./routes/feeds'),
|
||||||
themeRoute = require('./routes/theme');
|
metaRoute = require('./routes/meta');
|
||||||
|
|
||||||
if(nconf.get('ssl')) {
|
if(nconf.get('ssl')) {
|
||||||
server = require('https').createServer({
|
server = require('https').createServer({
|
||||||
@@ -483,7 +483,7 @@ process.on('uncaughtException', function(err) {
|
|||||||
|
|
||||||
app.namespace(nconf.get('relative_path'), function () {
|
app.namespace(nconf.get('relative_path'), function () {
|
||||||
auth.registerApp(app);
|
auth.registerApp(app);
|
||||||
themeRoute.createRoutes(app);
|
metaRoute.createRoutes(app);
|
||||||
admin.createRoutes(app);
|
admin.createRoutes(app);
|
||||||
userRoute.createRoutes(app);
|
userRoute.createRoutes(app);
|
||||||
apiRoute.createRoutes(app);
|
apiRoute.createRoutes(app);
|
||||||
|
|||||||
Reference in New Issue
Block a user