think/packages/config/src/index.ts

22 lines
542 B
TypeScript
Raw Normal View History

2022-02-20 11:51:55 +00:00
import * as fs from 'fs-extra';
import * as yaml from 'js-yaml';
import * as path from 'path';
const FILE_ENV_NAME = {
development: 'dev',
test: 'test',
production: 'prod',
};
const env = process.env.NODE_ENV || 'development';
export function getConfig() {
2022-05-21 14:38:26 +00:00
const filePath = path.join(__dirname, '../../../config', `${FILE_ENV_NAME[env]}.yaml`);
2022-02-20 11:51:55 +00:00
if (!fs.existsSync(filePath)) {
throw new Error(`Can not find config file: ${filePath}`);
}
return yaml.load(fs.readFileSync(filePath, 'utf8')) as Record<string, unknown>;
}