Spaces:
Running
Running
import path from 'path'; | |
import fs from 'fs-extra'; | |
import minimist from 'minimist'; | |
import _ from 'lodash'; | |
const cmdArgs = minimist(process.argv.slice(2)); //θ·εε½δ»€θ‘εζ° | |
const envVars = process.env; //θ·εη―ε’ει | |
class Environment { | |
/** ε½δ»€θ‘εζ° */ | |
cmdArgs: any; | |
/** η―ε’ει */ | |
envVars: any; | |
/** η―ε’εη§° */ | |
env?: string; | |
/** ζε‘εη§° */ | |
name?: string; | |
/** ζε‘ε°ε */ | |
host?: string; | |
/** ζε‘η«―ε£ */ | |
port?: number; | |
/** ε εζ° */ | |
package: any; | |
constructor(options: any = {}) { | |
const { cmdArgs, envVars, package: _package } = options; | |
this.cmdArgs = cmdArgs; | |
this.envVars = envVars; | |
this.env = _.defaultTo(cmdArgs.env || envVars.SERVER_ENV, 'dev'); | |
this.name = cmdArgs.name || envVars.SERVER_NAME || undefined; | |
this.host = cmdArgs.host || envVars.SERVER_HOST || undefined; | |
this.port = Number(cmdArgs.port || envVars.SERVER_PORT) ? Number(cmdArgs.port || envVars.SERVER_PORT) : undefined; | |
this.package = _package; | |
} | |
} | |
export default new Environment({ | |
cmdArgs, | |
envVars, | |
package: JSON.parse(fs.readFileSync(path.join(path.resolve(), "package.json")).toString()) | |
}); |