@alauda/doom 0.9.1 → 0.10.1
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/lib/plugins/auto-sidebar/utils.js +6 -11
- package/lib/plugins/auto-sidebar/walk.js +21 -8
- package/lib/utils/fs.d.ts +2 -0
- package/lib/utils/fs.js +14 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +1 -0
- package/package.json +14 -15
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import fs from '
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
2
3
|
import { logger } from '@rspress/shared/logger';
|
|
3
4
|
import { loadFrontMatter } from '@rspress/shared/node-utils';
|
|
4
|
-
import
|
|
5
|
+
import { pathExists } from '../../utils/index.js';
|
|
5
6
|
export async function detectFilePath(rawPath, extensions) {
|
|
6
7
|
// The params doesn't have extension name, so we need to try to find the file with the extension name.
|
|
7
8
|
let realPath = rawPath;
|
|
@@ -9,7 +10,7 @@ export async function detectFilePath(rawPath, extensions) {
|
|
|
9
10
|
// pathname may contain .json, see issue: https://github.com/web-infra-dev/rspress/issues/951
|
|
10
11
|
if (!extensions.includes(fileExtname)) {
|
|
11
12
|
const pathWithExtension = extensions.map((ext) => `${rawPath}${ext}`);
|
|
12
|
-
const pathExistInfo = await Promise.all(pathWithExtension.map((p) =>
|
|
13
|
+
const pathExistInfo = await Promise.all(pathWithExtension.map((p) => pathExists(p)));
|
|
13
14
|
const findPath = pathWithExtension.find((_, i) => pathExistInfo[i]);
|
|
14
15
|
// file may be public resource, see issue: https://github.com/web-infra-dev/rspress/issues/1052
|
|
15
16
|
if (!fileExtname || findPath) {
|
|
@@ -49,13 +50,7 @@ export async function extractInfoFromFrontmatter(filePath, rootDir, extensions)
|
|
|
49
50
|
}
|
|
50
51
|
export function combineWalkResult(walks, versions) {
|
|
51
52
|
return walks.reduce((acc, cur, curIndex) => ({
|
|
52
|
-
nav: {
|
|
53
|
-
...acc.nav,
|
|
54
|
-
[versions[curIndex] || 'default']: cur.nav,
|
|
55
|
-
},
|
|
53
|
+
nav: { ...acc.nav, [versions[curIndex] || 'default']: cur.nav },
|
|
56
54
|
sidebar: { ...acc.sidebar, ...cur.sidebar },
|
|
57
|
-
}), {
|
|
58
|
-
nav: {},
|
|
59
|
-
sidebar: {},
|
|
60
|
-
});
|
|
55
|
+
}), { nav: {}, sidebar: {} });
|
|
61
56
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
1
2
|
import path from 'node:path';
|
|
2
3
|
import { isExternalUrl, removeLeadingSlash, removeTrailingSlash, slash, withBase, } from '@rspress/shared';
|
|
3
|
-
import fs from '@rspress/shared/fs-extra';
|
|
4
4
|
import { logger } from '@rspress/shared/logger';
|
|
5
5
|
import { unset } from 'es-toolkit/compat';
|
|
6
6
|
import picomatch from 'picomatch';
|
|
7
7
|
import { detectFilePath, extractInfoFromFrontmatter } from './utils.js';
|
|
8
|
+
import { pathExists, readJson } from '../../utils/index.js';
|
|
8
9
|
const sidebarSorter = (a, b) => {
|
|
9
10
|
const aWeight = 'weight' in a && a.weight != null ? a.weight : 100;
|
|
10
11
|
const bWeight = 'weight' in b && b.weight != null ? b.weight : 100;
|
|
@@ -25,10 +26,22 @@ const processSideMeta = (sideMeta, extensions, excludeRoutes) => {
|
|
|
25
26
|
}
|
|
26
27
|
const ignored = excludeRoutes.some((glob) => picomatch.isMatch(curr._fileKey, glob));
|
|
27
28
|
let filePart;
|
|
28
|
-
if (
|
|
29
|
-
(filePart = curr._fileKey.split('/').at(-1)) &&
|
|
29
|
+
if ((filePart = curr._fileKey.split('/').at(-1)) &&
|
|
30
30
|
extensions.some((ext) => filePart === `index${ext}`)) {
|
|
31
|
-
acc.index
|
|
31
|
+
if (acc.index?._fileKey) {
|
|
32
|
+
// zh/development/component-quickstart/index.md vs zh/development/index.mdx
|
|
33
|
+
const relative = path.relative(path.dirname(acc.index._fileKey), path.dirname(curr._fileKey));
|
|
34
|
+
if (relative === '..' || relative.endsWith('/..')) {
|
|
35
|
+
acc.others.unshift(acc.index);
|
|
36
|
+
acc.index = curr;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
acc.others.push(curr);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
acc.index = curr;
|
|
44
|
+
}
|
|
32
45
|
if (ignored) {
|
|
33
46
|
curr.link = '';
|
|
34
47
|
}
|
|
@@ -42,7 +55,7 @@ const processSideMeta = (sideMeta, extensions, excludeRoutes) => {
|
|
|
42
55
|
return result;
|
|
43
56
|
};
|
|
44
57
|
export async function scanSideMeta(workDir, rootDir, docsDir, routePrefix, extensions, ignoredDirs, excludeRoutes) {
|
|
45
|
-
if (!(await
|
|
58
|
+
if (!(await pathExists(workDir))) {
|
|
46
59
|
logger.error('[plugin-auto-sidebar]', `Generate sidebar meta error: ${workDir} not exists`);
|
|
47
60
|
}
|
|
48
61
|
const addRoutePrefix = (link) => `${routePrefix}${removeLeadingSlash(link)}`;
|
|
@@ -54,7 +67,7 @@ export async function scanSideMeta(workDir, rootDir, docsDir, routePrefix, exten
|
|
|
54
67
|
// Get the sidebar config from the `_meta.json` file
|
|
55
68
|
try {
|
|
56
69
|
// Don't use require to avoid require cache, which make hmr not work.
|
|
57
|
-
sideMeta =
|
|
70
|
+
sideMeta = await readJson(metaFile);
|
|
58
71
|
}
|
|
59
72
|
catch {
|
|
60
73
|
// If the `_meta.json` file doesn't exist, we will generate the sidebar config from the directory structure.
|
|
@@ -88,10 +101,10 @@ export async function scanSideMeta(workDir, rootDir, docsDir, routePrefix, exten
|
|
|
88
101
|
const { title } = await extractInfoFromFrontmatter(filePath, rootDir, extensions);
|
|
89
102
|
label = title;
|
|
90
103
|
};
|
|
91
|
-
if (
|
|
104
|
+
if (await pathExists(mdxFilePath)) {
|
|
92
105
|
await setLabelFromFilePath(mdxFilePath);
|
|
93
106
|
}
|
|
94
|
-
else if (
|
|
107
|
+
else if (await pathExists(mdFilePath)) {
|
|
95
108
|
await setLabelFromFilePath(mdFilePath);
|
|
96
109
|
}
|
|
97
110
|
return {
|
package/lib/utils/fs.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
export async function pathExists(path) {
|
|
3
|
+
try {
|
|
4
|
+
await fs.access(path);
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export async function readJson(path) {
|
|
12
|
+
const raw = await fs.readFile(path, 'utf8');
|
|
13
|
+
return JSON.parse(raw);
|
|
14
|
+
}
|
package/lib/utils/index.d.ts
CHANGED
package/lib/utils/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alauda/doom",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Doctor Doom making docs.",
|
|
6
6
|
"repository": {
|
|
@@ -38,15 +38,15 @@
|
|
|
38
38
|
"swc-node": "node --enable-source-maps --import @swc-node/register/esm-register"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@inquirer/prompts": "^7.
|
|
41
|
+
"@inquirer/prompts": "^7.3.1",
|
|
42
42
|
"@openapi-contrib/openapi-schema-to-json-schema": "^5.1.0",
|
|
43
|
-
"@rspress/core": "1.
|
|
44
|
-
"@shikijs/transformers": "^2.
|
|
43
|
+
"@rspress/core": "1.41.1",
|
|
44
|
+
"@shikijs/transformers": "^2.3.2",
|
|
45
45
|
"chokidar": "^4.0.3",
|
|
46
46
|
"clsx": "^2.1.1",
|
|
47
47
|
"commander": "^13.1.0",
|
|
48
48
|
"ejs": "^3.1.10",
|
|
49
|
-
"es-toolkit": "^1.
|
|
49
|
+
"es-toolkit": "^1.32.0",
|
|
50
50
|
"mermaid": "^11.4.1",
|
|
51
51
|
"openapi-types": "^12.1.3",
|
|
52
52
|
"picomatch": "^4.0.2",
|
|
@@ -55,34 +55,33 @@
|
|
|
55
55
|
"remark-directive": "^2.0.1",
|
|
56
56
|
"remark-frontmatter": "^4.0.1",
|
|
57
57
|
"remark-gfm": "^3.0.1",
|
|
58
|
-
"shiki": "^2.
|
|
58
|
+
"shiki": "^2.3.2",
|
|
59
59
|
"simple-git": "^3.27.0",
|
|
60
60
|
"swagger2openapi": "^7.0.8",
|
|
61
61
|
"tinyglobby": "^0.2.10",
|
|
62
|
-
"type-fest": "^4.
|
|
62
|
+
"type-fest": "^4.34.1",
|
|
63
63
|
"yaml": "^2.7.0",
|
|
64
64
|
"yoctocolors": "^2.1.1"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@eslint/js": "^9.
|
|
67
|
+
"@eslint/js": "^9.20.0",
|
|
68
68
|
"@swc-node/register": "^1.10.9",
|
|
69
|
-
"@swc/core": "1.10.
|
|
69
|
+
"@swc/core": "1.10.15",
|
|
70
70
|
"@types/ejs": "^3.1.5",
|
|
71
71
|
"@types/eslint__js": "^8.42.3",
|
|
72
|
-
"@types/
|
|
73
|
-
"@types/node": "^18.19.71",
|
|
72
|
+
"@types/node": "^18.19.75",
|
|
74
73
|
"@types/picomatch": "^3.0.2",
|
|
75
74
|
"@types/react-dom": "^18.3.5",
|
|
76
75
|
"@types/swagger2openapi": "^7.0.4",
|
|
77
76
|
"@unts/patch-package": "^8.0.0",
|
|
78
|
-
"eslint": "^9.
|
|
79
|
-
"lint-staged": "^15.4.
|
|
77
|
+
"eslint": "^9.20.0",
|
|
78
|
+
"lint-staged": "^15.4.3",
|
|
80
79
|
"npm-run-all2": "^7.0.2",
|
|
81
|
-
"prettier": "^3.
|
|
80
|
+
"prettier": "^3.5.0",
|
|
82
81
|
"prettier-plugin-pkg": "^0.18.1",
|
|
83
82
|
"simple-git-hooks": "^2.11.1",
|
|
84
83
|
"typescript": "^5.7.3",
|
|
85
|
-
"typescript-eslint": "^8.
|
|
84
|
+
"typescript-eslint": "^8.23.0"
|
|
86
85
|
},
|
|
87
86
|
"publishConfig": {
|
|
88
87
|
"access": "public"
|