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:
parent
1db30f896f
commit
1d562c8914
4 changed files with 21 additions and 28 deletions
|
@ -3,7 +3,6 @@
|
||||||
var _ = require('lodash'),
|
var _ = require('lodash'),
|
||||||
config = require('../config'),
|
config = require('../config'),
|
||||||
errors = require('../errors'),
|
errors = require('../errors'),
|
||||||
parsePackageJson = require('../require-tree').parsePackageJson,
|
|
||||||
Promise = require('bluebird'),
|
Promise = require('bluebird'),
|
||||||
|
|
||||||
configuration;
|
configuration;
|
||||||
|
@ -13,17 +12,14 @@ function getValidKeys() {
|
||||||
fileStorage: config.fileStorage === false ? false : true,
|
fileStorage: config.fileStorage === false ? false : true,
|
||||||
apps: config.apps === true ? true : false,
|
apps: config.apps === true ? true : false,
|
||||||
tagsUI: config.tagsUI === true ? true : false,
|
tagsUI: config.tagsUI === true ? true : false,
|
||||||
version: false,
|
version: config.ghostVersion,
|
||||||
environment: process.env.NODE_ENV,
|
environment: process.env.NODE_ENV,
|
||||||
database: config.database.client,
|
database: config.database.client,
|
||||||
mail: _.isObject(config.mail) ? config.mail.transport : '',
|
mail: _.isObject(config.mail) ? config.mail.transport : '',
|
||||||
blogUrl: config.url
|
blogUrl: config.url
|
||||||
};
|
};
|
||||||
|
|
||||||
return parsePackageJson('package.json').then(function (json) {
|
return validKeys;
|
||||||
validKeys.version = json.version;
|
|
||||||
return validKeys;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,14 +35,12 @@ configuration = {
|
||||||
* @returns {Promise(Configurations)}
|
* @returns {Promise(Configurations)}
|
||||||
*/
|
*/
|
||||||
browse: function browse() {
|
browse: function browse() {
|
||||||
return getValidKeys().then(function (result) {
|
return Promise.resolve({configuration: _.map(getValidKeys(), function (value, key) {
|
||||||
return Promise.resolve({configuration: _.map(result, function (value, key) {
|
return {
|
||||||
return {
|
key: key,
|
||||||
key: key,
|
value: value
|
||||||
value: value
|
};
|
||||||
};
|
})});
|
||||||
})});
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,16 +48,16 @@ configuration = {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
read: function read(options) {
|
read: function read(options) {
|
||||||
return getValidKeys().then(function (result) {
|
var data = getValidKeys();
|
||||||
if (_.has(result, options.key)) {
|
|
||||||
return Promise.resolve({configuration: [{
|
if (_.has(data, options.key)) {
|
||||||
key: options.key,
|
return Promise.resolve({configuration: [{
|
||||||
value: result[options.key]
|
key: options.key,
|
||||||
}]});
|
value: data[options.key]
|
||||||
} else {
|
}]});
|
||||||
return Promise.reject(new errors.NotFoundError('Invalid key'));
|
} else {
|
||||||
}
|
return Promise.reject(new errors.NotFoundError('Invalid key'));
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -112,6 +112,7 @@ ConfigManager.prototype.set = function (config) {
|
||||||
database: {
|
database: {
|
||||||
knex: knexInstance
|
knex: knexInstance
|
||||||
},
|
},
|
||||||
|
ghostVersion: packageInfo.version,
|
||||||
paths: {
|
paths: {
|
||||||
appRoot: appRoot,
|
appRoot: appRoot,
|
||||||
subdir: subdir,
|
subdir: subdir,
|
||||||
|
|
|
@ -12,7 +12,6 @@ var api = require('../api'),
|
||||||
hbs = require('express-hbs'),
|
hbs = require('express-hbs'),
|
||||||
logger = require('morgan'),
|
logger = require('morgan'),
|
||||||
middleware = require('./middleware'),
|
middleware = require('./middleware'),
|
||||||
packageInfo = require('../../../package.json'),
|
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
routes = require('../routes'),
|
routes = require('../routes'),
|
||||||
slashes = require('connect-slashes'),
|
slashes = require('connect-slashes'),
|
||||||
|
@ -36,7 +35,7 @@ var api = require('../api'),
|
||||||
function ghostLocals(req, res, next) {
|
function ghostLocals(req, res, next) {
|
||||||
// Make sure we have a locals value.
|
// Make sure we have a locals value.
|
||||||
res.locals = res.locals || {};
|
res.locals = res.locals || {};
|
||||||
res.locals.version = packageInfo.version;
|
res.locals.version = config.ghostVersion;
|
||||||
// relative path from the URL
|
// relative path from the URL
|
||||||
res.locals.relativeUrl = req.path;
|
res.locals.relativeUrl = req.path;
|
||||||
|
|
||||||
|
|
|
@ -30,12 +30,11 @@ var crypto = require('crypto'),
|
||||||
api = require('./api'),
|
api = require('./api'),
|
||||||
config = require('./config'),
|
config = require('./config'),
|
||||||
errors = require('./errors'),
|
errors = require('./errors'),
|
||||||
packageInfo = require('../../package.json'),
|
|
||||||
|
|
||||||
internal = {context: {internal: true}},
|
internal = {context: {internal: true}},
|
||||||
allowedCheckEnvironments = ['development', 'production'],
|
allowedCheckEnvironments = ['development', 'production'],
|
||||||
checkEndpoint = 'updates.ghost.org',
|
checkEndpoint = 'updates.ghost.org',
|
||||||
currentVersion = packageInfo.version;
|
currentVersion = config.ghostVersion;
|
||||||
|
|
||||||
function updateCheckError(error) {
|
function updateCheckError(error) {
|
||||||
api.settings.edit(
|
api.settings.edit(
|
||||||
|
|
Loading…
Add table
Reference in a new issue