@@ -54,14 +54,28 @@ const getEnvironment = (): Environment => {
5454 return environment ;
5555} ;
5656
57- const getLocalConfigPath = ( env : Environment ) => {
57+ /**
58+ * Get the path of the default config file.
59+ */
60+ const getDefaultConfigPath = ( ) => {
61+
5862 // default to config/config.yml
59- let localConfigPath = join ( CONFIG_PATH , 'config.yml' ) ;
63+ let defaultConfigPath = join ( CONFIG_PATH , 'config.yml' ) ;
6064
61- if ( ! fs . existsSync ( localConfigPath ) ) {
62- localConfigPath = join ( CONFIG_PATH , 'config.yaml' ) ;
65+ if ( ! fs . existsSync ( defaultConfigPath ) ) {
66+ defaultConfigPath = join ( CONFIG_PATH , 'config.yaml' ) ;
6367 }
6468
69+ return defaultConfigPath ;
70+ } ;
71+
72+ /**
73+ * Get the path of an environment-specific config file.
74+ *
75+ * @param env the environment to get the config file for
76+ */
77+ const getEnvConfigFilePath = ( env : Environment ) => {
78+
6579 // determine app config filename variations
6680 let envVariations ;
6781 switch ( env ) {
@@ -76,22 +90,21 @@ const getLocalConfigPath = (env: Environment) => {
7690 envVariations = [ 'dev' , 'development' ] ;
7791 }
7892
93+ let envLocalConfigPath ;
94+
7995 // check if any environment variations of app config exist
8096 for ( const envVariation of envVariations ) {
81- let envLocalConfigPath = join ( CONFIG_PATH , `config.${ envVariation } .yml` ) ;
97+ envLocalConfigPath = join ( CONFIG_PATH , `config.${ envVariation } .yml` ) ;
98+ if ( fs . existsSync ( envLocalConfigPath ) ) {
99+ break ;
100+ }
101+ envLocalConfigPath = join ( CONFIG_PATH , `config.${ envVariation } .yaml` ) ;
82102 if ( fs . existsSync ( envLocalConfigPath ) ) {
83- localConfigPath = envLocalConfigPath ;
84103 break ;
85- } else {
86- envLocalConfigPath = join ( CONFIG_PATH , `config.${ envVariation } .yaml` ) ;
87- if ( fs . existsSync ( envLocalConfigPath ) ) {
88- localConfigPath = envLocalConfigPath ;
89- break ;
90- }
91104 }
92105 }
93106
94- return localConfigPath ;
107+ return envLocalConfigPath ;
95108} ;
96109
97110const overrideWithConfig = ( config : Config , pathToConfig : string ) => {
@@ -174,12 +187,20 @@ export const buildAppConfig = (destConfigPath?: string): AppConfig => {
174187 console . log ( `Building ${ colors . green . bold ( `development` ) } app config` ) ;
175188 }
176189
177- // override with dist config
178- const localConfigPath = getLocalConfigPath ( env ) ;
190+ // override with default config
191+ const defaultConfigPath = getDefaultConfigPath ( ) ;
192+ if ( fs . existsSync ( defaultConfigPath ) ) {
193+ overrideWithConfig ( appConfig , defaultConfigPath ) ;
194+ } else {
195+ console . warn ( `Unable to find default config file at ${ defaultConfigPath } ` ) ;
196+ }
197+
198+ // override with env config
199+ const localConfigPath = getEnvConfigFilePath ( env ) ;
179200 if ( fs . existsSync ( localConfigPath ) ) {
180201 overrideWithConfig ( appConfig , localConfigPath ) ;
181202 } else {
182- console . warn ( `Unable to find dist config file at ${ localConfigPath } ` ) ;
203+ console . warn ( `Unable to find env config file at ${ localConfigPath } ` ) ;
183204 }
184205
185206 // override with external config if specified by environment variable `DSPACE_APP_CONFIG_PATH`
0 commit comments