UNPKG

1.52 kBJavaScriptView Raw
1"use strict";
2// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3// See LICENSE in the project root for license information.
4Object.defineProperty(exports, "__esModule", { value: true });
5const State_1 = require("./State");
6const index_1 = require("./index");
7const ENVIRONMENT_VARIABLE_PREFIX = 'GCB_';
8function getConfigValue(name, defaultValue) {
9 // Try to get config value from environment variable.
10 const envVariable = ENVIRONMENT_VARIABLE_PREFIX + name.toUpperCase();
11 const envValue = process.env[envVariable];
12 const argsValue = State_1.args[name.toLowerCase()];
13 // getConfig can be undefined during the first few calls to this function because the build config is initialized
14 // before the getConfig function is defined. In those cases, a defaultValue is provided.
15 const configValue = ((index_1.getConfig ? index_1.getConfig() : {}) || {})[name];
16 return _firstDefinedValue(argsValue, envValue, defaultValue, configValue);
17}
18exports.getConfigValue = getConfigValue;
19function getFlagValue(name, defaultValue) {
20 const configValue = getConfigValue(name, defaultValue);
21 return configValue === 'true' || configValue === true;
22}
23exports.getFlagValue = getFlagValue;
24// eslint-disable-next-line @typescript-eslint/no-explicit-any
25function _firstDefinedValue(...values) {
26 for (const value of values) {
27 if (value !== undefined) {
28 return value;
29 }
30 }
31 return undefined;
32}
33//# sourceMappingURL=config.js.map
\No newline at end of file