Ghost/core/server/services/route-settings/index.js
Naz d4cd1bb865 Refactored ensure settings module into a class with DI
refs https://linear.app/tryghost/issue/CORE-35/refactor-route-and-redirect-settings

- Ensure settings had only one method but would benefit from class+DI pattern before extracting it into an outside module.
- The logic is now also less coupled with "routes" and single source/destination paths. It's all configureable instead and might be reused if similar pattern is needed for example with redirect settings defaults.
2021-09-29 20:56:55 +02:00

30 lines
938 B
JavaScript

const routeSettings = require('./route-settings');
const SettingsLoader = require('./loader');
const config = require('../../../shared/config');
const DefaultSettingsManager = require('./default-settings-manager');
const defaultSettingsManager = new DefaultSettingsManager({
type: 'routes',
extension: '.yaml',
destinationFolderPath: config.getContentPath('settings'),
sourceFolderPath: config.get('paths').defaultSettings
});
module.exports = {
init: async () => {
return await defaultSettingsManager.ensureSettingsFileExists();
},
loadRouteSettingsSync: SettingsLoader.loadSettingsSync,
loadRouteSettings: SettingsLoader.loadSettings,
getDefaultHash: routeSettings.getDefaultHash,
/**
* Methods used in the API
*/
api: {
setFromFilePath: routeSettings.setFromFilePath,
get: routeSettings.get,
getCurrentHash: routeSettings.getCurrentHash
}
};