mirror of
https://github.com/certd/certd.git
synced 2026-05-17 05:37:30 +08:00
27 lines
688 B
TypeScript
27 lines
688 B
TypeScript
|
|
import path from 'path';
|
||
|
|
import _ from 'lodash';
|
||
|
|
const yaml = require('js-yaml');
|
||
|
|
const fs = require('fs');
|
||
|
|
|
||
|
|
function parseEnv() {
|
||
|
|
const config = {};
|
||
|
|
for (const key in process.env) {
|
||
|
|
let keyName = key;
|
||
|
|
if (!keyName.startsWith('certd_')) {
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
keyName = keyName.replace('certd_', '');
|
||
|
|
const configKey = keyName.replace('_', '.');
|
||
|
|
_.set(config, configKey, process.env[key]);
|
||
|
|
}
|
||
|
|
return config;
|
||
|
|
}
|
||
|
|
|
||
|
|
export function load(env = '') {
|
||
|
|
// Get document, or throw exception on error
|
||
|
|
const yamlPath = path.join(process.cwd(), `.env.${env}.yaml`);
|
||
|
|
const doc = yaml.load(fs.readFileSync(yamlPath, 'utf8'));
|
||
|
|
_.merge(doc, parseEnv());
|
||
|
|
return doc;
|
||
|
|
}
|