@ruan-cat/utils 1.7.0 → 3.0.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/{readme.md → README.md} +6 -0
- package/dist/index.d.ts +1 -129
- package/dist/index.js +1 -56
- package/dist/index.js.map +1 -1
- package/dist/{node.cjs → node-cjs/index.cjs} +13 -15
- package/dist/node-cjs/index.cjs.map +1 -0
- package/dist/{node.d.cts → node-cjs/index.d.cts} +2 -3
- package/dist/node-esm/index.d.ts +33 -0
- package/dist/node-esm/index.js +114 -0
- package/dist/node-esm/index.js.map +1 -0
- package/package.json +26 -9
- package/src/index.ts +0 -6
- package/src/node-cjs/index.ts +1 -0
- package/src/{node.ts → node-cjs/tools.ts} +4 -2
- package/src/node-esm/index.ts +3 -0
- package/src/node-esm/scripts/clean.ts +45 -0
- package/src/unplugin-vue-router/README.md +21 -0
- package/src/unplugin-vue-router/index.ts +11 -0
- package/src/vite-plugin-autogeneration-import-file/README.md +37 -0
- package/src/vite-plugin-autogeneration-import-file/index.ts +120 -0
- package/src/vite-plugin-autogeneration-import-file/template/components.template.ts +21 -0
- package/src/vueuse/README.md +9 -0
- package/src/vueuse/index.ts +1 -0
- package/src/vueuse/useAxios/README.md +59 -0
- package/tsconfig.json +1 -1
- package/dist/node.cjs.map +0 -1
- package/dist/node.d.ts +0 -43
- package/dist/node.js +0 -62
- package/dist/node.js.map +0 -1
- /package/src/{ruan-cat-pkg-info.ts → node-esm/ruan-cat-pkg-info.ts} +0 -0
- /package/src/vueuse/{useAxios.ts → useAxios/index.ts} +0 -0
package/{readme.md → README.md}
RENAMED
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import { OptionalKeysOf } from 'type-fest';
|
|
2
|
-
import { Options } from 'unplugin-vue-router';
|
|
3
|
-
import { RequiredPick } from 'type-plus';
|
|
4
|
-
import { AxiosRequestConfig, AxiosResponse, AxiosInstance } from 'axios';
|
|
5
|
-
import { UseAxiosOptions, UseAxiosReturn } from '@vueuse/integrations/useAxios';
|
|
6
|
-
export { UseAxiosOptions } from '@vueuse/integrations/useAxios';
|
|
7
2
|
|
|
8
3
|
/**
|
|
9
4
|
* rmmv特征基类
|
|
@@ -116,18 +111,6 @@ type Conditions = Condition[];
|
|
|
116
111
|
declare function isConditionsEvery(conditions: Condition[]): boolean;
|
|
117
112
|
declare function isConditionsSome(conditions: Condition[]): boolean;
|
|
118
113
|
|
|
119
|
-
type GetRouteName = NonNullable<Options["getRouteName"]>;
|
|
120
|
-
/**
|
|
121
|
-
* 自主生成路由名称
|
|
122
|
-
* @description
|
|
123
|
-
* 对插件自动生成的路由名称,很不满意,不好看,容易引起阅读歧义。
|
|
124
|
-
*
|
|
125
|
-
* 故自定义。
|
|
126
|
-
*
|
|
127
|
-
* unplugin-vue-router 插件的 getRouteName 配置项
|
|
128
|
-
*/
|
|
129
|
-
declare const getRouteName: GetRouteName;
|
|
130
|
-
|
|
131
114
|
/** 创建简单的异步任务 */
|
|
132
115
|
declare function generateSimpleAsyncTask<T extends (...args: any) => any>(func: T): (...args: any) => Promise<ReturnType<T>>;
|
|
133
116
|
type SimpleAsyncTask = ReturnType<typeof generateSimpleAsyncTask>;
|
|
@@ -180,117 +163,6 @@ declare function executePromiseTasks(config: TasksConfig,
|
|
|
180
163
|
*/
|
|
181
164
|
lastParams?: any): Promise<any>;
|
|
182
165
|
|
|
183
|
-
/** 拓展的类型参数 用于约束必填的字段 */
|
|
184
|
-
type KeyAxiosRequestConfig<D = any> = keyof AxiosRequestConfig<D>;
|
|
185
|
-
/** 填写key值的帮助类型 */
|
|
186
|
-
type KeyHelper<K extends KeyAxiosRequestConfig> = K;
|
|
187
|
-
type RemoveUrl<T extends KeyAxiosRequestConfig> = Exclude<T, "url">;
|
|
188
|
-
/**
|
|
189
|
-
* 创建 AxiosRequestConfig 的各种变种类型
|
|
190
|
-
* @description
|
|
191
|
-
* 目前需要给 AxiosRequestConfig 添加必填属性
|
|
192
|
-
*
|
|
193
|
-
* 故需要本工具创建各种变种类型
|
|
194
|
-
*
|
|
195
|
-
* @example CreateAxiosRequestConfig<"url", D>
|
|
196
|
-
*/
|
|
197
|
-
type CreateAxiosRequestConfig<K extends keyof Target, D = any, Target = AxiosRequestConfig<D>> = RequiredPick<Target, K>;
|
|
198
|
-
/** 拓展K泛型后的类型 */
|
|
199
|
-
interface StrictUseAxiosReturn<T,
|
|
200
|
-
/**
|
|
201
|
-
* 拓展的类型参数 用于约束必填的字段
|
|
202
|
-
* @description
|
|
203
|
-
* 这里不需要提供默认的取值
|
|
204
|
-
*/
|
|
205
|
-
K extends KeyAxiosRequestConfig<D>, R, D> extends UseAxiosReturn<T, R, D> {
|
|
206
|
-
/**
|
|
207
|
-
* Manually call the axios request
|
|
208
|
-
*/
|
|
209
|
-
execute: (url?: string | CreateAxiosRequestConfig<K, D>, config?: CreateAxiosRequestConfig<K, D>) => Promise<StrictUseAxiosReturn<T, K, R, D>>;
|
|
210
|
-
}
|
|
211
|
-
declare module "@vueuse/integrations/useAxios" {
|
|
212
|
-
/**
|
|
213
|
-
* 拓展类型参数后的 useAxios 函数
|
|
214
|
-
* @description
|
|
215
|
-
* 在我们的封装中 使用本类型
|
|
216
|
-
*/
|
|
217
|
-
function useAxios<T = any,
|
|
218
|
-
/** 拓展的类型参数 用于约束必填的字段 */
|
|
219
|
-
K extends KeyAxiosRequestConfig<D> = "url", R = AxiosResponse<T>, D = any>(url: string, config: AxiosRequestConfig<D>, instance: AxiosInstance, options?: UseAxiosOptions): StrictUseAxiosReturn<T, K, R, D> & Promise<StrictUseAxiosReturn<T, K, R, D>>;
|
|
220
|
-
}
|
|
221
|
-
/** 包装器的参数 */
|
|
222
|
-
interface UseAxiosWrapperParams<
|
|
223
|
-
/**
|
|
224
|
-
* 业务数据类型
|
|
225
|
-
* @description
|
|
226
|
-
* 必须先填写业务类型
|
|
227
|
-
*/
|
|
228
|
-
T = any,
|
|
229
|
-
/**
|
|
230
|
-
* AxiosRequestConfig 默认必填的字段
|
|
231
|
-
* @description
|
|
232
|
-
* 用于约束其他类型的字段
|
|
233
|
-
*
|
|
234
|
-
* 然后才能填写必传的参数类型
|
|
235
|
-
*
|
|
236
|
-
* 默认为 必填url请求地址的 config 请求配置
|
|
237
|
-
*/
|
|
238
|
-
K extends KeyAxiosRequestConfig<D> = "url",
|
|
239
|
-
/**
|
|
240
|
-
* UseAxiosOptions 的派生类型
|
|
241
|
-
*/
|
|
242
|
-
UseAxiosOptionsLike extends UseAxiosOptions = UseAxiosOptions,
|
|
243
|
-
/**
|
|
244
|
-
* AxiosRequestConfig 用的类型
|
|
245
|
-
* @description
|
|
246
|
-
* 最后才可以传递此类型
|
|
247
|
-
*/
|
|
248
|
-
D = any> {
|
|
249
|
-
/**
|
|
250
|
-
* axios的配置类型
|
|
251
|
-
* @description
|
|
252
|
-
* 默认为 必填url请求地址的 config 请求配置
|
|
253
|
-
*/
|
|
254
|
-
config: CreateAxiosRequestConfig<K, D>;
|
|
255
|
-
/**
|
|
256
|
-
* axios实例
|
|
257
|
-
* @description
|
|
258
|
-
* 对于包装器函数而言 必须传递有意义的请求实例
|
|
259
|
-
*/
|
|
260
|
-
instance: AxiosInstance;
|
|
261
|
-
/** useAxios 的选项配置 */
|
|
262
|
-
options: UseAxiosOptionsLike;
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* useAxios 的包装函数
|
|
266
|
-
* @description
|
|
267
|
-
* 其本质是对 useAxios 函数的封装,仅仅是包装了参数层
|
|
268
|
-
*
|
|
269
|
-
* 预期设计成一个万能的 通用的请求函数
|
|
270
|
-
*/
|
|
271
|
-
declare function useAxiosWrapper<T, K extends KeyAxiosRequestConfig, D = any>(params: UseAxiosWrapperParams): StrictUseAxiosReturn<T, K, AxiosResponse<T, any>, D> & Promise<StrictUseAxiosReturn<T, K, AxiosResponse<T, any>, D>>;
|
|
272
|
-
|
|
273
|
-
/** 包的信息 */
|
|
274
|
-
interface PackageInfo {
|
|
275
|
-
/** 包名 */
|
|
276
|
-
name: string;
|
|
277
|
-
/** 包的描述 */
|
|
278
|
-
description: string;
|
|
279
|
-
/** 带有包名的官方镜像源地址 */
|
|
280
|
-
url: `https://npm.im/${string}`;
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* 获得阮喵喵全部的包信息
|
|
284
|
-
* @description
|
|
285
|
-
* 这是一个node环境下的函数,用于获取阮喵喵的所有包的信息。
|
|
286
|
-
*
|
|
287
|
-
* 使用的是node的child_process模块,调用pnpm命令获取包信息。
|
|
288
|
-
*
|
|
289
|
-
* - 默认仅考虑pnpm包
|
|
290
|
-
* - 在node环境下运行
|
|
291
|
-
*/
|
|
292
|
-
declare function getRuanCatPkgInfo(): Promise<PackageInfo[]>;
|
|
293
|
-
|
|
294
166
|
/**
|
|
295
167
|
* pnpm-workspace.yaml 文件的类型声明
|
|
296
168
|
* @description
|
|
@@ -328,4 +200,4 @@ type Prettify<T> = {
|
|
|
328
200
|
*/
|
|
329
201
|
type ToNumberLike<T extends number> = T | `${T}`;
|
|
330
202
|
|
|
331
|
-
export { type AttributePromptTool, type BaseTask, type Condition, type Conditions, type
|
|
203
|
+
export { type AttributePromptTool, type BaseTask, type Condition, type Conditions, type FunctionKeys, type HandleStrategy, type ParallelTasks, type PnpmWorkspace, type Prettify, type PromiseTasksConfig, type QueueTasks, RmmvClass, type SimpleAsyncTask, type SingleTasks, type Task, type TaskType, type TasksConfig, type ToNumberLike, defaultHandleStrategy, type defaultHandleStrategy_FuncationName, definePromiseTasks, executePromiseTasks, generateSimpleAsyncTask, initFlag, isConditionsEvery, isConditionsSome, rmmvClassExpandTools, runPromiseByConcurrency, runPromiseByQueue, taskTypes };
|
package/dist/index.js
CHANGED
|
@@ -842,17 +842,6 @@ function isConditionsSome(conditions) {
|
|
|
842
842
|
return conditions.some((condition) => condition());
|
|
843
843
|
}
|
|
844
844
|
|
|
845
|
-
// src/unplugin-vue-router/index.ts
|
|
846
|
-
var getRouteName = function _getRouteName(node) {
|
|
847
|
-
if (!node.parent) {
|
|
848
|
-
return "";
|
|
849
|
-
}
|
|
850
|
-
const last = _getRouteName(node.parent);
|
|
851
|
-
const connector = last === "" ? "" : "-";
|
|
852
|
-
const current = node.value.rawSegment === "index" ? "" : `${connector}${node.value.rawSegment}`;
|
|
853
|
-
return last + current;
|
|
854
|
-
};
|
|
855
|
-
|
|
856
845
|
// src/define-promise-tasks.ts
|
|
857
846
|
var taskTypes = ["single", "parallel", "queue"];
|
|
858
847
|
function isSingleTasks(config) {
|
|
@@ -920,62 +909,18 @@ async function runPromiseByQueue(promises) {
|
|
|
920
909
|
async function runPromiseByConcurrency(promises) {
|
|
921
910
|
await Promise.all(promises.map((promise) => promise()));
|
|
922
911
|
}
|
|
923
|
-
|
|
924
|
-
// src/vueuse/useAxios.ts
|
|
925
|
-
import { useAxios } from "@vueuse/integrations/useAxios";
|
|
926
|
-
function useAxiosWrapper(params) {
|
|
927
|
-
const {
|
|
928
|
-
config: { url },
|
|
929
|
-
config,
|
|
930
|
-
instance,
|
|
931
|
-
options
|
|
932
|
-
} = params;
|
|
933
|
-
return useAxios(url, config, instance, options);
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
// src/ruan-cat-pkg-info.ts
|
|
937
|
-
import { spawnSync } from "node:child_process";
|
|
938
|
-
async function getRuanCatPkgInfo() {
|
|
939
|
-
return new Promise((resolve, reject) => {
|
|
940
|
-
const result = spawnSync("pnpm", ["s", "@ruan-cat/*", "--registry", "https://registry.npmmirror.com/", "--json"], {
|
|
941
|
-
encoding: "utf-8"
|
|
942
|
-
});
|
|
943
|
-
if (result.error) {
|
|
944
|
-
console.error(`Error executing command: ${result.error.message}`);
|
|
945
|
-
reject(result.error);
|
|
946
|
-
return;
|
|
947
|
-
}
|
|
948
|
-
if (result.stderr) {
|
|
949
|
-
console.error(`Error in output: ${result.stderr}`);
|
|
950
|
-
reject(new Error(result.stderr));
|
|
951
|
-
return;
|
|
952
|
-
}
|
|
953
|
-
const packages = JSON.parse(result.stdout);
|
|
954
|
-
const res = packages.map(
|
|
955
|
-
(pkg) => ({
|
|
956
|
-
name: pkg.name,
|
|
957
|
-
description: pkg.description,
|
|
958
|
-
url: `https://npm.im/${pkg.name}`
|
|
959
|
-
})
|
|
960
|
-
);
|
|
961
|
-
resolve(res);
|
|
962
|
-
});
|
|
963
|
-
}
|
|
964
912
|
export {
|
|
965
913
|
defaultHandleStrategy,
|
|
966
914
|
definePromiseTasks,
|
|
967
915
|
executePromiseTasks,
|
|
968
916
|
generateSimpleAsyncTask,
|
|
969
|
-
getRouteName,
|
|
970
|
-
getRuanCatPkgInfo,
|
|
971
917
|
initFlag,
|
|
972
918
|
isConditionsEvery,
|
|
973
919
|
isConditionsSome,
|
|
974
920
|
rmmvClassExpandTools,
|
|
975
921
|
runPromiseByConcurrency,
|
|
976
922
|
runPromiseByQueue,
|
|
977
|
-
taskTypes
|
|
978
|
-
useAxiosWrapper
|
|
923
|
+
taskTypes
|
|
979
924
|
};
|
|
980
925
|
/*! Bundled license information:
|
|
981
926
|
|