mirror of
https://github.com/Terncode/pixel.horse.git
synced 2026-09-24 13:55:04 +02:00
Merge pull request #32 from Stubenhocker1399/no-such-file-settings
Create settings file if it does not exist
This commit is contained in:
@@ -14,8 +14,18 @@ const settingsPath = paths.pathTo('settings', `settings.json`);
|
||||
|
||||
/* istanbul ignore next */
|
||||
export async function loadSettings() {
|
||||
const json = await readFileAsync(settingsPath, 'utf8');
|
||||
return JSON.parse(json) as Settings;
|
||||
try {
|
||||
const json = await readFileAsync(settingsPath, 'utf8');
|
||||
return JSON.parse(json) as Settings;
|
||||
} catch (e) {
|
||||
if (e === 'ENOENT') {
|
||||
writeFileAsync(settingsPath, '{}', 'utf8');
|
||||
return {} as Settings;
|
||||
} else {
|
||||
console.log("Error reading settings file: " + e);
|
||||
return {} as Settings;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* istanbul ignore next */
|
||||
|
||||
Reference in New Issue
Block a user