2021-09-29 13:56:55 -05:00
|
|
|
const config = require('../../../shared/config');
|
2021-09-30 10:33:17 -05:00
|
|
|
const parseYaml = require('./yaml-parser');
|
2021-11-23 11:17:38 -05:00
|
|
|
const SettingsPathManager = require('@tryghost/settings-path-manager');
|
2021-09-29 13:56:55 -05:00
|
|
|
|
2021-11-23 03:38:49 -05:00
|
|
|
let settingsLoader;
|
|
|
|
let routeSettings;
|
2021-09-30 14:07:38 -05:00
|
|
|
|
2021-09-28 02:47:42 -05:00
|
|
|
module.exports = {
|
|
|
|
init: async () => {
|
2021-11-23 03:38:49 -05:00
|
|
|
const RouteSettings = require('./route-settings');
|
|
|
|
const SettingsLoader = require('./settings-loader');
|
|
|
|
const DefaultSettingsManager = require('./default-settings-manager');
|
|
|
|
|
2021-11-23 11:17:38 -05:00
|
|
|
const settingsPathManager = new SettingsPathManager({type: 'routes', paths: [config.getContentPath('settings')]});
|
|
|
|
settingsLoader = new SettingsLoader({parseYaml, settingFilePath: settingsPathManager.getDefaultFilePath()});
|
|
|
|
routeSettings = new RouteSettings({
|
|
|
|
settingsLoader,
|
|
|
|
settingsPath: settingsPathManager.getDefaultFilePath(),
|
|
|
|
backupPath: settingsPathManager.getBackupFilePath()
|
|
|
|
});
|
2021-11-23 03:38:49 -05:00
|
|
|
const defaultSettingsManager = new DefaultSettingsManager({
|
|
|
|
type: 'routes',
|
|
|
|
extension: '.yaml',
|
|
|
|
destinationFolderPath: config.getContentPath('settings'),
|
|
|
|
sourceFolderPath: config.get('paths').defaultSettings
|
|
|
|
});
|
|
|
|
|
2021-09-29 13:56:55 -05:00
|
|
|
return await defaultSettingsManager.ensureSettingsFileExists();
|
2021-09-28 02:47:42 -05:00
|
|
|
},
|
|
|
|
|
2021-11-23 03:38:49 -05:00
|
|
|
get loadRouteSettingsSync() {
|
|
|
|
return settingsLoader.loadSettingsSync.bind(settingsLoader);
|
|
|
|
},
|
|
|
|
get loadRouteSettings() {
|
|
|
|
return settingsLoader.loadSettings.bind(settingsLoader);
|
|
|
|
},
|
|
|
|
get getDefaultHash() {
|
|
|
|
return routeSettings.getDefaultHash.bind(routeSettings);
|
|
|
|
},
|
|
|
|
|
2021-09-28 02:47:42 -05:00
|
|
|
/**
|
|
|
|
* Methods used in the API
|
|
|
|
*/
|
|
|
|
api: {
|
2021-11-23 03:38:49 -05:00
|
|
|
get setFromFilePath() {
|
|
|
|
return routeSettings.setFromFilePath.bind(routeSettings);
|
|
|
|
},
|
|
|
|
get get() {
|
|
|
|
return routeSettings.get.bind(routeSettings);
|
|
|
|
},
|
|
|
|
get getCurrentHash() {
|
|
|
|
return routeSettings.getCurrentHash.bind(routeSettings);
|
|
|
|
}
|
2021-09-28 02:47:42 -05:00
|
|
|
}
|
|
|
|
};
|