Ghost/core/server/config/paths.js
Harry Wolff 9090764052 Standardize file path access throughout ghost
resolves #1390

update all string based references to file paths
to use the ./core/server/config/paths file
so that it is the single source of truth
2013-12-12 21:27:07 -05:00

62 lines
2.1 KiB
JavaScript

// Contains all path information to be used throughout
// the codebase.
var path = require('path'),
when = require('when'),
url = require('url'),
requireTree = require('../require-tree'),
appRoot = path.resolve(__dirname, '../../../'),
corePath = path.resolve(appRoot, 'core/'),
contentPath = path.resolve(appRoot, 'content/'),
themePath = path.resolve(contentPath + '/themes'),
pluginPath = path.resolve(contentPath + '/plugins'),
themeDirectories = requireTree(themePath),
pluginDirectories = requireTree(pluginPath),
localPath = '',
availableThemes,
availablePlugins;
function getPaths() {
return {
'appRoot': appRoot,
'path': localPath,
'webroot': localPath === '/' ? '' : localPath,
'config': path.join(appRoot, 'config.js'),
'configExample': path.join(appRoot, 'config.example.js'),
'contentPath': contentPath,
'corePath': corePath,
'themePath': themePath,
'pluginPath': pluginPath,
'imagesPath': path.resolve(contentPath, 'images/'),
'imagesRelPath': 'content/images',
'adminViews': path.join(corePath, '/server/views/'),
'helperTemplates': path.join(corePath, '/server/helpers/tpl/'),
'lang': path.join(corePath, '/shared/lang/'),
'availableThemes': availableThemes,
'availablePlugins': availablePlugins
};
}
// TODO: remove configURL and give direct access to config object?
// TODO: not called when executing tests
function updatePaths(configURL) {
localPath = url.parse(configURL).path;
// Remove trailing slash
if (localPath !== '/') {
localPath = localPath.replace(/\/$/, '');
}
return when.all([themeDirectories, pluginDirectories]).then(function (paths) {
availableThemes = paths[0];
availablePlugins = paths[1];
return;
});
}
module.exports = getPaths;
module.exports.updatePaths = updatePaths;