mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 18:01:36 +03:00
15d9a77092
* moved `server/config` to `shared/config` * updated config import paths in server to use shared * updated config import paths in frontend to use shared * updated config import paths in test to use shared * updated config import paths in root to use shared * trigger regression tests * of course the rebase broke tests
46 lines
1.3 KiB
JavaScript
46 lines
1.3 KiB
JavaScript
const path = require('path');
|
|
const _ = require('lodash');
|
|
const Promise = require('bluebird');
|
|
const {i18n} = require('../../../server/lib/common');
|
|
const config = require('../../../shared/config');
|
|
const Proxy = require('./proxy');
|
|
|
|
// Get the full path to an app by name
|
|
function getAppAbsolutePath(name) {
|
|
return path.join(config.get('paths').internalAppPath, name);
|
|
}
|
|
|
|
function loadApp(name) {
|
|
return require(getAppAbsolutePath(name));
|
|
}
|
|
|
|
function getAppByName(name) {
|
|
// Grab the app class to instantiate
|
|
const AppClass = loadApp(name);
|
|
const proxy = Proxy.getInstance();
|
|
|
|
// Check for an actual class, otherwise just use whatever was returned
|
|
const app = _.isFunction(AppClass) ? new AppClass(proxy) : AppClass;
|
|
|
|
return {
|
|
app,
|
|
proxy
|
|
};
|
|
}
|
|
|
|
module.exports = {
|
|
// Activate a app and return it
|
|
activateAppByName: function (name) {
|
|
const {app, proxy} = getAppByName(name);
|
|
|
|
// Check for an activate() method on the app.
|
|
if (!_.isFunction(app.activate)) {
|
|
return Promise.reject(new Error(i18n.t('errors.apps.noActivateMethodLoadingApp.error', {name: name})));
|
|
}
|
|
|
|
// Wrapping the activate() with a when because it's possible
|
|
// to not return a promise from it.
|
|
return Promise.resolve(app.activate(proxy)).return(app);
|
|
}
|
|
};
|