-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathconfig.ts
95 lines (85 loc) · 2.47 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import * as os from "os";
import * as fs from "fs";
import * as path from "path";
import * as _ from "lodash";
import * as yaml from "js-yaml";
import { ReportLaunchingCircuitBreaker } from "./Reporting/ReportLaunchingCircuitBreaker";
import { Reporter } from "./Core/Reporter";
export interface Config {
reporters: (string | Reporter)[];
normalizeLineEndingsTo: boolean | string;
failOnLineEndingDifferences: boolean;
appendEOL: boolean;
EOL: string;
errorOnStaleApprovedFiles: boolean;
shouldIgnoreStaleApprovedFile: (fileName?: string) => boolean;
stripBOM: boolean;
forceApproveAll: boolean;
blockUntilReporterExits: boolean;
maxLaunches: number;
cmdOptionOverrides?: any;
cmdArgs?: string[];
}
// begin-snippet: default_config
export const defaultConfig: Config = {
reporters: [
"BeyondCompare",
"diffmerge",
"p4merge",
"tortoisemerge",
"nodediff",
"opendiff",
"gitdiff",
],
normalizeLineEndingsTo: false,
failOnLineEndingDifferences: false,
appendEOL: true,
EOL: os.EOL,
errorOnStaleApprovedFiles: true,
shouldIgnoreStaleApprovedFile: () => false,
stripBOM: false,
forceApproveAll: false,
blockUntilReporterExits: false,
maxLaunches: 10,
};
// end-snippet
export function getHomeApprovalConfig(): Config | null {
const homeConfigPath = path.join(os.homedir(), ".approvalsConfig");
if (fs.existsSync(homeConfigPath)) {
const configFileData = fs.readFileSync(homeConfigPath).toString();
try {
return yaml.load(configFileData) as Config;
} catch (ex) {
throw new Error("Error parsing " + homeConfigPath + ". " + ex);
}
}
return null;
}
let currentConfigObj: Config;
export function getConfig(configOverrides?: Partial<Config>): Config {
const homeConfig = getHomeApprovalConfig() || {};
const resultConfig = _.defaults(
configOverrides || {},
currentConfigObj || {},
homeConfig,
defaultConfig,
);
return resultConfig as Config;
}
export function configure(overrideOptions?: Partial<Config>): Config {
currentConfigObj = getConfig(overrideOptions);
processConfig(currentConfigObj);
return currentConfigObj;
}
export function currentConfig(): Config {
return currentConfigObj;
}
export function reset(): void {
currentConfigObj = _.defaults({}, getHomeApprovalConfig(), defaultConfig);
}
currentConfigObj = getConfig();
function processConfig(config: Config): void {
if (config.maxLaunches) {
ReportLaunchingCircuitBreaker.setMaxLaunch(config.maxLaunches);
}
}