-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved apps to /services/ & moved individual tests (#9187)
refs #9178 * Moved app handling code into services/apps - Apps is a service, that allows for the App lifecycle - /server/apps = contains internal apps - /server/services/apps = contains code for managing/handling app life cycle, providing the proxy, etc * Split apps service tests into separate files * Moved internal app tests into test folders - Problem: Not all the tests in apps were unit tests, yet they were treated like they were in Gruntfile.js - Unit tests now live in /test/unit/apps - Route tests now live in /test/functional/routes/apps - Gruntfile.js has been updated to match * Switch api.read usage for settingsCache * Add tests to cover the basic App lifecycle * Simplify some of the init logic
- Loading branch information
Showing
27 changed files
with
785 additions
and
675 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
core/server/apps/dependencies.js → core/server/services/apps/dependencies.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
var _ = require('lodash'), | ||
fs = require('fs'), | ||
path = require('path'), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
var debug = require('ghost-ignition').debug('services:apps'), | ||
_ = require('lodash'), | ||
Promise = require('bluebird'), | ||
logging = require('../../logging'), | ||
errors = require('../../errors'), | ||
api = require('../../api'), | ||
i18n = require('../../i18n'), | ||
config = require('../../config'), | ||
settingsCache = require('../../settings/cache'), | ||
loader = require('./loader'), | ||
// Internal APps are in config | ||
internalApps = config.get('apps:internal'), | ||
// Holds the available apps | ||
availableApps = {}; | ||
|
||
function recordLoadedApp(name, loadedApp) { | ||
// After loading the app, add it to our hash of loaded apps | ||
availableApps[name] = loadedApp; | ||
return loadedApp; | ||
} | ||
|
||
function saveInstalledApps(installedApps) { | ||
debug('saving begin'); | ||
var currentInstalledApps = settingsCache.get('installed_apps'), | ||
// Never save internal apps | ||
updatedAppsInstalled = _.difference(_.uniq(installedApps.concat(currentInstalledApps)), internalApps); | ||
|
||
if (_.difference(updatedAppsInstalled, currentInstalledApps).length === 0) { | ||
debug('saving unneeded'); | ||
return new Promise.resolve(); | ||
} | ||
|
||
debug('saving settings'); | ||
return api.settings.edit({settings: [{key: 'installed_apps', value: updatedAppsInstalled}]}, {context: {internal: true}}); | ||
} | ||
|
||
module.exports = { | ||
init: function () { | ||
debug('init begin'); | ||
var activeApps = settingsCache.get('active_apps'), | ||
installedApps = settingsCache.get('installed_apps'), | ||
// Load means either activate, or install and activate | ||
// We load all Active Apps, and all Internal Apps | ||
appsToLoad = activeApps.concat(internalApps); | ||
|
||
function loadApp(appName) { | ||
// If internal or already installed, the app only needs activating | ||
if (_.includes(internalApps, appName) || _.includes(installedApps, appName)) { | ||
return loader.activateAppByName(appName).then(function (loadedApp) { | ||
return recordLoadedApp(appName, loadedApp); | ||
}); | ||
} | ||
|
||
// Else first install, then activate the app | ||
return loader.installAppByName(appName).then(function () { | ||
return loader.activateAppByName(appName); | ||
}).then(function (loadedApp) { | ||
return recordLoadedApp(appName, loadedApp); | ||
}); | ||
} | ||
|
||
return Promise.map(appsToLoad, loadApp) | ||
.then(function () { | ||
// Save our installed apps to settings | ||
return saveInstalledApps(_.keys(availableApps)); | ||
}) | ||
.catch(function (err) { | ||
logging.error(new errors.GhostError({ | ||
err: err, | ||
context: i18n.t('errors.apps.appWillNotBeLoaded.error'), | ||
help: i18n.t('errors.apps.appWillNotBeLoaded.help') | ||
})); | ||
}); | ||
}, | ||
availableApps: availableApps | ||
}; |
7 changes: 4 additions & 3 deletions
7
core/server/apps/loader.js → core/server/services/apps/loader.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
core/server/apps/permissions.js → core/server/services/apps/permissions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
core/server/apps/proxy.js → core/server/services/apps/proxy.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 4 additions & 5 deletions
9
core/server/apps/sandbox.js → core/server/services/apps/sandbox.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...er/apps/subscribers/tests/routing_spec.js → ...l/routes/apps/subscribers/routing_spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ver/apps/amp/tests/amp_components_spec.js → ...test/unit/apps/amp/amp_components_spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...erver/apps/default-cards/tests/hr_spec.js → core/test/unit/apps/default-cards/hr_spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ver/apps/default-cards/tests/html_spec.js → ...test/unit/apps/default-cards/html_spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...er/apps/default-cards/tests/image_spec.js → ...est/unit/apps/default-cards/image_spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...apps/default-cards/tests/markdown_spec.js → .../unit/apps/default-cards/markdown_spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...s/default-cards/tests/soft-return_spec.js → ...it/apps/default-cards/soft-return_spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...private-blogging/tests/controller_spec.js → .../apps/private-blogging/controller_spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.