2013-11-20 17:58:52 +04:00
|
|
|
|
|
|
|
|
|
|
|
var path = require('path'),
|
|
|
|
when = require('when'),
|
2013-12-06 12:51:35 +04:00
|
|
|
url = require('url'),
|
2013-11-20 17:58:52 +04:00
|
|
|
requireTree = require('../require-tree'),
|
|
|
|
appRoot = path.resolve(__dirname, '../../../'),
|
|
|
|
themePath = path.resolve(appRoot + '/content/themes'),
|
|
|
|
pluginPath = path.resolve(appRoot + '/content/plugins'),
|
|
|
|
themeDirectories = requireTree(themePath),
|
|
|
|
pluginDirectories = requireTree(pluginPath),
|
2013-12-06 12:51:35 +04:00
|
|
|
localPath = '',
|
2013-11-20 17:58:52 +04:00
|
|
|
availableThemes,
|
2013-12-06 12:51:35 +04:00
|
|
|
|
2013-11-20 17:58:52 +04:00
|
|
|
availablePlugins;
|
|
|
|
|
|
|
|
|
|
|
|
function getPaths() {
|
|
|
|
return {
|
|
|
|
'appRoot': appRoot,
|
2013-12-06 12:51:35 +04:00
|
|
|
'path': localPath,
|
|
|
|
'webroot': localPath === '/' ? '' : localPath,
|
2013-11-26 07:22:59 +04:00
|
|
|
'config': path.join(appRoot, 'config.js'),
|
|
|
|
'configExample': path.join(appRoot, 'config.example.js'),
|
2013-11-20 17:58:52 +04:00
|
|
|
'themePath': themePath,
|
|
|
|
'pluginPath': pluginPath,
|
|
|
|
'adminViews': path.join(appRoot, '/core/server/views/'),
|
|
|
|
'helperTemplates': path.join(appRoot, '/core/server/helpers/tpl/'),
|
|
|
|
'lang': path.join(appRoot, '/core/shared/lang/'),
|
|
|
|
'availableThemes': availableThemes,
|
|
|
|
'availablePlugins': availablePlugins
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-12-06 12:51:35 +04:00
|
|
|
// 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(/\/$/, '');
|
|
|
|
}
|
2013-11-20 17:58:52 +04:00
|
|
|
|
|
|
|
return when.all([themeDirectories, pluginDirectories]).then(function (paths) {
|
|
|
|
availableThemes = paths[0];
|
|
|
|
availablePlugins = paths[1];
|
|
|
|
return;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = getPaths;
|
|
|
|
|
|
|
|
module.exports.updatePaths = updatePaths;
|