0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Add Ghost version to config object.

No Issue
- Use Ghost version value that is already loaded instead of
  reading package.json from the filesystem and parsing it on
  every call into the configuration API.
This commit is contained in:
Jason Williams 2014-11-28 17:47:32 +00:00
parent 1db30f896f
commit 1d562c8914
4 changed files with 21 additions and 28 deletions

View file

@ -3,7 +3,6 @@
var _ = require('lodash'),
config = require('../config'),
errors = require('../errors'),
parsePackageJson = require('../require-tree').parsePackageJson,
Promise = require('bluebird'),
configuration;
@ -13,17 +12,14 @@ function getValidKeys() {
fileStorage: config.fileStorage === false ? false : true,
apps: config.apps === true ? true : false,
tagsUI: config.tagsUI === true ? true : false,
version: false,
version: config.ghostVersion,
environment: process.env.NODE_ENV,
database: config.database.client,
mail: _.isObject(config.mail) ? config.mail.transport : '',
blogUrl: config.url
};
return parsePackageJson('package.json').then(function (json) {
validKeys.version = json.version;
return validKeys;
});
return validKeys;
}
/**
@ -39,14 +35,12 @@ configuration = {
* @returns {Promise(Configurations)}
*/
browse: function browse() {
return getValidKeys().then(function (result) {
return Promise.resolve({configuration: _.map(result, function (value, key) {
return {
key: key,
value: value
};
})});
});
return Promise.resolve({configuration: _.map(getValidKeys(), function (value, key) {
return {
key: key,
value: value
};
})});
},
/**
@ -54,16 +48,16 @@ configuration = {
*
*/
read: function read(options) {
return getValidKeys().then(function (result) {
if (_.has(result, options.key)) {
return Promise.resolve({configuration: [{
key: options.key,
value: result[options.key]
}]});
} else {
return Promise.reject(new errors.NotFoundError('Invalid key'));
}
});
var data = getValidKeys();
if (_.has(data, options.key)) {
return Promise.resolve({configuration: [{
key: options.key,
value: data[options.key]
}]});
} else {
return Promise.reject(new errors.NotFoundError('Invalid key'));
}
}
};

View file

@ -112,6 +112,7 @@ ConfigManager.prototype.set = function (config) {
database: {
knex: knexInstance
},
ghostVersion: packageInfo.version,
paths: {
appRoot: appRoot,
subdir: subdir,

View file

@ -12,7 +12,6 @@ var api = require('../api'),
hbs = require('express-hbs'),
logger = require('morgan'),
middleware = require('./middleware'),
packageInfo = require('../../../package.json'),
path = require('path'),
routes = require('../routes'),
slashes = require('connect-slashes'),
@ -36,7 +35,7 @@ var api = require('../api'),
function ghostLocals(req, res, next) {
// Make sure we have a locals value.
res.locals = res.locals || {};
res.locals.version = packageInfo.version;
res.locals.version = config.ghostVersion;
// relative path from the URL
res.locals.relativeUrl = req.path;

View file

@ -30,12 +30,11 @@ var crypto = require('crypto'),
api = require('./api'),
config = require('./config'),
errors = require('./errors'),
packageInfo = require('../../package.json'),
internal = {context: {internal: true}},
allowedCheckEnvironments = ['development', 'production'],
checkEndpoint = 'updates.ghost.org',
currentVersion = packageInfo.version;
currentVersion = config.ghostVersion;
function updateCheckError(error) {
api.settings.edit(