@contextjs/system
Version:
ContextJS - System
36 lines (35 loc) • 1.06 kB
JavaScript
import { Console } from "../services/console.js";
import { EnvironmentName } from "./environment-name.js";
export class Environment {
_name;
constructor(args = process.argv.slice(2)) {
this._name = this.extractEnvironmentName(args);
}
get name() {
return this._name;
}
set name(value) {
this._name = value.toLowerCase();
}
get isDevelopment() {
return this._name === EnvironmentName.development;
}
get isProduction() {
return this._name === EnvironmentName.production;
}
get isTest() {
return this._name === EnvironmentName.test;
}
get isStaging() {
return this._name === EnvironmentName.staging;
}
toString() {
return this._name;
}
extractEnvironmentName(args) {
const parsed = Console.parseArguments(args);
const envArg = parsed.find(t => t.name === '--environment' || t.name === '-e');
const env = envArg?.values?.[0]?.toLowerCase();
return env || EnvironmentName.development;
}
}