File tree Expand file tree Collapse file tree 4 files changed +16
-12
lines changed Expand file tree Collapse file tree 4 files changed +16
-12
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @secjs/config" ,
3
- "version" : " 1.1.1 " ,
3
+ "version" : " 1.1.2 " ,
4
4
"description" : " " ,
5
5
"license" : " MIT" ,
6
6
"author" : " João Lenon" ,
Original file line number Diff line number Diff line change @@ -39,6 +39,10 @@ export class Config {
39
39
return config
40
40
}
41
41
42
+ loadIfUnloaded ( configPath = '/config' ) {
43
+ if ( ! Config . configs . size ) this . loadSync ( configPath )
44
+ }
45
+
42
46
loadSync ( configPath = '/config' ) {
43
47
Config . loadEnvs ( )
44
48
@@ -47,8 +51,6 @@ export class Config {
47
51
const { files } = new Folder ( path ) . loadSync ( { withFileContent : true } )
48
52
49
53
files . forEach ( file => Config . loadOnDemand ( file . path , files , 0 ) )
50
-
51
- return this
52
54
}
53
55
54
56
async load ( configPath = '/config' ) {
@@ -59,14 +61,6 @@ export class Config {
59
61
const { files } = await new Folder ( path ) . load ( { withFileContent : true } )
60
62
61
63
files . forEach ( file => Config . loadOnDemand ( file . path , files , 0 ) )
62
-
63
- return this
64
- }
65
-
66
- static verifyPath ( folderName = 'dist' ) {
67
- if ( process . env . NODE_ENV === 'testing' ) return '/config'
68
-
69
- return `/${ folderName } /config`
70
64
}
71
65
72
66
private static loadEnvs ( ) {
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ export {}
5
5
6
6
declare global {
7
7
class Config {
8
+ loadIfUnloaded ( configPath ?: string ) : void
8
9
loadSync ( configPath ?: string ) : void
9
10
load ( configPath ?: string ) : Promise < void >
10
11
static verifyPath ( folderName ?: string ) : string
@@ -16,6 +17,6 @@ const _global = global as any
16
17
17
18
Path . switchEnvVerify ( )
18
19
19
- new ConfigInstance ( ) . loadSync ( )
20
+ new ConfigInstance ( ) . loadIfUnloaded ( )
20
21
21
22
_global . Config = ConfigInstance
Original file line number Diff line number Diff line change @@ -80,4 +80,13 @@ describe('\n Config', () => {
80
80
expect ( Config . get ( 'DB_NAME' ) ) . toBe ( 'testing' )
81
81
expect ( Config . get ( 'database.dbName' ) ) . toBe ( 'testing' )
82
82
} )
83
+
84
+ it ( 'should be able to use loadIfUnloaded method to load configs if they are not loaded' , async ( ) => {
85
+ expect ( Config . get ( 'app' ) ) . toBe ( undefined )
86
+
87
+ new Config ( ) . loadIfUnloaded ( )
88
+
89
+ expect ( Config . get ( 'DB_NAME' ) ) . toBe ( 'testing' )
90
+ expect ( Config . get ( 'database.dbName' ) ) . toBe ( 'testing' )
91
+ } )
83
92
} )
You can’t perform that action at this time.
0 commit comments