think/packages/config/lib/index.js

21 lines
618 B
JavaScript
Raw Normal View History

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