Merge pull request #1020 from miksago/themes_dir

Implemented `themes_dir` configuration option.
v1.18.x
Julian Lam 11 years ago
commit b6b795dbc6

@ -79,25 +79,26 @@ function start() {
file: __dirname + '/config.json'
});
nconf.defaults({
themes_dir: path.join(__dirname, 'node_modules')
});
nconf.set('url', nconf.get('base_url') + (nconf.get('use_port') ? ':' + nconf.get('port') : '') + nconf.get('relative_path'));
nconf.set('upload_url', path.join(path.sep, nconf.get('relative_path'), 'uploads', path.sep));
nconf.set('base_dir', __dirname);
// Ensure themes_dir is a full filepath
nconf.set('themes_dir', path.resolve(__dirname, nconf.get('themes_dir')));
winston.info('Time: ' + new Date());
winston.info('Initializing NodeBB v' + pkg.version + ', using ' + nconf./**/get('database') +' store at ' + nconf.get(nconf.get('database') + ':host') + ':' + nconf.get(nconf.get('database') + ':port') + '.');
winston.info('Initializing NodeBB v' + pkg.version);
winston.info('* using ' + nconf.get('database') +' store at ' + nconf.get(nconf.get('database') + ':host') + ':' + nconf.get(nconf.get('database') + ':port'));
winston.info('* using themes stored in: ' + nconf.get('themes_dir'));
if (process.env.NODE_ENV === 'development') {
winston.info('Base Configuration OK.');
}
if (!semver.satisfies(require('./node_modules/nodebb-theme-cerulean/package.json').version, pkg.dependencies['nodebb-theme-cerulean'])) {
winston.error('nodebb-theme-cerulean is out of date - please run npm install.');
}
if (!semver.satisfies(require('./node_modules/nodebb-theme-vanilla/package.json').version, pkg.dependencies['nodebb-theme-vanilla'])) {
winston.error('nodebb-theme-vanilla is out of date - please run npm install.');
}
var meta = require('./src/meta');
require('./src/database').init(function(err) {
@ -122,7 +123,7 @@ function start() {
translator.loadServer();
var customTemplates = meta.config['theme:templates'] ? path.join(__dirname, 'node_modules', meta.config['theme:id'], meta.config['theme:templates']) : false;
var customTemplates = meta.config['theme:templates'] ? path.join(nconf.get('themes_dir'), meta.config['theme:id'], meta.config['theme:templates']) : false;
utils.walk(path.join(__dirname, 'public/templates'), function (err, tplsToLoad) {
templates.init(tplsToLoad, customTemplates);

@ -85,7 +85,7 @@ var fs = require('fs'),
Meta.themes = {
get: function (callback) {
var themePath = path.join(__dirname, '../node_modules');
var themePath = nconf.get('themes_dir');
fs.readdir(themePath, function (err, files) {
async.filter(files, function (file, next) {
fs.stat(path.join(themePath, file), function (err, fileStat) {
@ -132,7 +132,7 @@ var fs = require('fs'),
case 'local':
async.waterfall([
function(next) {
fs.readFile(path.join(__dirname, '../node_modules', data.id, 'theme.json'), function(err, config) {
fs.readFile(path.join(nconf.get('themes_dir'), data.id, 'theme.json'), function(err, config) {
if (!err) {
config = JSON.parse(config.toString());
next(null, config);

@ -255,7 +255,7 @@ module.exports.server = server;
// Theme's static directory
if (themeData['theme:staticDir']) {
app.use('/css/assets', express.static(path.join(__dirname, '../node_modules', themeData['theme:id'], themeData['theme:staticDir']), {
app.use('/css/assets', express.static(path.join(__dirname, nconf.get('themes_dir'), themeData['theme:id'], themeData['theme:staticDir']), {
maxAge: app.enabled('cache') ? 5184000000 : 0
}));
if (process.env.NODE_ENV === 'development') {
@ -264,7 +264,7 @@ module.exports.server = server;
}
if (themeData['theme:templates']) {
app.use('/templates', express.static(path.join(__dirname, '../node_modules', themeData['theme:id'], themeData['theme:templates']), {
app.use('/templates', express.static(path.join(__dirname, nconf.get('themes_dir'), themeData['theme:id'], themeData['theme:templates']), {
maxAge: app.enabled('cache') ? 5184000000 : 0
}));
if (process.env.NODE_ENV === 'development') {
@ -273,7 +273,7 @@ module.exports.server = server;
}
app.use(require('less-middleware')({
src: path.join(__dirname, '../node_modules/' + themeId),
src: path.join(__dirname, nconf.get('themes_dir') + themeId),
dest: path.join(__dirname, '../public/css'),
prefix: nconf.get('relative_path') + '/css',
yuicompress: app.enabled('minification') ? true : false
@ -287,7 +287,7 @@ module.exports.server = server;
}
app.use(require('less-middleware')({
src: path.join(__dirname, '../node_modules/nodebb-theme-vanilla'),
src: path.join(__dirname, nconf.get('themes_dir'), '/nodebb-theme-vanilla'),
dest: path.join(__dirname, '../public/css'),
prefix: nconf.get('relative_path') + '/css',
yuicompress: app.enabled('minification') ? true : false
@ -303,7 +303,7 @@ module.exports.server = server;
async.each(themes, function(themeObj, next) {
if (themeObj.screenshot) {
screenshotPath = path.join(__dirname, '../node_modules', themeObj.id, themeObj.screenshot);
screenshotPath = path.join(__dirname, nconf.get('themes_dir'), themeObj.id, themeObj.screenshot);
(function(id, path) {
fs.exists(path, function(exists) {
if (exists) {

Loading…
Cancel
Save