@@ -4,7 +4,27 @@ const path = require("path")
44const util = require ( "util" )
55const pack = require ( "./package.json" )
66
7- let cachedConfig = false
7+ /**
8+ * Copy deep object values into target object
9+ * @param {Object } core Target object
10+ * @param {Object } override Source object
11+ */
12+ function deepCopyObject ( core , override ) {
13+ // For each core property
14+ for ( let prop in core ) {
15+ // Check if the prop is an deeper object, run this function recursively on it if it is
16+ if ( typeof core [ prop ] == "object" ) {
17+ deepCopyObject ( core [ prop ] , override [ prop ] )
18+ continue
19+ }
20+
21+ // Otherwise, if the prop is set in both the core and overwrite, set it to the overwrite value
22+ if ( typeof override [ prop ] != 'undefined' ) {
23+ core [ prop ] = override [ prop ]
24+ }
25+ }
26+ }
27+
828// Load the default config
929let loadedConfig = JSON5 . parse ( fs . readFileSync ( path . join ( __dirname , "config" , "config.json5" ) , "utf8" ) )
1030
@@ -16,8 +36,8 @@ if (pack.version != loadedConfig._version) {
1636if ( fs . existsSync ( path . join ( __dirname , "config" , "config.override.json5" ) ) ) {
1737 // Read the overwrite file
1838 let override = JSON5 . parse ( fs . readFileSync ( path . join ( __dirname , "config" , "config.override.json5" ) , "utf8" ) )
19- // Merge the configs
20- Object . assign ( loadedConfig , override )
39+ // Set any settings in the core config to the override ones
40+ deepCopyObject ( loadedConfig , override )
2141}
2242
2343// Show config in console if enabled
0 commit comments