1
1
import { existsSync , readFileSync } from "node:fs" ;
2
2
import yaml from "yaml" ;
3
+ import { getHelpers } from "./env" ;
3
4
import { logger } from "./logger" ;
4
5
import {
5
6
ConfigArrInstance ,
@@ -12,10 +13,6 @@ import {
12
13
InputConfigSchema ,
13
14
MergedConfigInstance ,
14
15
} from "./types/config.types" ;
15
- import { ROOT_PATH } from "./util" ;
16
-
17
- const CONFIG_LOCATION = process . env . CONFIG_LOCATION ?? `${ ROOT_PATH } /config.yml` ;
18
- const SECRETS_LOCATION = process . env . SECRETS_LOCATION ?? `${ ROOT_PATH } /secrets.yml` ;
19
16
20
17
let config : ConfigSchema ;
21
18
let secrets : any ;
@@ -50,12 +47,14 @@ export const getConfig = (): ConfigSchema => {
50
47
return config ;
51
48
}
52
49
53
- if ( ! existsSync ( CONFIG_LOCATION ) ) {
54
- logger . error ( `Config file in location "${ CONFIG_LOCATION } " does not exists.` ) ;
50
+ const configLocation = getHelpers ( ) . configLocation ;
51
+
52
+ if ( ! existsSync ( configLocation ) ) {
53
+ logger . error ( `Config file in location "${ configLocation } " does not exists.` ) ;
55
54
throw new Error ( "Config file not found." ) ;
56
55
}
57
56
58
- const file = readFileSync ( CONFIG_LOCATION , "utf8" ) ;
57
+ const file = readFileSync ( configLocation , "utf8" ) ;
59
58
60
59
const inputConfig = yaml . parse ( file , { customTags : [ secretsTag , envTag ] } ) as InputConfigSchema ;
61
60
@@ -65,12 +64,14 @@ export const getConfig = (): ConfigSchema => {
65
64
} ;
66
65
67
66
export const readConfigRaw = ( ) : object => {
68
- if ( ! existsSync ( CONFIG_LOCATION ) ) {
69
- logger . error ( `Config file in location "${ CONFIG_LOCATION } " does not exists.` ) ;
67
+ const configLocation = getHelpers ( ) . configLocation ;
68
+
69
+ if ( ! existsSync ( configLocation ) ) {
70
+ logger . error ( `Config file in location "${ configLocation } " does not exists.` ) ;
70
71
throw new Error ( "Config file not found." ) ;
71
72
}
72
73
73
- const file = readFileSync ( CONFIG_LOCATION , "utf8" ) ;
74
+ const file = readFileSync ( configLocation , "utf8" ) ;
74
75
75
76
const inputConfig = yaml . parse ( file , { customTags : [ secretsTag , envTag ] } ) ;
76
77
@@ -82,12 +83,14 @@ export const getSecrets = () => {
82
83
return secrets ;
83
84
}
84
85
85
- if ( ! existsSync ( SECRETS_LOCATION ) ) {
86
- logger . error ( `Secret file in location "${ SECRETS_LOCATION } " does not exists.` ) ;
86
+ const secretLocation = getHelpers ( ) . secretLocation ;
87
+
88
+ if ( ! existsSync ( secretLocation ) ) {
89
+ logger . error ( `Secret file in location "${ secretLocation } " does not exists.` ) ;
87
90
throw new Error ( "Secret file not found." ) ;
88
91
}
89
92
90
- const file = readFileSync ( SECRETS_LOCATION , "utf8" ) ;
93
+ const file = readFileSync ( secretLocation , "utf8" ) ;
91
94
config = yaml . parse ( file ) ;
92
95
return config ;
93
96
} ;
0 commit comments