1- const fs = require ( 'fs' ) ;
2- const path = require ( ' path' ) ;
3- const os = require ( 'os' ) ;
1+ const fs = require ( "fs" ) ;
2+ const path = require ( " path" ) ;
3+ const os = require ( "os" ) ;
44
55const loadConfig = ( configPath ) => {
6- const defaultProjectConfig = path . resolve ( process . cwd ( ) , 'contract-shield.config.json' ) ;
7- const defaultGlobalConfig = path . resolve ( os . homedir ( ) , 'contract-shield.json' ) ;
8- const finalConfigPath = configPath || ( fs . existsSync ( defaultProjectConfig ) ? defaultProjectConfig : fs . existsSync ( defaultGlobalConfig ) ? defaultGlobalConfig : null ) ;
6+ const CONFIG_FILES = {
7+ PROJECT : "contract-shield.config.json" ,
8+ GLOBAL : "contract-shield.json" ,
9+ } ;
910
10- return finalConfigPath && fs . existsSync ( finalConfigPath ) ? JSON . parse ( fs . readFileSync ( finalConfigPath , 'utf-8' ) ) : { } ;
11+ const defaultProjectConfig = path . resolve (
12+ process . cwd ( ) ,
13+ CONFIG_FILES . PROJECT
14+ ) ;
15+
16+ const defaultGlobalConfig = path . resolve ( os . homedir ( ) , CONFIG_FILES . GLOBAL ) ;
17+ const finalConfigPath =
18+ configPath ||
19+ ( fs . existsSync ( defaultProjectConfig )
20+ ? defaultProjectConfig
21+ : fs . existsSync ( defaultGlobalConfig )
22+ ? defaultGlobalConfig
23+ : null ) ;
24+
25+ return finalConfigPath && fs . existsSync ( finalConfigPath )
26+ ? JSON . parse ( fs . readFileSync ( finalConfigPath , "utf-8" ) )
27+ : { } ;
1128} ;
1229
13- module . exports = { loadConfig } ;
30+ module . exports = { loadConfig } ;
0 commit comments