Skip to content

Commit f652bc0

Browse files
committed
2 parents abc8671 + 44949a8 commit f652bc0

2 files changed

Lines changed: 42 additions & 8 deletions

File tree

contract-shield.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"patterns": [
3+
"**/*.js"
4+
],
5+
"exclude": [
6+
"node_modules/**",
7+
"dist/**",
8+
"coverage/**",
9+
"build/**",
10+
"test/**",
11+
"tests/**",
12+
"**/*.config.js",
13+
"__tests__/**",
14+
"**/*.test.js"
15+
],
16+
"output": "./dist"
17+
}

src/utils/configUtils.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
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

55
const 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

Comments
 (0)