feat: 从~/.hydro/env读取环境变量

This commit is contained in:
undefined committed 2020-12-26 17:55:23 +08:00
1 parent e3dad8ff60
commit c6b67bb1a8
7 files changed
+26 -13

No files matched your search

+8
View File
@@ -6,6 +6,14 @@ import { Logger } from './logger';
const logger = new Logger('options');
export = function load() {
const envFile = path.resolve(os.homedir(), '.hydro', 'env');
if (fs.existsSync(envFile)) {
const content = fs.readFileSync(envFile).toString();
for (const line of content.split('\n')) {
process.env[line.split('=')[0]] = line.split('=')[1];
}
}
let f = path.resolve(process.cwd(), 'config.json');
if (!fs.existsSync(f)) f = path.resolve(__dirname, 'config.json');
if (!fs.existsSync(f)) f = path.resolve(os.homedir(), '.config', 'hydro', 'config.json');