WIP commit for CSS static directories

v1.18.x
Julian Lam 11 years ago
parent 0b299b2fe7
commit 63ff572076

@ -215,11 +215,11 @@ var utils = require('./../public/src/utils.js'),
}),
minified;
winston.info('Minifying client-side libraries');
if (process.env.NODE_ENV === 'development') winston.info('Minifying client-side libraries');
minified = uglifyjs.minify(jsPaths);
fs.writeFile(Meta.js.minFile, minified.code, function (err) {
if (!err) {
winston.info('Minified client-side libraries');
if (process.env.NODE_ENV === 'development') winston.info('Minified client-side libraries');
callback();
} else {
winston.error('Problem minifying client-side libraries, exiting.');

@ -8,6 +8,7 @@ var fs = require('fs'),
libraries: {},
loadedHooks: {},
staticDirs: {},
cssFiles: [],
// Events
readyEvent: new eventEmitter,
@ -93,6 +94,7 @@ var fs = require('fs'),
} else next();
},
function(next) {
// Static Directories for Plugins
if (pluginData.staticDir) {
staticDir = path.join(pluginPath, pluginData.staticDir);
@ -103,6 +105,19 @@ var fs = require('fs'),
} else next();
});
} else next();
},
function(next) {
// CSS Files for plugins
if (pluginData.css && pluginData.css instanceof Array) {
for(var x=0,numCss=pluginData.css.length;x<numCss;x++) {
_self.cssFiles.push({
plugin: pluginData.id,
path: path.join(pluginPath, pluginData.css[x])
});
}
next();
} else next();
}
], function(err) {
if (!err) {

@ -119,18 +119,36 @@ var express = require('express'),
next();
},
function(next) {
// Static CSS files for NodeBB Plugins
plugins.ready(function() {
var file,x,numCss,route;
for(x=0,numCss=plugins.cssFiles.length;x<numCss;x++) {
file = plugins.cssFiles[x];
route = path.join(nconf.get('relative_path'), '/css/', file.plugin);
app.use(route, express.static(file.path));
if (process.env.NODE_ENV === 'development') winston.info('Plugin CSS file found: ' + route);
console.log('route', route);
console.log('path', file.path);
}
next();
});
},
function(next) {
// Static Directories for NodeBB Plugins
plugins.ready(function () {
for (d in plugins.staticDirs) {
console.log(plugins.staticDirs[d]);
app.use(nconf.get('relative_path') + '/plugins/' + d, express.static(plugins.staticDirs[d]));
winston.info('Static directory routed for plugin: ' + d);
if (process.env.NODE_ENV === 'development') winston.info('Static directory routed for plugin: ' + d);
}
next();
});
},
function(next) {
console.log('router');
// Router & post-router middlewares
app.use(app.router);
@ -176,8 +194,9 @@ var express = require('express'),
], function(err) {
if (err) {
winston.error('Errors were encountered while attempting to initialise NodeBB.');
process.exit();
} else {
winston.info('Middlewares loaded.');
if (process.env.NODE_ENV === 'development') winston.info('Middlewares loaded.');
}
});
});

Loading…
Cancel
Save