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; minified;
winston.info('Minifying client-side libraries'); if (process.env.NODE_ENV === 'development') winston.info('Minifying client-side libraries');
minified = uglifyjs.minify(jsPaths); minified = uglifyjs.minify(jsPaths);
fs.writeFile(Meta.js.minFile, minified.code, function (err) { fs.writeFile(Meta.js.minFile, minified.code, function (err) {
if (!err) { if (!err) {
winston.info('Minified client-side libraries'); if (process.env.NODE_ENV === 'development') winston.info('Minified client-side libraries');
callback(); callback();
} else { } else {
winston.error('Problem minifying client-side libraries, exiting.'); winston.error('Problem minifying client-side libraries, exiting.');

@ -8,6 +8,7 @@ var fs = require('fs'),
libraries: {}, libraries: {},
loadedHooks: {}, loadedHooks: {},
staticDirs: {}, staticDirs: {},
cssFiles: [],
// Events // Events
readyEvent: new eventEmitter, readyEvent: new eventEmitter,
@ -93,6 +94,7 @@ var fs = require('fs'),
} else next(); } else next();
}, },
function(next) { function(next) {
// Static Directories for Plugins
if (pluginData.staticDir) { if (pluginData.staticDir) {
staticDir = path.join(pluginPath, pluginData.staticDir); staticDir = path.join(pluginPath, pluginData.staticDir);
@ -103,6 +105,19 @@ var fs = require('fs'),
} else next(); } else next();
}); });
} 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) { ], function(err) {
if (!err) { if (!err) {

@ -119,18 +119,36 @@ var express = require('express'),
next(); 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) { function(next) {
// Static Directories for NodeBB Plugins // Static Directories for NodeBB Plugins
plugins.ready(function () { plugins.ready(function () {
for (d in plugins.staticDirs) { for (d in plugins.staticDirs) {
console.log(plugins.staticDirs[d]);
app.use(nconf.get('relative_path') + '/plugins/' + d, express.static(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(); next();
}); });
}, },
function(next) { function(next) {
console.log('router');
// Router & post-router middlewares // Router & post-router middlewares
app.use(app.router); app.use(app.router);
@ -176,8 +194,9 @@ var express = require('express'),
], function(err) { ], function(err) {
if (err) { if (err) {
winston.error('Errors were encountered while attempting to initialise NodeBB.'); winston.error('Errors were encountered while attempting to initialise NodeBB.');
process.exit();
} else { } else {
winston.info('Middlewares loaded.'); if (process.env.NODE_ENV === 'development') winston.info('Middlewares loaded.');
} }
}); });
}); });

Loading…
Cancel
Save