@@ -2,7 +2,7 @@ import { mkdir, readFile, writeFile } from 'fs/promises'
2
2
3
3
import { merge } from 'lodash-es'
4
4
5
- import { themesDirectory , userspaceDirectory , userspaceSettingsPath } from './helpers/paths.js'
5
+ import { themesDirectory , userspaceBombsitesPath , userspaceDirectory , userspaceRadarsPath , userspaceSettingsPath } from './helpers/paths.js'
6
6
import { fileExists } from './helpers/file-exists.js'
7
7
8
8
export const initSettings = async ( ) => {
@@ -16,18 +16,33 @@ export const initSettings = async () => {
16
16
}
17
17
18
18
export const getSettings = async ( ) => {
19
- const settingsObjects = [ await readJson ( userspaceSettingsPath ) ]
20
19
const themeTree = [ 'userspace' ]
21
20
21
+ const bombsiteObjects = [ await readJsonIfExists ( userspaceBombsitesPath ) ]
22
+ const radarObjects = [ await readJsonIfExists ( userspaceRadarsPath ) ]
23
+ const settingsObjects = [ await readJson ( userspaceSettingsPath ) ]
24
+
22
25
while ( settingsObjects [ settingsObjects . length - 1 ] . parent ) {
23
26
themeTree . push ( settingsObjects [ settingsObjects . length - 1 ] . parent )
27
+
24
28
settingsObjects . push (
25
- await readJson ( `${ themesDirectory } /${ settingsObjects [ settingsObjects . length - 1 ] . parent } /theme.json` )
29
+ await readJson ( `${ themesDirectory } /${ settingsObjects [ settingsObjects . length - 1 ] . parent } /theme.json` ) ,
30
+ )
31
+
32
+ bombsiteObjects . push (
33
+ await readJsonIfExists ( `${ themesDirectory } /${ settingsObjects [ settingsObjects . length - 1 ] . parent } /bombsites.json` ) ,
34
+ )
35
+
36
+ radarObjects . push (
37
+ await readJsonIfExists ( `${ themesDirectory } /${ settingsObjects [ settingsObjects . length - 1 ] . parent } /radars.json` ) ,
26
38
)
27
39
}
28
40
29
41
return {
30
42
themeTree,
43
+
44
+ bombsites : merge ( { } , ...bombsiteObjects . reverse ( ) ) ,
45
+ radars : merge ( { } , ...radarObjects . reverse ( ) ) ,
31
46
settings : merge ( { } , ...settingsObjects . reverse ( ) ) ,
32
47
}
33
48
}
@@ -38,3 +53,12 @@ const readJson = async (path) => {
38
53
const str = await readFile ( path , 'utf-8' )
39
54
return JSON . parse ( str )
40
55
}
56
+
57
+ const readJsonIfExists = async ( path ) => {
58
+ try {
59
+ return await readJson ( path )
60
+ } catch ( err ) {
61
+ if ( err . code === 'ENOENT' ) return { }
62
+ throw err
63
+ }
64
+ }
0 commit comments