UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

42 lines (39 loc) 1.14 kB
import { getFs } from '../nodejs/fs.mjs'; import { getDotenv } from '../third-party/dotenv.mjs'; import { getDotenvExpand } from '../third-party/dotenv-expand.mjs'; /** * 用 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 = getDotenv(); var dotenvExpand = getDotenvExpand(); if (!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")); } } export { loadDotenv };