-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathenvConfig.ts
82 lines (69 loc) · 2.48 KB
/
envConfig.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
import { isCorrectLogLevel, Logger } from "backfill-logger";
import {
getAzureBlobConfigFromSerializedOptions,
getNpmConfigFromSerializedOptions,
} from "./cacheConfig";
import { isCorrectMode, Config } from "./index";
export function getEnvConfig(logger: Logger) {
const config: Partial<Config> = {};
const cacheProvider = process.env["BACKFILL_CACHE_PROVIDER"];
const serializedCacheProviderOptions =
process.env["BACKFILL_CACHE_PROVIDER_OPTIONS"];
if (cacheProvider === "azure-blob" && serializedCacheProviderOptions) {
config["cacheStorageConfig"] = getAzureBlobConfigFromSerializedOptions(
serializedCacheProviderOptions,
logger
);
} else if (cacheProvider === "npm" && serializedCacheProviderOptions) {
config["cacheStorageConfig"] = getNpmConfigFromSerializedOptions(
serializedCacheProviderOptions,
logger
);
} else if (cacheProvider === "local") {
// local cache has no config at the moment
}
const internalCacheFolder = process.env["BACKFILL_INTERNAL_CACHE_FOLDER"];
if (internalCacheFolder) {
config["internalCacheFolder"] = internalCacheFolder;
}
const logFolder = process.env["BACKFILL_LOG_FOLDER"];
if (logFolder) {
config["logFolder"] = logFolder;
}
const mode = process.env["BACKFILL_MODE"];
if (mode) {
if (isCorrectMode(mode)) {
config["mode"] = mode;
} else {
throw `Backfill config option "BACKFILL_MODE" was set, but with the wrong value: "${mode}".`;
}
}
const logLevel = process.env["BACKFILL_LOG_LEVEL"];
if (logLevel) {
if (isCorrectLogLevel(logLevel)) {
config["logLevel"] = logLevel;
} else {
throw `Backfill config option "BACKFILL_LOG_LEVEL" was set, but with the wrong value: "${logLevel}".`;
}
}
const performanceReportName = process.env["BACKFILL_PERFORMANCE_REPORT_NAME"];
if (performanceReportName) {
config["performanceReportName"] = performanceReportName;
}
const producePerformanceLogs =
process.env["BACKFILL_PRODUCE_PERFORMANCE_LOGS"];
if (producePerformanceLogs) {
config["producePerformanceLogs"] = Boolean(
producePerformanceLogs === "true"
);
}
const validateOutput = process.env["BACKFILL_VALIDATE_OUTPUT"];
if (validateOutput) {
config["validateOutput"] = Boolean(validateOutput === "true");
}
const incrementalCaching = process.env["BACKFILL_INCREMENTAL_CACHING"];
if (incrementalCaching) {
config["incrementalCaching"] = Boolean(incrementalCaching === "true");
}
return config;
}