This commit is contained in:
+15
-9
@@ -1,19 +1,25 @@
|
||||
import path from "path";
|
||||
|
||||
export class Env {
|
||||
static set(key: string, value: string) {
|
||||
process.env[key] = value;
|
||||
constructor(private target: Record<string, string | undefined>) {}
|
||||
|
||||
set(key: string, value: string) {
|
||||
this.target[key] = value;
|
||||
}
|
||||
|
||||
static get(key: string) {
|
||||
return process.env[key];
|
||||
get(key: string) {
|
||||
return this.target[key];
|
||||
}
|
||||
|
||||
static addPath(value: string, key = "PATH") {
|
||||
if (!process.env[key]) {
|
||||
process.env[key] = value;
|
||||
} else if (process.env[key].split(path.delimiter).indexOf(value) === -1) {
|
||||
process.env[key] = [process.env[key], value].join(path.delimiter);
|
||||
addPath(value: string, key: string = "PATH") {
|
||||
if (!this.target[key]) {
|
||||
this.target[key] = value;
|
||||
} else if (this.target[key].split(path.delimiter).indexOf(value) === -1) {
|
||||
this.target[key] = [this.target[key], value].join(path.delimiter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const env = new Env(process.env);
|
||||
|
||||
export default env;
|
||||
|
||||
Reference in New Issue
Block a user