Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-protocol/src/env.ts
2498 views
1
/**
2
* Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import { injectable } from "inversify";
8
9
@injectable()
10
export abstract class AbstractComponentEnv {}
11
12
export function getEnvVar(name: string, defaultValue?: string): string {
13
const value = process.env[name] || defaultValue;
14
if (!value) {
15
throw new Error(`Environment variable undefined or empty: ${name}`);
16
}
17
return value;
18
}
19
20
export function filePathTelepresenceAware(filePath: string): string {
21
if (filePath && process.env.TELEPRESENCE_ROOT) {
22
filePath = process.env.TELEPRESENCE_ROOT + filePath;
23
}
24
return filePath;
25
}
26
27
export function getEnvVarParsed<T>(name: string, parser: (value: string) => T, defaultValue?: string): T {
28
return parser(getEnvVar(name, defaultValue));
29
}
30
31