mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
f16dc290b7
addresses #1789, #1364 - Moves ./core/server/loader -> ./core/bootstrap. The bootstrap file is only accessed once during startup, and it’s sole job is to ensure a config.js file exists (creating one if it doesn’t) and then validates the contents of the config file. Since this is directly related to the initializing the application is is appropriate to have it in the ./core folder, named bootstrap as that is what it does. This also improves the dependency graph, as now the bootstrap file require’s the ./core/server/config module and is responsible for passing in the validated config file. Whereas before we had ./core/server/config require’ing ./core/server/loader and running its init code and then passing that value back to itself, the flow is now more straight forward of ./core/bootstrap handling initialization and then instatiation of config module - Merges ./core/server/config/paths into ./core/server/config This flow was always confusing me to that some config options were on the config object, and some were on the paths object. This change now incorporates all of the variables previously defined in config/paths directly into the config module, and in extension, the config.js file. This means that you now have the option of deciding at startup where the content directory for ghost should reside. - broke out loader tests in config_spec to bootstrap_spec - updated all relevant files to now use config().paths - moved urlFor and urlForPost function into ./server/config/url.js
75 lines
No EOL
2.1 KiB
JavaScript
75 lines
No EOL
2.1 KiB
JavaScript
|
|
var path = require('path'),
|
|
_ = require('lodash'),
|
|
when = require('when'),
|
|
appProxy = require('./proxy'),
|
|
config = require('../config'),
|
|
AppSandbox = require('./sandbox'),
|
|
loader;
|
|
|
|
// Get a relative path to the given apps root, defaults
|
|
// to be relative to __dirname
|
|
function getAppRelativePath(name, relativeTo) {
|
|
relativeTo = relativeTo || __dirname;
|
|
|
|
return path.relative(relativeTo, path.join(config().paths.appPath, name));
|
|
}
|
|
|
|
// Load apps through a psuedo sandbox
|
|
function loadApp(appPath) {
|
|
var sandbox = new AppSandbox();
|
|
|
|
return sandbox.loadApp(appPath);
|
|
}
|
|
|
|
function getAppByName(name) {
|
|
// Grab the app class to instantiate
|
|
var AppClass = loadApp(getAppRelativePath(name)),
|
|
app;
|
|
|
|
// Check for an actual class, otherwise just use whatever was returned
|
|
if (_.isFunction(AppClass)) {
|
|
app = new AppClass(appProxy);
|
|
} else {
|
|
app = AppClass;
|
|
}
|
|
|
|
return app;
|
|
}
|
|
|
|
// The loader is responsible for loading apps
|
|
loader = {
|
|
// Load a app and return the instantiated app
|
|
installAppByName: function (name) {
|
|
var app = getAppByName(name);
|
|
|
|
// Check for an install() method on the app.
|
|
if (!_.isFunction(app.install)) {
|
|
return when.reject(new Error("Error loading app named " + name + "; no install() method defined."));
|
|
}
|
|
|
|
// Wrapping the install() with a when because it's possible
|
|
// to not return a promise from it.
|
|
return when(app.install(appProxy)).then(function () {
|
|
return when.resolve(app);
|
|
});
|
|
},
|
|
|
|
// Activate a app and return it
|
|
activateAppByName: function (name) {
|
|
var app = getAppByName(name);
|
|
|
|
// Check for an activate() method on the app.
|
|
if (!_.isFunction(app.activate)) {
|
|
return when.reject(new Error("Error loading app named " + name + "; no activate() method defined."));
|
|
}
|
|
|
|
// Wrapping the activate() with a when because it's possible
|
|
// to not return a promise from it.
|
|
return when(app.activate(appProxy)).then(function () {
|
|
return when.resolve(app);
|
|
});
|
|
}
|
|
};
|
|
|
|
module.exports = loader; |