@@ -36,35 +36,38 @@ function ensureAppDirectoryExists(appDir: string) {
3636// This function does not do any validations on the data
3737// (that should have happened after loading the config)
3838// NOTE: the config is saved as JSON (TOML serialization can be weird)
39- function saveConfig ( configData : Config . Options , outputPath : string ) {
39+ function saveConfig ( configData : Config . FileConfiguration , outputPath : string ) {
4040 // update the config hash on import to account for the
4141 const outputData = JSON . stringify ( configData , null , ' ' ) ;
4242 fs . writeFileSync ( outputPath , outputData , CONFIG_FILE_ENCODING ) ;
4343 log ( 'Written config data to ' , outputPath ) ;
4444}
4545
4646interface ConfigStorePaths {
47- configFilePath : string ;
48- appConfigFilePath : string ;
49- backupConfigFilePath : string ;
50- region : string ;
47+ config : string ;
48+ appConfig : string ;
49+ backupConfig : string ;
5150}
5251
5352export class ConfigStore {
54- data ?: Config . Options = undefined ;
53+ data ?: Config . FileConfiguration = undefined ;
5554 validationResult = { } ;
5655 hasConfigLoaded : boolean = false ;
5756 isValid : boolean = false ;
5857 isUsingBackupConfig : boolean = false ;
5958 lastUpdated : Date ;
6059 loadError : string | undefined ;
60+ usingUI : boolean ;
6161
6262 appConfig : AppConfigData = DEFAULT_APP_CONFIG ;
63- configPaths : ConfigStorePaths ;
63+ filePaths : ConfigStorePaths ;
64+ region : string ;
6465
65- constructor ( configPaths : ConfigStorePaths ) {
66+ constructor ( filePaths : ConfigStorePaths , region : string , usingUI : boolean = false ) {
6667 this . lastUpdated = new Date ( ) ;
67- this . configPaths = configPaths ;
68+ this . filePaths = filePaths ;
69+ this . region = region ;
70+ this . usingUI = usingUI ;
6871 }
6972
7073 getConfig ( ) {
@@ -73,22 +76,22 @@ export class ConfigStore {
7376
7477 // Returns the region of the store
7578 getRegion ( ) {
76- return this . configPaths . region ;
79+ return this . region ;
7780 }
7881
7982 // Returns the path of the user config file
8083 getConfigFilePath ( ) {
81- return this . configPaths . configFilePath ;
84+ return this . filePaths . config ;
8285 }
8386
8487 // Returns the path of the backup config file
8588 getBackupConfigFilePath ( ) {
86- return this . configPaths . backupConfigFilePath ;
89+ return this . filePaths . backupConfig ;
8790 }
8891
8992 // Returns the path of the application config file
9093 getAppConfigFilePath ( ) {
91- return this . configPaths . appConfigFilePath ;
94+ return this . filePaths . appConfig ;
9295 }
9396
9497 // Returns true if the current config is a backup configuration
@@ -213,14 +216,14 @@ export class ConfigStore {
213216 }
214217
215218 // use a backup config and store its 'backupness'
216- useBackupConfig ( configData : Config . Options ) {
219+ useBackupConfig ( configData : Config . FileConfiguration ) {
217220 this . isUsingBackupConfig = true ;
218221 this . lastUpdated = new Date ( ) ;
219222 this . _useConfig ( configData ) ;
220223 }
221224
222225 // use an actual user-provided config and store its 'user-providedness'
223- useUserConfig ( configData : Config . Options , lastUpdateDate : Date ) {
226+ useUserConfig ( configData : Config . FileConfiguration , lastUpdateDate : Date ) {
224227 this . isUsingBackupConfig = false ;
225228 this . lastUpdated = lastUpdateDate ;
226229 this . _useConfig ( configData ) ;
@@ -234,7 +237,7 @@ export class ConfigStore {
234237 }
235238
236239 // use an already validated config as the app config
237- _useConfig ( configData : Config . Options ) {
240+ _useConfig ( configData : Config . FileConfiguration ) {
238241 this . data = configData ;
239242 this . hasConfigLoaded = true ;
240243 this . isValid = true ;
@@ -248,7 +251,7 @@ export class ConfigStore {
248251 }
249252
250253 // Overwrites the existing configuration file with the new data
251- saveNewConfigData ( configData : Config . Options ) {
254+ saveNewConfigData ( configData : Config . FileConfiguration ) {
252255 // before saving ensure that we can save the configuration
253256 ensureAppDirectoryExists ( dirname ( this . getConfigFilePath ( ) ) ) ;
254257 // TODO: maybe do a rename w/ timestamp for backup
@@ -292,7 +295,7 @@ export class ConfigStore {
292295 }
293296}
294297
295- export function makeConfigStore ( storeConfig : ConfigStorePaths ) {
296- if ( ! storeConfig ) throw new Error ( `ConfigStore params MUST be provided.` ) ;
297- return new ConfigStore ( storeConfig ) ;
298+ export function makeConfigStore ( { filePaths , region , usingUI } : { filePaths : ConfigStorePaths , region : string , usingUI : boolean } ) {
299+ if ( ! filePaths || ! region ) throw new Error ( `ConfigStore params MUST be provided.` ) ;
300+ return new ConfigStore ( filePaths , region , usingUI ) ;
298301}
0 commit comments