Ghost/core/server/services/route-settings/index.js
Naz 7619ad31d4 Extracted yaml parsing into DI for settings loader
refs https://linear.app/tryghost/issue/CORE-35/refactor-route-and-redirect-settings

- When the yaml parser is injected through a DI it's easier to test and later on the redirects service initialization would use same pattern with exactly the same yamlParse funciton
- Next step is getting yaml parser into an outside module
- Also simplified getSettingFilePath method while swapping to an updated yaml parser implementation. Now this method function is exactly like the one used in redirects
2021-09-30 17:33:17 +02:00

33 lines
1.1 KiB
JavaScript

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