t-comm
Version:
专业、稳定、纯粹的工具库
46 lines (41 loc) • 1.29 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var nodejs_fs = require('../nodejs/fs.js');
var thirdParty_dotenv = require('../third-party/dotenv.js');
var thirdParty_dotenvExpand = require('../third-party/dotenv-expand.js');
/**
* 用 dotenv-expand 加载环境变量
* @param file 文件路径,默认 .env.local
* @param param 参数
*
* @example
* ```ts
* loadEnv();
*
* loadEnv('.env');
*
* loadEnv('.env.local', {
* debug: false, // 是否打印日志,默认 true
* });
* ```
*/
function loadDotenv() {
var file = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '.env.local';
var options = arguments.length > 1 ? arguments[1] : undefined;
var _a;
var dotenv = thirdParty_dotenv.getDotenv();
var dotenvExpand = thirdParty_dotenvExpand.getDotenvExpand();
if (!nodejs_fs.getFs().existsSync(file)) {
console.log(">>> loadEnv ".concat(file, " \u4E0D\u5B58\u5728"));
return;
}
var myEnv = dotenv.config({
path: file
});
dotenvExpand.expand(myEnv);
var debug = (_a = options === null || options === void 0 ? void 0 : options.debug) !== null && _a !== void 0 ? _a : true;
if (debug) {
console.log(">>> loadEnv ".concat(file, " success"));
}
}
exports.loadDotenv = loadDotenv;