diff --git a/package.json b/package.json index bda34fe..846edcd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/use-config", - "version": "1.0.25", + "version": "1.0.26", "types": "dist/config.d.ts", "scripts": { "build": "npm run clean && code-builder build --dts", diff --git a/src/env.ts b/src/env.ts index 3afabc1..bb2db5f 100644 --- a/src/env.ts +++ b/src/env.ts @@ -47,6 +47,7 @@ export type Config = { BAILIAN_API_KEY?: string; ZHIPU_API_KEY?: string; MINIMAX_API_KEY?: string; + DOUBAO_API_KEY?: string; JIMENG_API_URL?: string; JIMENG_API_KEY?: string; @@ -75,7 +76,6 @@ export type Config = { KUBECONFIG_DATA?: string; // 其他自定义配置 - [key: string]: any; } & T; export const initConfig: Config = { PORT: '3000', @@ -155,7 +155,7 @@ export const getConfig = (opts?: GetConfigOpts): Config => { return prased; } else { if (showError) { - if(!quiet) { + if (!quiet) { console.warn('config 读取失败'); } throw new Error('未找到配置文件'); @@ -169,8 +169,8 @@ export const getConfig = (opts?: GetConfigOpts): Config => { console.log('config pathname:', filePath); } if (!filePath) { - if(showError) { - if(!quiet) { + if (showError) { + if (!quiet) { console.warn('config 路径未找到'); } throw new Error('未找到配置文件'); @@ -216,9 +216,11 @@ export const mergeConfig = (config: { [key: string]: any }) => { return _config; }; -export const useKey = (key: string, opts?: { defaultValue?: string; isNumber?: boolean; isBoolean?: boolean }): string | number | boolean => { +export const useKey = (key: keyof Config, opts?: { defaultValue?: string; isNumber?: boolean; isBoolean?: boolean }): string | number | boolean => { + // @ts-ignore let v = useConfig()[key]; if (!v) { + // @ts-ignore v = process.env[key]; } if (!v) {