()
| 66 | } |
| 67 | |
| 68 | public static createSettings(): Settings { |
| 69 | if (SettingsStatic._settings) { |
| 70 | return SettingsStatic._settings |
| 71 | } |
| 72 | logger('creating settings') |
| 73 | |
| 74 | const basePath = SettingsStatic.getSettingsFileBasePath() |
| 75 | if (!fs.existsSync(basePath)) { |
| 76 | fs.mkdirSync(basePath) |
| 77 | } |
| 78 | const defaultsFilePath = SettingsStatic.getDefaultSettingsFilePath() |
| 79 | const fileType = SettingsStatic.settingsFileType(basePath) |
| 80 | const settingsFilePath = join(basePath, `settings.${fileType}`) |
| 81 | |
| 82 | const defaults = SettingsStatic.loadSettings(defaultsFilePath, SettingsFileTypes.yaml) |
| 83 | |
| 84 | try { |
| 85 | if (fileType) { |
| 86 | SettingsStatic._settings = mergeDeepRight(defaults, SettingsStatic.loadSettings(settingsFilePath, fileType)) |
| 87 | } else { |
| 88 | SettingsStatic.saveSettings(basePath, defaults) |
| 89 | SettingsStatic._settings = mergeDeepRight({}, defaults) |
| 90 | } |
| 91 | |
| 92 | if (typeof SettingsStatic._settings === 'undefined') { |
| 93 | throw new Error('Unable to set settings') |
| 94 | } |
| 95 | |
| 96 | return SettingsStatic._settings |
| 97 | } catch (error) { |
| 98 | logger('error reading config file at %s: %o', settingsFilePath, error) |
| 99 | |
| 100 | return defaults |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | public static saveSettings(path: string, settings: Settings) { |
| 105 | logger('saving settings to %s: %o', path, settings) |
no test coverage detected