@ruan-cat/utils 3.3.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/node-esm/index.d.ts +30 -1
- package/dist/node-esm/index.js +2694 -1
- package/dist/node-esm/index.js.map +1 -1
- package/package.json +9 -9
- package/src/node-esm/index.ts +3 -0
- package/src/node-esm/scripts/add-changelog-to-doc.ts +29 -0
- package/src/node-esm/scripts/copy-changelog.ts +26 -0
- package/src/node-esm/scripts/yaml-to-md.ts +69 -0
- package/src/vueuse/useAxios/index.ts +34 -27
- package/src/vueuse/useAxios/v2.ts +36 -40
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import consola from "consola";
|
|
4
|
+
|
|
5
|
+
/** 检查当前运行的根目录 是否存在 CHANGELOG.md 文件 */
|
|
6
|
+
export function hasChangelogMd() {
|
|
7
|
+
consola.log("当前项目根目录为:", process.cwd());
|
|
8
|
+
consola.warn("当前项目根目录不存在 CHANGELOG.md 文件");
|
|
9
|
+
return fs.existsSync(path.resolve(process.cwd(), "CHANGELOG.md"));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 将 CHANGELOG.md 文件移动到指定要求的位置内
|
|
14
|
+
* @description
|
|
15
|
+
* 该函数相当于实现 `cpx CHANGELOG.md docs` 命令
|
|
16
|
+
*/
|
|
17
|
+
export function copyChangelogMd(/** 目标文件夹 */ target: string) {
|
|
18
|
+
if (!hasChangelogMd()) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const source = path.resolve(process.cwd(), "CHANGELOG.md");
|
|
23
|
+
const destination = path.resolve(process.cwd(), target, "CHANGELOG.md");
|
|
24
|
+
|
|
25
|
+
fs.copyFileSync(source, destination);
|
|
26
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
|
|
3
|
+
import { consola } from "consola";
|
|
4
|
+
import { isUndefined } from "lodash-es";
|
|
5
|
+
import yaml from "js-yaml";
|
|
6
|
+
|
|
7
|
+
// import { program } from "commander";
|
|
8
|
+
// import prettier from "prettier";
|
|
9
|
+
// import prettierConfig from "../prettier.config.js";
|
|
10
|
+
// program
|
|
11
|
+
// .name("yaml-in-md")
|
|
12
|
+
// // 环境变量的地址
|
|
13
|
+
// .option("--md <path>", "目标md文件的地址,目前仅考虑单个文件")
|
|
14
|
+
// .parse();
|
|
15
|
+
// const options = program.opts();
|
|
16
|
+
// consola.info(" 查看命令行提供的参数 ", options);
|
|
17
|
+
// /** md文件的地址 */
|
|
18
|
+
// const defMdPath: string = options?.md;
|
|
19
|
+
|
|
20
|
+
export interface WriteYaml2mdParams<T = Record<string, any>> {
|
|
21
|
+
/** 目标md文件地址 */
|
|
22
|
+
mdPath: string;
|
|
23
|
+
|
|
24
|
+
/** 被插入到md头部的数据 */
|
|
25
|
+
data: T;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 将YAML数据写入到MD文件内
|
|
30
|
+
*/
|
|
31
|
+
export function writeYaml2md<T>(params: WriteYaml2mdParams<T>) {
|
|
32
|
+
consola.info(` 当前运行的地址为: ${process.cwd()} `);
|
|
33
|
+
const { mdPath, data } = params;
|
|
34
|
+
|
|
35
|
+
if (isUndefined(mdPath)) {
|
|
36
|
+
consola.error(" 请提供md文件的地址 ");
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Check if file exists
|
|
41
|
+
try {
|
|
42
|
+
readFileSync(mdPath, "utf-8");
|
|
43
|
+
} catch (error) {
|
|
44
|
+
consola.error(` 文件 ${mdPath} 不存在 `);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Read the existing MD file
|
|
49
|
+
const mdContent = readFileSync(mdPath, "utf-8");
|
|
50
|
+
|
|
51
|
+
// Convert data to YAML
|
|
52
|
+
const yamlContent = yaml.dump(data);
|
|
53
|
+
|
|
54
|
+
// Combine YAML with MD content
|
|
55
|
+
const newContent = `---\n${yamlContent}---\n\n${mdContent}`;
|
|
56
|
+
|
|
57
|
+
// 警告 暂不考虑使用本函数内的prettier功能 避免打包体积太大
|
|
58
|
+
// Format with prettier using project config
|
|
59
|
+
// const formattedContent = await prettier.format(newContent, {
|
|
60
|
+
// parser: "markdown",
|
|
61
|
+
// ...prettierConfig,
|
|
62
|
+
// });
|
|
63
|
+
|
|
64
|
+
// Write back to file
|
|
65
|
+
// writeFileSync(mdPath, formattedContent, "utf-8");
|
|
66
|
+
writeFileSync(mdPath, newContent, "utf-8");
|
|
67
|
+
|
|
68
|
+
consola.success(` 已将YAML数据写入到 ${mdPath} `);
|
|
69
|
+
}
|
|
@@ -14,6 +14,7 @@ export type KeyHelper<K extends KeyAxiosRequestConfig> = K;
|
|
|
14
14
|
|
|
15
15
|
/** @deprecated 在v2版本中,我们不使用该工具来约束删减类型 */
|
|
16
16
|
export type RemoveUrl<T extends KeyAxiosRequestConfig> = Exclude<T, "url">;
|
|
17
|
+
|
|
17
18
|
/** @deprecated 在v2版本中,我们不使用该工具来约束删减类型 */
|
|
18
19
|
export type RemoveUrlMethod<T extends KeyAxiosRequestConfig> = Exclude<T, "url" | "method">;
|
|
19
20
|
|
|
@@ -72,35 +73,42 @@ declare module "@vueuse/integrations/useAxios" {
|
|
|
72
73
|
): StrictUseAxiosReturn<T, K, R, D> & Promise<StrictUseAxiosReturn<T, K, R, D>>;
|
|
73
74
|
}
|
|
74
75
|
|
|
75
|
-
/** 包装器的参数 @version
|
|
76
|
+
/** 包装器的参数 @version 2 */
|
|
76
77
|
export interface UseAxiosWrapperParams<
|
|
77
|
-
/**
|
|
78
|
-
* 业务数据类型
|
|
79
|
-
* @description
|
|
80
|
-
* 必须先填写业务类型
|
|
81
|
-
*/
|
|
82
|
-
T = any,
|
|
83
78
|
/**
|
|
84
79
|
* AxiosRequestConfig 默认必填的字段
|
|
85
80
|
* @description
|
|
86
|
-
*
|
|
81
|
+
* key是首先必填的字段 必须要约束axios请求配置的可选项值
|
|
87
82
|
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* 默认为 必填url请求地址的 config 请求配置
|
|
83
|
+
* 该key值不再默认要求url是必填项 不做严格约束
|
|
91
84
|
*/
|
|
92
|
-
K extends KeyAxiosRequestConfig
|
|
85
|
+
K extends KeyAxiosRequestConfig,
|
|
93
86
|
/**
|
|
94
|
-
*
|
|
87
|
+
* 业务数据类型
|
|
88
|
+
* @description
|
|
89
|
+
* axios的返回值类型 二版本不再默认提供any类型
|
|
90
|
+
*
|
|
91
|
+
* 下游工具必须主动传递类型
|
|
95
92
|
*/
|
|
96
|
-
|
|
93
|
+
T,
|
|
94
|
+
/** UseAxiosOptionsBase 的派生类型 */
|
|
95
|
+
UseAxiosOptionsLike extends UseAxiosOptionsBase = UseAxiosOptionsBase<T>,
|
|
97
96
|
/**
|
|
98
97
|
* AxiosRequestConfig 用的类型
|
|
99
98
|
* @description
|
|
100
|
-
*
|
|
99
|
+
* 通常是 axios 的输入值
|
|
101
100
|
*/
|
|
102
101
|
D = any,
|
|
103
102
|
> {
|
|
103
|
+
/**
|
|
104
|
+
* 接口的url
|
|
105
|
+
* @description
|
|
106
|
+
* 接口必须要有url地址,该url迁移到此处专门设置
|
|
107
|
+
*
|
|
108
|
+
* 不要求在 axios 配置内必传url了。
|
|
109
|
+
* @version 2
|
|
110
|
+
*/
|
|
111
|
+
url: string;
|
|
104
112
|
/**
|
|
105
113
|
* axios的配置类型
|
|
106
114
|
* @description
|
|
@@ -125,19 +133,18 @@ export interface UseAxiosWrapperParams<
|
|
|
125
133
|
* 其本质是对 useAxios 函数的封装,仅仅是包装了参数层
|
|
126
134
|
*
|
|
127
135
|
* 预期设计成一个万能的 通用的请求函数
|
|
128
|
-
*
|
|
136
|
+
*
|
|
137
|
+
* 类型必传key T UseAxiosOptionsLike
|
|
138
|
+
* @version 2
|
|
129
139
|
*/
|
|
130
|
-
export function useAxiosWrapper<
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
} = params;
|
|
137
|
-
|
|
138
|
-
// return useAxios<T, AxiosResponse<T>, D>(url, config, instance, options);
|
|
139
|
-
|
|
140
|
-
// 跳转到我们拓展的函数声明
|
|
140
|
+
export function useAxiosWrapper<
|
|
141
|
+
K extends KeyAxiosRequestConfig,
|
|
142
|
+
T,
|
|
143
|
+
UseAxiosOptionsLike extends UseAxiosOptionsBase,
|
|
144
|
+
D = any,
|
|
145
|
+
>(params: UseAxiosWrapperParams<K, T, UseAxiosOptionsLike, D>) {
|
|
146
|
+
const { config = {}, instance, options = {} } = params;
|
|
147
|
+
const url = params.url || "";
|
|
141
148
|
return useAxios<T, K, AxiosResponse<T>, D>(url, config, instance, options);
|
|
142
149
|
}
|
|
143
150
|
|
|
@@ -1,48 +1,46 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* 这里是第一版本的工具
|
|
3
|
+
* 已经不再使用
|
|
4
4
|
*/
|
|
5
|
+
import type { RequiredPick } from "type-plus";
|
|
5
6
|
import type { AxiosResponse, AxiosInstance } from "axios";
|
|
6
|
-
import type { UseAxiosOptionsBase } from "@vueuse/integrations/useAxios";
|
|
7
|
+
import type { UseAxiosOptionsBase, UseAxiosOptions } from "@vueuse/integrations/useAxios";
|
|
7
8
|
import { useAxios } from "@vueuse/integrations/useAxios";
|
|
8
9
|
import type { CreateAxiosRequestConfig, KeyAxiosRequestConfig } from "./index.ts";
|
|
9
10
|
|
|
10
|
-
/**
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* 包装器的参数
|
|
13
|
+
* @version 1
|
|
14
|
+
* @deprecated
|
|
15
|
+
*/
|
|
16
|
+
export interface UseAxiosWrapperParamsV1<
|
|
12
17
|
/**
|
|
13
|
-
*
|
|
18
|
+
* 业务数据类型
|
|
14
19
|
* @description
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* 该key值不再默认要求url是必填项 不做严格约束
|
|
20
|
+
* 必须先填写业务类型
|
|
18
21
|
*/
|
|
19
|
-
|
|
22
|
+
T = any,
|
|
20
23
|
/**
|
|
21
|
-
*
|
|
24
|
+
* AxiosRequestConfig 默认必填的字段
|
|
22
25
|
* @description
|
|
23
|
-
*
|
|
26
|
+
* 用于约束其他类型的字段
|
|
27
|
+
*
|
|
28
|
+
* 然后才能填写必传的参数类型
|
|
24
29
|
*
|
|
25
|
-
*
|
|
30
|
+
* 默认为 必填url请求地址的 config 请求配置
|
|
31
|
+
*/
|
|
32
|
+
K extends KeyAxiosRequestConfig<D> = "url",
|
|
33
|
+
/**
|
|
34
|
+
* UseAxiosOptions 的派生类型
|
|
26
35
|
*/
|
|
27
|
-
|
|
28
|
-
/** UseAxiosOptionsBase 的派生类型 */
|
|
29
|
-
UseAxiosOptionsLike extends UseAxiosOptionsBase = UseAxiosOptionsBase<T>,
|
|
36
|
+
UseAxiosOptionsLike extends UseAxiosOptions = UseAxiosOptions,
|
|
30
37
|
/**
|
|
31
38
|
* AxiosRequestConfig 用的类型
|
|
32
39
|
* @description
|
|
33
|
-
*
|
|
40
|
+
* 最后才可以传递此类型
|
|
34
41
|
*/
|
|
35
42
|
D = any,
|
|
36
43
|
> {
|
|
37
|
-
/**
|
|
38
|
-
* 接口的url
|
|
39
|
-
* @description
|
|
40
|
-
* 接口必须要有url地址,该url迁移到此处专门设置
|
|
41
|
-
*
|
|
42
|
-
* 不要求在 axios 配置内必传url了。
|
|
43
|
-
* @version 2
|
|
44
|
-
*/
|
|
45
|
-
url: string;
|
|
46
44
|
/**
|
|
47
45
|
* axios的配置类型
|
|
48
46
|
* @description
|
|
@@ -61,26 +59,24 @@ export interface UseAxiosWrapperParams2<
|
|
|
61
59
|
options: UseAxiosOptionsLike;
|
|
62
60
|
}
|
|
63
61
|
|
|
64
|
-
/**
|
|
65
|
-
* 正在尝试重构的2 url不是非必填 多了独立的url参数 */
|
|
66
|
-
|
|
67
62
|
/**
|
|
68
63
|
* useAxios 的包装函数
|
|
69
64
|
* @description
|
|
70
65
|
* 其本质是对 useAxios 函数的封装,仅仅是包装了参数层
|
|
71
66
|
*
|
|
72
67
|
* 预期设计成一个万能的 通用的请求函数
|
|
73
|
-
*
|
|
74
|
-
* 类型必传key T UseAxiosOptionsLike
|
|
75
|
-
* @version 2
|
|
68
|
+
* @version 1
|
|
76
69
|
*/
|
|
77
|
-
export function
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
70
|
+
export function useAxiosWrapperV1<T, K extends KeyAxiosRequestConfig, D = any>(params: UseAxiosWrapperParamsV1) {
|
|
71
|
+
const {
|
|
72
|
+
config: { url },
|
|
73
|
+
config,
|
|
74
|
+
instance,
|
|
75
|
+
options,
|
|
76
|
+
} = params;
|
|
77
|
+
// 跳转到 vueuse 内的函数声明
|
|
78
|
+
// return useAxios<T, AxiosResponse<T>, D>(url, config, instance, options);
|
|
79
|
+
|
|
80
|
+
// 跳转到我们拓展的函数声明
|
|
85
81
|
return useAxios<T, K, AxiosResponse<T>, D>(url, config, instance, options);
|
|
86
82
|
}
|