fix tips
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@kevisual/use-config",
|
"name": "@kevisual/use-config",
|
||||||
"version": "1.0.23",
|
"version": "1.0.24",
|
||||||
"types": "dist/config.d.ts",
|
"types": "dist/config.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "npm run clean && code-builder build --dts",
|
"build": "npm run clean && code-builder build --dts",
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ export const getConfigFile = (opts?: ConfigOpts) => {
|
|||||||
if (lastLast) return lastLastPath;
|
if (lastLast) return lastLastPath;
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
type GetConfigOpts = ConfigOpts & { dotenvOpts?: dotenv.DotenvConfigOptions };
|
type GetConfigOpts = ConfigOpts & { dotenvOpts?: dotenv.DotenvConfigOptions, quite?: boolean };
|
||||||
/**
|
/**
|
||||||
* 初始化配置, 不会把配置内容挂载到全局
|
* 初始化配置, 不会把配置内容挂载到全局
|
||||||
* @param opts 配置选项
|
* @param opts 配置选项
|
||||||
@@ -143,8 +143,9 @@ type GetConfigOpts = ConfigOpts & { dotenvOpts?: dotenv.DotenvConfigOptions };
|
|||||||
* @returns 配置
|
* @returns 配置
|
||||||
*/
|
*/
|
||||||
export const getConfig = (opts?: GetConfigOpts): Config => {
|
export const getConfig = (opts?: GetConfigOpts): Config => {
|
||||||
|
let quiet = opts?.quite ?? true;
|
||||||
if (opts?.dotenvOpts) {
|
if (opts?.dotenvOpts) {
|
||||||
const prased = dotenv.config({ quiet: true, ...opts.dotenvOpts }).parsed as Config;
|
const prased = dotenv.config({ quiet, ...opts.dotenvOpts }).parsed as Config;
|
||||||
if (prased) {
|
if (prased) {
|
||||||
return prased;
|
return prased;
|
||||||
} else {
|
} else {
|
||||||
@@ -153,7 +154,9 @@ export const getConfig = (opts?: GetConfigOpts): Config => {
|
|||||||
}
|
}
|
||||||
// 配置读取路径,3级判断
|
// 配置读取路径,3级判断
|
||||||
const filePath = getConfigFile(opts);
|
const filePath = getConfigFile(opts);
|
||||||
|
if (!quiet) {
|
||||||
console.log('config pathname:', filePath);
|
console.log('config pathname:', filePath);
|
||||||
|
}
|
||||||
if (!filePath) {
|
if (!filePath) {
|
||||||
throw new Error('未找到配置文件');
|
throw new Error('未找到配置文件');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user