@ruan-cat/utils 4.2.2 → 4.3.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/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 ruan-cat
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/node-esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/node-esm/ruan-cat-pkg-info.ts
|
|
2
|
-
import { spawnSync } from "
|
|
2
|
+
import { spawnSync } from "child_process";
|
|
3
3
|
async function getRuanCatPkgInfo() {
|
|
4
4
|
return new Promise((resolve, reject) => {
|
|
5
5
|
const result = spawnSync("pnpm", ["s", "@ruan-cat/*", "--registry", "https://registry.npmmirror.com/", "--json"], {
|
|
@@ -28,7 +28,7 @@ async function getRuanCatPkgInfo() {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
// src/node-cjs/tools.ts
|
|
31
|
-
import { spawnSync as spawnSync2 } from "
|
|
31
|
+
import { spawnSync as spawnSync2 } from "child_process";
|
|
32
32
|
|
|
33
33
|
// src/simple-promise-tools.ts
|
|
34
34
|
function generateSimpleAsyncTask(func) {
|
|
@@ -108,8 +108,8 @@ async function clean(targets) {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
// src/node-esm/scripts/copy-changelog.ts
|
|
111
|
-
import fs from "
|
|
112
|
-
import path from "
|
|
111
|
+
import fs from "fs";
|
|
112
|
+
import path from "path";
|
|
113
113
|
import consola2 from "consola";
|
|
114
114
|
function hasChangelogMd() {
|
|
115
115
|
const res = fs.existsSync(path.resolve(process.cwd(), "CHANGELOG.md"));
|
|
@@ -129,7 +129,7 @@ function copyChangelogMd(target) {
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
// src/node-esm/scripts/yaml-to-md.ts
|
|
132
|
-
import { readFileSync, writeFileSync } from "
|
|
132
|
+
import { readFileSync, writeFileSync } from "fs";
|
|
133
133
|
import { consola as consola3 } from "consola";
|
|
134
134
|
import { isUndefined } from "lodash-es";
|
|
135
135
|
|
|
@@ -2780,7 +2780,7 @@ ${mdContent}`;
|
|
|
2780
2780
|
}
|
|
2781
2781
|
|
|
2782
2782
|
// src/node-esm/scripts/add-changelog-to-doc.ts
|
|
2783
|
-
import path2 from "
|
|
2783
|
+
import path2 from "path";
|
|
2784
2784
|
function addChangelog2doc(options) {
|
|
2785
2785
|
const { data, target } = options;
|
|
2786
2786
|
if (!hasChangelogMd()) {
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// 工具包文档项目 直接导入生成文档配置 避免出现循环依赖
|
|
2
|
-
import { setUserConfig, setGenerateSidebar } from "../../../vitepress-preset-config";
|
|
2
|
+
import { setUserConfig, setGenerateSidebar, withMermaid } from "../../../vitepress-preset-config";
|
|
3
3
|
import { addChangelog2doc } from "@ruan-cat/utils/node-esm";
|
|
4
4
|
|
|
5
5
|
import { description } from "../../package.json";
|
|
@@ -31,4 +31,4 @@ const userConfig = setUserConfig({
|
|
|
31
31
|
userConfig.themeConfig.sidebar = setGenerateSidebar({
|
|
32
32
|
documentRootPath: "src",
|
|
33
33
|
});
|
|
34
|
-
export default userConfig;
|
|
34
|
+
export default withMermaid(userConfig);
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 处理自动路由
|
|
3
|
+
* @description
|
|
4
|
+
* 处理来自虚拟模块 `vue-router/auto-routes` 提供的 routes 数据
|
|
5
|
+
*
|
|
6
|
+
* 将该数据按照格式处理多出来的组件目录层级 移除掉脏数据
|
|
7
|
+
*
|
|
8
|
+
* 最终生成符合常规意义下的父子路由配置数组
|
|
9
|
+
*/
|
|
10
|
+
import type { RouteRecordRaw } from "vue-router";
|
|
11
|
+
import { omit } from "lodash-es";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 处理单个路由,包括处理空路径子路由和拼接完整路径
|
|
15
|
+
* @param route 原始路由配置
|
|
16
|
+
* @param parentPath 父路由路径
|
|
17
|
+
* @returns 处理后的路由配置
|
|
18
|
+
*/
|
|
19
|
+
export function processRoute(route: RouteRecordRaw, parentPath = ""): RouteRecordRaw {
|
|
20
|
+
// 创建路由副本,避免修改原始对象
|
|
21
|
+
const processedRoute: RouteRecordRaw = { ...route };
|
|
22
|
+
|
|
23
|
+
// 拼接完整路径
|
|
24
|
+
let fullPath = route.path;
|
|
25
|
+
if (parentPath && !fullPath.startsWith("/")) {
|
|
26
|
+
fullPath = `${parentPath}/${fullPath}`.replace(/\/\//g, "/");
|
|
27
|
+
}
|
|
28
|
+
processedRoute.path = fullPath;
|
|
29
|
+
|
|
30
|
+
// 处理子路由
|
|
31
|
+
if (Array.isArray(route.children) && route.children.length > 0) {
|
|
32
|
+
// 查找空路径子路由
|
|
33
|
+
const emptyPathChild = route.children.find((child) => child.path === "");
|
|
34
|
+
|
|
35
|
+
// 将空路径子路由的所有信息(除了path)复制到父路由
|
|
36
|
+
if (emptyPathChild) {
|
|
37
|
+
// 使用lodash-es的omit函数,复制除path外的所有属性
|
|
38
|
+
Object.assign(processedRoute, omit(emptyPathChild, ["path"]));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// 处理非空路径子路由
|
|
42
|
+
const processedChildren = route.children
|
|
43
|
+
.filter((child) => child.path !== "") // 过滤掉空路径子路由
|
|
44
|
+
.map((child) => processRoute(child, fullPath)); // 递归处理每个子路由
|
|
45
|
+
|
|
46
|
+
// 只有在有子路由的情况下才保留children属性
|
|
47
|
+
if (processedChildren.length > 0) {
|
|
48
|
+
processedRoute.children = processedChildren;
|
|
49
|
+
} else {
|
|
50
|
+
delete processedRoute.children;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return processedRoute;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 处理自动路由脏数据
|
|
59
|
+
* @param routes 原始路由配置
|
|
60
|
+
* @returns 处理后的路由配置
|
|
61
|
+
*/
|
|
62
|
+
export function disposalAutoRouter(routes: RouteRecordRaw[]): RouteRecordRaw[] {
|
|
63
|
+
if (!Array.isArray(routes) || routes.length === 0) {
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// 处理所有顶级路由
|
|
68
|
+
return routes.map((route) => processRoute(route));
|
|
69
|
+
}
|