MCPcopy Index your code
hub / github.com/cameri/nostream / createSettings

Method createSettings

src/utils/settings.ts:68–102  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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)

Callers 5

shared.tsFile · 0.80
setCreatedAtLimitsFunction · 0.80
settings.spec.tsFile · 0.80
createSettingsFunction · 0.80
reloadMethod · 0.80

Calls 5

settingsFileTypeMethod · 0.80
loadSettingsMethod · 0.80
saveSettingsMethod · 0.80

Tested by

no test coverage detected