mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-26 04:13:30 +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,
|
spawn = require('child_process').spawn,
|
||||||
buildDirectory = path.resolve(process.cwd(), '.build'),
|
buildDirectory = path.resolve(process.cwd(), '.build'),
|
||||||
distDirectory = path.resolve(process.cwd(), '.dist'),
|
distDirectory = path.resolve(process.cwd(), '.dist'),
|
||||||
configLoader = require('./core/server/config/loader'),
|
config = require('./core/server/config'),
|
||||||
|
|
||||||
buildGlob = [
|
buildGlob = [
|
||||||
'**',
|
'**',
|
||||||
@ -499,7 +499,7 @@ var path = require('path'),
|
|||||||
|
|
||||||
grunt.registerTask('loadConfig', function () {
|
grunt.registerTask('loadConfig', function () {
|
||||||
var done = this.async();
|
var done = this.async();
|
||||||
configLoader().then(function () {
|
config.load().then(function () {
|
||||||
done();
|
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'),
|
var loader = require('./loader'),
|
||||||
loader = require('./loader'),
|
paths = require('./paths'),
|
||||||
paths = require('./paths');
|
ghostConfig;
|
||||||
|
|
||||||
|
// Returns NODE_ENV config object
|
||||||
function configIndex() {
|
function config() {
|
||||||
return ghostConfig[process.env.NODE_ENV];
|
// @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;
|
config.load = loadConfig;
|
||||||
configIndex.paths = paths;
|
config.paths = paths;
|
||||||
|
|
||||||
|
module.exports = config;
|
||||||
module.exports = configIndex;
|
|
@ -3,10 +3,11 @@ var fs = require('fs'),
|
|||||||
when = require('when'),
|
when = require('when'),
|
||||||
errors = require('../errorHandling'),
|
errors = require('../errorHandling'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
|
paths = require('./paths'),
|
||||||
|
|
||||||
appRoot = path.resolve(__dirname, '../../../'),
|
appRoot = paths().appRoot,
|
||||||
configexample = path.join(appRoot, 'config.example.js'),
|
configexample = paths().configExample,
|
||||||
config = path.join(appRoot, 'config.js');
|
config = paths().config;
|
||||||
|
|
||||||
function writeConfigFile() {
|
function writeConfigFile() {
|
||||||
var written = when.defer();
|
var written = when.defer();
|
||||||
@ -83,19 +84,19 @@ function validateConfigEnvironment() {
|
|||||||
return when.reject();
|
return when.reject();
|
||||||
}
|
}
|
||||||
|
|
||||||
return when.resolve();
|
return when.resolve(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadConfig() {
|
function loadConfig() {
|
||||||
var loaded = when.defer();
|
var loaded = when.defer(),
|
||||||
|
pendingConfig;
|
||||||
/* 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(config, function checkConfig(configExists) {
|
fs.exists(config, function checkConfig(configExists) {
|
||||||
if (configExists) {
|
if (!configExists) {
|
||||||
validateConfigEnvironment().then(loaded.resolve).otherwise(loaded.reject);
|
pendingConfig = writeConfigFile();
|
||||||
} else {
|
|
||||||
writeConfigFile().then(validateConfigEnvironment).then(loaded.resolve).otherwise(loaded.reject);
|
|
||||||
}
|
}
|
||||||
|
when(pendingConfig).then(validateConfigEnvironment).then(loaded.resolve).otherwise(loaded.reject);
|
||||||
});
|
});
|
||||||
return loaded.promise;
|
return loaded.promise;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@ var path = require('path'),
|
|||||||
function getPaths() {
|
function getPaths() {
|
||||||
return {
|
return {
|
||||||
'appRoot': appRoot,
|
'appRoot': appRoot,
|
||||||
|
'config': path.join(appRoot, 'config.js'),
|
||||||
|
'configExample': path.join(appRoot, 'config.example.js'),
|
||||||
'themePath': themePath,
|
'themePath': themePath,
|
||||||
'pluginPath': pluginPath,
|
'pluginPath': pluginPath,
|
||||||
'activeTheme': path.join(themePath, activeTheme),
|
'activeTheme': path.join(themePath, activeTheme),
|
||||||
|
@ -3,20 +3,20 @@
|
|||||||
// modules to ensure config gets right setting.
|
// modules to ensure config gets right setting.
|
||||||
|
|
||||||
// Module dependencies
|
// Module dependencies
|
||||||
var config = require('./server/config'),
|
var config = require('./config'),
|
||||||
express = require('express'),
|
express = require('express'),
|
||||||
when = require('when'),
|
when = require('when'),
|
||||||
_ = require('underscore'),
|
_ = require('underscore'),
|
||||||
semver = require('semver'),
|
semver = require('semver'),
|
||||||
fs = require('fs'),
|
fs = require('fs'),
|
||||||
errors = require('./server/errorHandling'),
|
errors = require('./errorHandling'),
|
||||||
plugins = require('./server/plugins'),
|
plugins = require('./plugins'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
Ghost = require('./ghost'),
|
Ghost = require('../ghost'),
|
||||||
helpers = require('./server/helpers'),
|
helpers = require('./helpers'),
|
||||||
middleware = require('./server/middleware'),
|
middleware = require('./middleware'),
|
||||||
routes = require('./server/routes'),
|
routes = require('./routes'),
|
||||||
packageInfo = require('../package.json'),
|
packageInfo = require('../../package.json'),
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
ghost = new Ghost(),
|
ghost = new Ghost(),
|
@ -14,7 +14,7 @@ var middleware = require('./middleware'),
|
|||||||
config = require('../config'),
|
config = require('../config'),
|
||||||
storage = require('../storage'),
|
storage = require('../storage'),
|
||||||
packageInfo = require('../../../package.json'),
|
packageInfo = require('../../../package.json'),
|
||||||
BSStore = require('../../bookshelf-session'),
|
BSStore = require('../bookshelf-session'),
|
||||||
|
|
||||||
ghost = new Ghost();
|
ghost = new Ghost();
|
||||||
|
|
||||||
|
@ -4,14 +4,14 @@ var ghostBookshelf,
|
|||||||
moment = require('moment'),
|
moment = require('moment'),
|
||||||
_ = require('underscore'),
|
_ = require('underscore'),
|
||||||
uuid = require('node-uuid'),
|
uuid = require('node-uuid'),
|
||||||
config = require('../../../config'),
|
config = require('../config'),
|
||||||
Validator = require('validator').Validator,
|
Validator = require('validator').Validator,
|
||||||
unidecode = require('unidecode'),
|
unidecode = require('unidecode'),
|
||||||
sanitize = require('validator').sanitize;
|
sanitize = require('validator').sanitize;
|
||||||
|
|
||||||
// Initializes a new Bookshelf instance, for reference elsewhere in Ghost.
|
// Initializes a new Bookshelf instance, for reference elsewhere in Ghost.
|
||||||
ghostBookshelf = Bookshelf.ghost = Bookshelf.initialize(config[process.env.NODE_ENV].database);
|
ghostBookshelf = Bookshelf.ghost = Bookshelf.initialize(config().database);
|
||||||
ghostBookshelf.client = config[process.env.NODE_ENV].database.client;
|
ghostBookshelf.client = config().database.client;
|
||||||
|
|
||||||
ghostBookshelf.validator = new Validator();
|
ghostBookshelf.validator = new Validator();
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ var Post,
|
|||||||
github = require('../../shared/vendor/showdown/extensions/github'),
|
github = require('../../shared/vendor/showdown/extensions/github'),
|
||||||
converter = new Showdown.converter({extensions: [github]}),
|
converter = new Showdown.converter({extensions: [github]}),
|
||||||
User = require('./user').User,
|
User = require('./user').User,
|
||||||
config = require('../../../config'),
|
|
||||||
Tag = require('./tag').Tag,
|
Tag = require('./tag').Tag,
|
||||||
Tags = require('./tag').Tags,
|
Tags = require('./tag').Tags,
|
||||||
ghostBookshelf = require('./base');
|
ghostBookshelf = require('./base');
|
||||||
|
10
index.js
10
index.js
@ -2,12 +2,6 @@
|
|||||||
// Orchestrates the loading of Ghost
|
// Orchestrates the loading of Ghost
|
||||||
// When run from command line.
|
// When run from command line.
|
||||||
|
|
||||||
var configLoader = require('./core/server/config/loader'),
|
var ghost = require('./core');
|
||||||
errors = require('./core/server/errorHandling');
|
|
||||||
|
|
||||||
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
ghost();
|
||||||
|
|
||||||
configLoader().then(function () {
|
|
||||||
var ghost = require('./core/server');
|
|
||||||
ghost();
|
|
||||||
}).otherwise(errors.logAndThrowError);
|
|
@ -22,7 +22,7 @@
|
|||||||
"url": "https://raw.github.com/TryGhost/Ghost/master/LICENSE"
|
"url": "https://raw.github.com/TryGhost/Ghost/master/LICENSE"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"main": "./core/server",
|
"main": "./core/index",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node index",
|
"start": "node index",
|
||||||
"test": "grunt validate --verbose"
|
"test": "grunt validate --verbose"
|
||||||
|
Loading…
Reference in New Issue
Block a user