update
This commit is contained in:
@@ -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",
|
||||
|
||||
12
src/env.ts
12
src/env.ts
@@ -47,6 +47,7 @@ export type Config<T = {}> = {
|
||||
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<T = {}> = {
|
||||
|
||||
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 = <T = {}>(key: keyof Config<T>, 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) {
|
||||
|
||||
Reference in New Issue
Block a user