think/packages/config/lib/index.js

21 lines
624 B
JavaScript
Raw Normal View History

2022-02-20 19:51:55 +08:00
"use strict";
2022-05-18 16:02:29 +08:00
exports.__esModule = true;
2022-02-20 19:51:55 +08:00
exports.getConfig = void 0;
2022-05-18 16:02:29 +08:00
var fs = require("fs-extra");
var yaml = require("js-yaml");
var path = require("path");
var FILE_ENV_NAME = {
2022-02-20 19:51:55 +08:00
development: 'dev',
test: 'test',
2022-05-18 16:02:29 +08:00
production: 'prod'
2022-02-20 19:51:55 +08:00
};
2022-05-18 16:02:29 +08:00
var env = process.env.NODE_ENV || 'development';
2022-02-20 19:51:55 +08:00
function getConfig() {
2022-05-21 22:38:26 +08:00
var filePath = path.join(__dirname, '../../../config', "".concat(FILE_ENV_NAME[env], ".yaml"));
2022-02-20 19:51:55 +08:00
if (!fs.existsSync(filePath)) {
2022-05-18 16:02:29 +08:00
throw new Error("Can not find config file: ".concat(filePath));
2022-02-20 19:51:55 +08:00
}
return yaml.load(fs.readFileSync(filePath, 'utf8'));
}
exports.getConfig = getConfig;