-
Notifications
You must be signed in to change notification settings - Fork 934
/
Copy pathload-config.ts
43 lines (38 loc) · 1.01 KB
/
load-config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import path from 'path';
import {cosmiconfig} from 'cosmiconfig';
import TypeScriptLoader from '@endemolshinegroup/cosmiconfig-typescript-loader';
export interface LoadConfigResult {
config: unknown;
filepath: string;
isEmpty?: boolean;
}
export async function loadConfig(
cwd: string,
configPath?: string
): Promise<LoadConfigResult | null> {
const moduleName = 'commitlint';
const explorer = cosmiconfig('commitlint', {
searchPlaces: [
'package.json',
`.${moduleName}rc`,
`.${moduleName}rc.json`,
`.${moduleName}rc.yaml`,
`.${moduleName}rc.yml`,
`.${moduleName}rc.ts`,
`.${moduleName}rc.js`,
`${moduleName}.config.ts`,
`${moduleName}.config.js`,
],
loaders: {
'.ts': TypeScriptLoader,
},
});
const explicitPath = configPath ? path.resolve(cwd, configPath) : undefined;
const explore = explicitPath ? explorer.load : explorer.search;
const searchPath = explicitPath ? explicitPath : cwd;
const local = await explore(searchPath);
if (local) {
return local;
}
return null;
}