mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Adds ability to pass in configFile path when loading
ghost as a npm module - modifies main script file to allow it to take in an options object that currently supports an express instance or a config file path - added tests
This commit is contained in:
parent
37b7907c09
commit
9dd543231b
5 changed files with 35 additions and 16 deletions
11
core/bootstrap.js
vendored
11
core/bootstrap.js
vendored
|
@ -13,8 +13,8 @@ var fs = require('fs'),
|
||||||
|
|
||||||
appRoot = config().paths.appRoot,
|
appRoot = config().paths.appRoot,
|
||||||
configExample = config().paths.configExample,
|
configExample = config().paths.configExample,
|
||||||
configFile = process.env.GHOST_CONFIG || config().paths.config,
|
rejectMessage = 'Unable to load config',
|
||||||
rejectMessage = 'Unable to load config';
|
configFile;
|
||||||
|
|
||||||
function readConfigFile(envVal) {
|
function readConfigFile(envVal) {
|
||||||
return require(configFile)[envVal];
|
return require(configFile)[envVal];
|
||||||
|
@ -103,9 +103,14 @@ function validateConfigEnvironment() {
|
||||||
return when.resolve(config);
|
return when.resolve(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadConfig() {
|
function loadConfig(configFilePath) {
|
||||||
var loaded = when.defer(),
|
var loaded = when.defer(),
|
||||||
pendingConfig;
|
pendingConfig;
|
||||||
|
|
||||||
|
// Allow config file path to be taken from, in order of importance:
|
||||||
|
// environment process, passed in value, default location
|
||||||
|
configFile = process.env.GHOST_CONFIG || configFilePath || config().paths.config;
|
||||||
|
|
||||||
/* Check for config file and copy from config.example.js
|
/* Check for config file and copy from config.example.js
|
||||||
if one doesn't exist. After that, start the server. */
|
if one doesn't exist. After that, start the server. */
|
||||||
fs.exists(configFile, function checkConfig(configExists) {
|
fs.exists(configFile, function checkConfig(configExists) {
|
||||||
|
|
|
@ -7,10 +7,11 @@ var bootstrap = require('./bootstrap'),
|
||||||
|
|
||||||
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
||||||
|
|
||||||
function startGhost(app) {
|
function startGhost(options) {
|
||||||
bootstrap().then(function () {
|
options = options || {};
|
||||||
|
bootstrap(options.config).then(function () {
|
||||||
var ghost = require('./server');
|
var ghost = require('./server');
|
||||||
ghost(app);
|
ghost(options.app);
|
||||||
}).otherwise(errors.logAndThrowError);
|
}).otherwise(errors.logAndThrowError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ function updateConfig(config) {
|
||||||
paths: {
|
paths: {
|
||||||
'appRoot': appRoot,
|
'appRoot': appRoot,
|
||||||
'subdir': subdir,
|
'subdir': subdir,
|
||||||
'config': path.join(appRoot, 'config.js'),
|
'config': ghostConfig.paths.config || path.join(appRoot, 'config.js'),
|
||||||
'configExample': path.join(appRoot, 'config.example.js'),
|
'configExample': path.join(appRoot, 'config.example.js'),
|
||||||
'corePath': corePath,
|
'corePath': corePath,
|
||||||
|
|
||||||
|
|
12
core/test/unit/bootstrap_spec.js
vendored
12
core/test/unit/bootstrap_spec.js
vendored
|
@ -51,6 +51,18 @@ describe('Bootstrap', function () {
|
||||||
}).then(null, done);
|
}).then(null, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('uses the passed in config file location', function (done) {
|
||||||
|
bootstrap(path.join(config().paths.appRoot, 'config.example.js')).then(function (config) {
|
||||||
|
config.url.should.equal(defaultConfig.url);
|
||||||
|
config.database.client.should.equal(defaultConfig.database.client);
|
||||||
|
config.database.connection.should.eql(defaultConfig.database.connection);
|
||||||
|
config.server.host.should.equal(defaultConfig.server.host);
|
||||||
|
config.server.port.should.equal(defaultConfig.server.port);
|
||||||
|
|
||||||
|
done();
|
||||||
|
}).then(null, done);
|
||||||
|
});
|
||||||
|
|
||||||
it('creates the config file if one does not exist', function (done) {
|
it('creates the config file if one does not exist', function (done) {
|
||||||
|
|
||||||
var deferred = when.defer(),
|
var deferred = when.defer(),
|
||||||
|
|
|
@ -69,15 +69,13 @@ describe('Config', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Index', function () {
|
describe('Index', function () {
|
||||||
var defaultContentPath = config().paths.contentPath;
|
// Make a copy of the default config file
|
||||||
|
// so we can restore it after every test.
|
||||||
|
// Using _.merge to recursively apply every property.
|
||||||
|
var defaultConfigFile = _.merge({}, config());
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
configUpdate({
|
configUpdate(defaultConfigFile);
|
||||||
url: defaultConfig.url,
|
|
||||||
paths: {
|
|
||||||
contentPath: defaultContentPath
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have exactly the right keys', function () {
|
it('should have exactly the right keys', function () {
|
||||||
|
@ -136,15 +134,18 @@ describe('Config', function () {
|
||||||
config().paths.should.have.property('subdir', '/my/blog');
|
config().paths.should.have.property('subdir', '/my/blog');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set contentPath and sub-directories correctly', function () {
|
it('should allow specific properties to be user defined', function () {
|
||||||
var contentPath = config().paths.appRoot + '/otherContent/';
|
var contentPath = config().paths.appRoot + '/otherContent/',
|
||||||
|
configFile = 'configFileDanceParty.js';
|
||||||
|
|
||||||
configUpdate({
|
configUpdate({
|
||||||
|
config: configFile,
|
||||||
paths: {
|
paths: {
|
||||||
contentPath: contentPath
|
contentPath: contentPath
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
config().should.have.property('config', configFile);
|
||||||
config().paths.should.have.property('contentPath', contentPath);
|
config().paths.should.have.property('contentPath', contentPath);
|
||||||
config().paths.should.have.property('themePath', contentPath + 'themes');
|
config().paths.should.have.property('themePath', contentPath + 'themes');
|
||||||
config().paths.should.have.property('appPath', contentPath + 'apps');
|
config().paths.should.have.property('appPath', contentPath + 'apps');
|
||||||
|
|
Loading…
Add table
Reference in a new issue