mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
7f0bf62ec9
refs https://github.com/TryGhost/Toolbox/issues/214 - The `defaultSettings` path name in the config (one pointing to routes yaml file) creates confusion with the `defaultSettings` which populate defaults for in the database settings table. - Furthermore, the name collision creates a problem when trying to make database default settings dynamic - being able to load them from configurable file path. - Rename makes "routing" explicit to avoid ambiguity and free up the name for the database defaults - The value seems to be safe to be renamed as all keys used in `overrides.json` are taking priority - the name "defaultRouteSettings" hasn't surfaced at any point in the git history
55 lines
1.9 KiB
JavaScript
55 lines
1.9 KiB
JavaScript
const config = require('../../../shared/config');
|
|
const parseYaml = require('./yaml-parser');
|
|
const SettingsPathManager = require('@tryghost/settings-path-manager');
|
|
|
|
let settingsLoader;
|
|
let routeSettings;
|
|
|
|
module.exports = {
|
|
init: async () => {
|
|
const RouteSettings = require('./route-settings');
|
|
const SettingsLoader = require('./settings-loader');
|
|
const DefaultSettingsManager = require('./default-settings-manager');
|
|
|
|
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()
|
|
});
|
|
const defaultSettingsManager = new DefaultSettingsManager({
|
|
type: 'routes',
|
|
extension: '.yaml',
|
|
destinationFolderPath: config.getContentPath('settings'),
|
|
sourceFolderPath: config.get('paths').defaultRouteSettings
|
|
});
|
|
|
|
return await defaultSettingsManager.ensureSettingsFileExists();
|
|
},
|
|
|
|
get loadRouteSettingsSync() {
|
|
return settingsLoader.loadSettingsSync.bind(settingsLoader);
|
|
},
|
|
get loadRouteSettings() {
|
|
return settingsLoader.loadSettings.bind(settingsLoader);
|
|
},
|
|
get getDefaultHash() {
|
|
return routeSettings.getDefaultHash.bind(routeSettings);
|
|
},
|
|
|
|
/**
|
|
* Methods used in the API
|
|
*/
|
|
api: {
|
|
get setFromFilePath() {
|
|
return routeSettings.setFromFilePath.bind(routeSettings);
|
|
},
|
|
get get() {
|
|
return routeSettings.get.bind(routeSettings);
|
|
},
|
|
get getCurrentHash() {
|
|
return routeSettings.getCurrentHash.bind(routeSettings);
|
|
}
|
|
}
|
|
};
|