mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 11:55:03 +03:00
Merge pull request #1569 from hswolff/ghost-module-support
This commit is contained in:
commit
5566840d82
@ -6,7 +6,7 @@ var path = require('path'),
|
||||
spawn = require('child_process').spawn,
|
||||
buildDirectory = path.resolve(process.cwd(), '.build'),
|
||||
distDirectory = path.resolve(process.cwd(), '.dist'),
|
||||
configLoader = require('./core/server/config/loader'),
|
||||
config = require('./core/server/config'),
|
||||
|
||||
buildGlob = [
|
||||
'**',
|
||||
@ -499,7 +499,7 @@ var path = require('path'),
|
||||
|
||||
grunt.registerTask('loadConfig', function () {
|
||||
var done = this.async();
|
||||
configLoader().then(function () {
|
||||
config.load().then(function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
17
core/index.js
Normal file
17
core/index.js
Normal file
@ -0,0 +1,17 @@
|
||||
// # Ghost bootloader
|
||||
// Orchestrates the loading of Ghost
|
||||
// When run from command line.
|
||||
|
||||
var config = require('./server/config'),
|
||||
errors = require('./server/errorHandling');
|
||||
|
||||
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
||||
|
||||
function startGhost(app) {
|
||||
config.load().then(function () {
|
||||
var ghost = require('./server');
|
||||
ghost(app);
|
||||
}).otherwise(errors.logAndThrowError);
|
||||
}
|
||||
|
||||
module.exports = startGhost;
|
@ -1,16 +1,28 @@
|
||||
|
||||
var ghostConfig = require('../../../config'),
|
||||
loader = require('./loader'),
|
||||
paths = require('./paths');
|
||||
var loader = require('./loader'),
|
||||
paths = require('./paths'),
|
||||
ghostConfig;
|
||||
|
||||
|
||||
function configIndex() {
|
||||
return ghostConfig[process.env.NODE_ENV];
|
||||
// Returns NODE_ENV config object
|
||||
function config() {
|
||||
// @TODO: get rid of require statement.
|
||||
// This is currently needed for tests to load config file
|
||||
// successfully. While running application we should never
|
||||
// have to directly delegate to the config.js file.
|
||||
return ghostConfig || require(paths().config)[process.env.NODE_ENV];
|
||||
}
|
||||
|
||||
function loadConfig() {
|
||||
return loader().then(function (config) {
|
||||
// Cache the config.js object's environment
|
||||
// object so we can later refer to it.
|
||||
// Note: this is not the entirity of config.js,
|
||||
// just the object appropriate for this NODE_ENV
|
||||
ghostConfig = config;
|
||||
});
|
||||
}
|
||||
|
||||
configIndex.loader = loader;
|
||||
configIndex.paths = paths;
|
||||
config.load = loadConfig;
|
||||
config.paths = paths;
|
||||
|
||||
|
||||
module.exports = configIndex;
|
||||
module.exports = config;
|
@ -3,10 +3,11 @@ var fs = require('fs'),
|
||||
when = require('when'),
|
||||
errors = require('../errorHandling'),
|
||||
path = require('path'),
|
||||
paths = require('./paths'),
|
||||
|
||||
appRoot = path.resolve(__dirname, '../../../'),
|
||||
configexample = path.join(appRoot, 'config.example.js'),
|
||||
config = path.join(appRoot, 'config.js');
|
||||
appRoot = paths().appRoot,
|
||||
configexample = paths().configExample,
|
||||
config = paths().config;
|
||||
|
||||
function writeConfigFile() {
|
||||
var written = when.defer();
|
||||
@ -83,19 +84,19 @@ function validateConfigEnvironment() {
|
||||
return when.reject();
|
||||
}
|
||||
|
||||
return when.resolve();
|
||||
return when.resolve(config);
|
||||
}
|
||||
|
||||
function loadConfig() {
|
||||
var loaded = when.defer();
|
||||
var loaded = when.defer(),
|
||||
pendingConfig;
|
||||
/* Check for config file and copy from config.example.js
|
||||
if one doesn't exist. After that, start the server. */
|
||||
fs.exists(config, function checkConfig(configExists) {
|
||||
if (configExists) {
|
||||
validateConfigEnvironment().then(loaded.resolve).otherwise(loaded.reject);
|
||||
} else {
|
||||
writeConfigFile().then(validateConfigEnvironment).then(loaded.resolve).otherwise(loaded.reject);
|
||||
if (!configExists) {
|
||||
pendingConfig = writeConfigFile();
|
||||
}
|
||||
when(pendingConfig).then(validateConfigEnvironment).then(loaded.resolve).otherwise(loaded.reject);
|
||||
});
|
||||
return loaded.promise;
|
||||
}
|
||||
|
@ -16,6 +16,8 @@ var path = require('path'),
|
||||
function getPaths() {
|
||||
return {
|
||||
'appRoot': appRoot,
|
||||
'config': path.join(appRoot, 'config.js'),
|
||||
'configExample': path.join(appRoot, 'config.example.js'),
|
||||
'themePath': themePath,
|
||||
'pluginPath': pluginPath,
|
||||
'activeTheme': path.join(themePath, activeTheme),
|
||||
|
@ -3,20 +3,20 @@
|
||||
// modules to ensure config gets right setting.
|
||||
|
||||
// Module dependencies
|
||||
var config = require('./server/config'),
|
||||
var config = require('./config'),
|
||||
express = require('express'),
|
||||
when = require('when'),
|
||||
_ = require('underscore'),
|
||||
semver = require('semver'),
|
||||
fs = require('fs'),
|
||||
errors = require('./server/errorHandling'),
|
||||
plugins = require('./server/plugins'),
|
||||
errors = require('./errorHandling'),
|
||||
plugins = require('./plugins'),
|
||||
path = require('path'),
|
||||
Ghost = require('./ghost'),
|
||||
helpers = require('./server/helpers'),
|
||||
middleware = require('./server/middleware'),
|
||||
routes = require('./server/routes'),
|
||||
packageInfo = require('../package.json'),
|
||||
Ghost = require('../ghost'),
|
||||
helpers = require('./helpers'),
|
||||
middleware = require('./middleware'),
|
||||
routes = require('./routes'),
|
||||
packageInfo = require('../../package.json'),
|
||||
|
||||
// Variables
|
||||
ghost = new Ghost(),
|
@ -14,7 +14,7 @@ var middleware = require('./middleware'),
|
||||
config = require('../config'),
|
||||
storage = require('../storage'),
|
||||
packageInfo = require('../../../package.json'),
|
||||
BSStore = require('../../bookshelf-session'),
|
||||
BSStore = require('../bookshelf-session'),
|
||||
|
||||
ghost = new Ghost();
|
||||
|
||||
|
@ -4,14 +4,14 @@ var ghostBookshelf,
|
||||
moment = require('moment'),
|
||||
_ = require('underscore'),
|
||||
uuid = require('node-uuid'),
|
||||
config = require('../../../config'),
|
||||
config = require('../config'),
|
||||
Validator = require('validator').Validator,
|
||||
unidecode = require('unidecode'),
|
||||
sanitize = require('validator').sanitize;
|
||||
|
||||
// Initializes a new Bookshelf instance, for reference elsewhere in Ghost.
|
||||
ghostBookshelf = Bookshelf.ghost = Bookshelf.initialize(config[process.env.NODE_ENV].database);
|
||||
ghostBookshelf.client = config[process.env.NODE_ENV].database.client;
|
||||
ghostBookshelf = Bookshelf.ghost = Bookshelf.initialize(config().database);
|
||||
ghostBookshelf.client = config().database.client;
|
||||
|
||||
ghostBookshelf.validator = new Validator();
|
||||
|
||||
|
@ -8,7 +8,6 @@ var Post,
|
||||
github = require('../../shared/vendor/showdown/extensions/github'),
|
||||
converter = new Showdown.converter({extensions: [github]}),
|
||||
User = require('./user').User,
|
||||
config = require('../../../config'),
|
||||
Tag = require('./tag').Tag,
|
||||
Tags = require('./tag').Tags,
|
||||
ghostBookshelf = require('./base');
|
||||
|
10
index.js
10
index.js
@ -2,12 +2,6 @@
|
||||
// Orchestrates the loading of Ghost
|
||||
// When run from command line.
|
||||
|
||||
var configLoader = require('./core/server/config/loader'),
|
||||
errors = require('./core/server/errorHandling');
|
||||
var ghost = require('./core');
|
||||
|
||||
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
||||
|
||||
configLoader().then(function () {
|
||||
var ghost = require('./core/server');
|
||||
ghost();
|
||||
}).otherwise(errors.logAndThrowError);
|
||||
ghost();
|
@ -22,7 +22,7 @@
|
||||
"url": "https://raw.github.com/TryGhost/Ghost/master/LICENSE"
|
||||
}
|
||||
],
|
||||
"main": "./core/server",
|
||||
"main": "./core/index",
|
||||
"scripts": {
|
||||
"start": "node index",
|
||||
"test": "grunt validate --verbose"
|
||||
|
Loading…
Reference in New Issue
Block a user