@ruan-cat/vitepress-preset-config 2.7.0 → 2.9.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/config.d.mts +3 -3
- package/dist/config.mjs +55 -43
- package/package.json +2 -3
- package/src/config/add-changelog-to-doc.ts +31 -9
- package/src/config.mts +1 -1
package/dist/config.d.mts
CHANGED
|
@@ -127,14 +127,14 @@ interface CopyClaudeAgentsOptions {
|
|
|
127
127
|
*/
|
|
128
128
|
declare function copyClaudeAgents(options: CopyClaudeAgentsOptions): void;
|
|
129
129
|
|
|
130
|
-
interface AddChangelog2docOptions<T = Record<string, any>> {
|
|
130
|
+
interface AddChangelog2docOptions<T extends Record<string, any> = Record<string, any>> {
|
|
131
131
|
/** 目标文件夹 */
|
|
132
132
|
target: string;
|
|
133
133
|
/** 被插入到md头部的数据 */
|
|
134
|
-
data
|
|
134
|
+
data?: T;
|
|
135
135
|
}
|
|
136
136
|
/** 将变更日志添加到指定的文档目录内 并提供参数 */
|
|
137
|
-
declare function addChangelog2doc<T
|
|
137
|
+
declare function addChangelog2doc<T extends Record<string, any>>(options: AddChangelog2docOptions<T>): void;
|
|
138
138
|
|
|
139
139
|
type VitePressSidebarOptions = Parameters<typeof generateSidebar>[0];
|
|
140
140
|
/**
|
package/dist/config.mjs
CHANGED
|
@@ -119,6 +119,9 @@ function copyClaudeAgents(options) {
|
|
|
119
119
|
|
|
120
120
|
// src/config/add-changelog-to-doc.ts
|
|
121
121
|
import path4 from "path";
|
|
122
|
+
import fs4 from "fs";
|
|
123
|
+
import consola4 from "consola";
|
|
124
|
+
import matter from "gray-matter";
|
|
122
125
|
|
|
123
126
|
// src/utils/copy-changelog.ts
|
|
124
127
|
import fs3 from "fs";
|
|
@@ -142,18 +145,27 @@ function copyChangelogMd(target) {
|
|
|
142
145
|
}
|
|
143
146
|
|
|
144
147
|
// src/config/add-changelog-to-doc.ts
|
|
145
|
-
import { writeYaml2md } from "@ruan-cat/utils/node-esm";
|
|
146
148
|
function addChangelog2doc(options) {
|
|
147
|
-
const { data, target } = options;
|
|
149
|
+
const { data = pageOrderConfig.changelog, target } = options;
|
|
148
150
|
if (!hasChangelogMd()) {
|
|
149
151
|
return;
|
|
150
152
|
}
|
|
151
153
|
copyChangelogMd(target);
|
|
152
154
|
const mdPath = path4.resolve(process.cwd(), target, "CHANGELOG.md");
|
|
153
|
-
|
|
154
|
-
mdPath
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
try {
|
|
156
|
+
if (fs4.existsSync(mdPath)) {
|
|
157
|
+
const fileContent = fs4.readFileSync(mdPath, "utf-8");
|
|
158
|
+
const parsed = matter(fileContent);
|
|
159
|
+
const newContent = matter.stringify(parsed.content, data);
|
|
160
|
+
fs4.writeFileSync(mdPath, newContent, "utf-8");
|
|
161
|
+
consola4.success(`\u5DF2\u5C06YAML\u6570\u636E\u5199\u5165\u5230 ${mdPath}`);
|
|
162
|
+
} else {
|
|
163
|
+
consola4.warn(`\u6587\u4EF6 ${mdPath} \u4E0D\u5B58\u5728\uFF0C\u65E0\u6CD5\u5199\u5165 YAML frontmatter`);
|
|
164
|
+
}
|
|
165
|
+
} catch (error) {
|
|
166
|
+
consola4.error(`\u5199\u5165 YAML \u6570\u636E\u5230 ${mdPath} \u65F6\u53D1\u751F\u9519\u8BEF:`, error);
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
157
169
|
}
|
|
158
170
|
|
|
159
171
|
// src/config/plugins.ts
|
|
@@ -191,28 +203,28 @@ function handlePlugins(userConfig, extraConfig) {
|
|
|
191
203
|
}
|
|
192
204
|
|
|
193
205
|
// src/config/changelog-nav.ts
|
|
194
|
-
import
|
|
206
|
+
import consola5 from "consola";
|
|
195
207
|
import { isUndefined } from "lodash-es";
|
|
196
208
|
function handleChangeLog(userConfig) {
|
|
197
209
|
var _a;
|
|
198
210
|
if (!hasChangelogMd()) {
|
|
199
|
-
|
|
211
|
+
consola5.warn(` \u672A\u627E\u5230\u53D8\u66F4\u65E5\u5FD7\u6587\u4EF6\uFF0C\u4E0D\u6DFB\u52A0\u53D8\u66F4\u65E5\u5FD7\u5BFC\u822A\u680F\u3002 `);
|
|
200
212
|
return;
|
|
201
213
|
}
|
|
202
214
|
const nav = (_a = userConfig == null ? void 0 : userConfig.themeConfig) == null ? void 0 : _a.nav;
|
|
203
215
|
if (isUndefined(nav)) {
|
|
204
|
-
|
|
216
|
+
consola5.error(` \u5F53\u524D\u7684\u7528\u6237\u914D\u7F6E\u4E3A\uFF1A `, userConfig);
|
|
205
217
|
throw new Error(` nav \u9ED8\u8BA4\u63D0\u4F9B\u7684\u5BFC\u822A\u680F\u914D\u7F6E\u4E3A\u7A7A\u3002\u4E0D\u7B26\u5408\u9ED8\u8BA4\u914D\u7F6E\uFF0C\u8BF7\u68C0\u67E5\u3002 `);
|
|
206
218
|
}
|
|
207
219
|
nav.push({ text: "\u66F4\u65B0\u65E5\u5FD7", link: "/CHANGELOG.md" });
|
|
208
220
|
}
|
|
209
221
|
|
|
210
222
|
// src/config/prompts-nav.ts
|
|
211
|
-
import
|
|
223
|
+
import fs5 from "fs";
|
|
212
224
|
import path5 from "path";
|
|
213
|
-
import
|
|
225
|
+
import consola6 from "consola";
|
|
214
226
|
import { isUndefined as isUndefined2, merge } from "lodash-es";
|
|
215
|
-
import
|
|
227
|
+
import matter2 from "gray-matter";
|
|
216
228
|
var PROMPTS_INDEX_MD_PATH = "prompts/index.md";
|
|
217
229
|
function getProjectRootFromArgs() {
|
|
218
230
|
const args = process.argv;
|
|
@@ -239,8 +251,8 @@ function getVitepressProjectRoot() {
|
|
|
239
251
|
const projectRootFromArgs = getProjectRootFromArgs();
|
|
240
252
|
if (projectRootFromArgs) {
|
|
241
253
|
const vitepressDir2 = path5.join(projectRootFromArgs, ".vitepress");
|
|
242
|
-
if (
|
|
243
|
-
|
|
254
|
+
if (fs5.existsSync(vitepressDir2)) {
|
|
255
|
+
consola6.log("\u4ECE\u547D\u4EE4\u884C\u53C2\u6570\u83B7\u53D6\u5230 VitePress \u9879\u76EE\u6839\u76EE\u5F55\uFF1A", projectRootFromArgs);
|
|
244
256
|
return projectRootFromArgs;
|
|
245
257
|
}
|
|
246
258
|
}
|
|
@@ -248,19 +260,19 @@ function getVitepressProjectRoot() {
|
|
|
248
260
|
const root = path5.parse(currentDir).root;
|
|
249
261
|
while (currentDir !== root) {
|
|
250
262
|
const vitepressDir2 = path5.join(currentDir, ".vitepress");
|
|
251
|
-
if (
|
|
252
|
-
|
|
263
|
+
if (fs5.existsSync(vitepressDir2)) {
|
|
264
|
+
consola6.log("\u901A\u8FC7\u5411\u4E0A\u67E5\u627E\u83B7\u53D6\u5230 VitePress \u9879\u76EE\u6839\u76EE\u5F55\uFF1A", currentDir);
|
|
253
265
|
return currentDir;
|
|
254
266
|
}
|
|
255
267
|
currentDir = path5.dirname(currentDir);
|
|
256
268
|
}
|
|
257
269
|
const vitepressDir = path5.join(root, ".vitepress");
|
|
258
|
-
if (
|
|
259
|
-
|
|
270
|
+
if (fs5.existsSync(vitepressDir)) {
|
|
271
|
+
consola6.log("\u5728\u6587\u4EF6\u7CFB\u7EDF\u6839\u76EE\u5F55\u627E\u5230 VitePress \u9879\u76EE\u6839\u76EE\u5F55\uFF1A", root);
|
|
260
272
|
return root;
|
|
261
273
|
}
|
|
262
274
|
const fallbackDir = process.cwd();
|
|
263
|
-
|
|
275
|
+
consola6.warn("\u672A\u627E\u5230 .vitepress \u76EE\u5F55\uFF0C\u56DE\u9000\u5230\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55\uFF1A", fallbackDir);
|
|
264
276
|
return fallbackDir;
|
|
265
277
|
}
|
|
266
278
|
function getVitepressSourceDirectory(userConfig) {
|
|
@@ -268,19 +280,19 @@ function getVitepressSourceDirectory(userConfig) {
|
|
|
268
280
|
const srcDir = userConfig.srcDir;
|
|
269
281
|
if (srcDir) {
|
|
270
282
|
const sourceDirectory = path5.resolve(projectRoot, srcDir);
|
|
271
|
-
|
|
272
|
-
|
|
283
|
+
consola6.log("\u4ECE\u914D\u7F6E\u4E2D\u83B7\u53D6\u5230 srcDir:", srcDir);
|
|
284
|
+
consola6.log("VitePress \u6E90\u76EE\u5F55\u4E3A\uFF1A", sourceDirectory);
|
|
273
285
|
return sourceDirectory;
|
|
274
286
|
}
|
|
275
|
-
|
|
287
|
+
consola6.log("\u914D\u7F6E\u4E2D\u672A\u6307\u5B9A srcDir\uFF0C\u6E90\u76EE\u5F55\u7B49\u4E8E\u9879\u76EE\u6839\u76EE\u5F55\uFF1A", projectRoot);
|
|
276
288
|
return projectRoot;
|
|
277
289
|
}
|
|
278
290
|
function hasPromptsIndexMd(userConfig) {
|
|
279
291
|
const sourceDir = getVitepressSourceDirectory(userConfig);
|
|
280
|
-
const res =
|
|
292
|
+
const res = fs5.existsSync(path5.resolve(sourceDir, PROMPTS_INDEX_MD_PATH));
|
|
281
293
|
if (!res) {
|
|
282
|
-
|
|
283
|
-
|
|
294
|
+
consola6.log("\u5F53\u524D\u9879\u76EE\u7684vitepress\u6E90\u76EE\u5F55\u4E3A\uFF1A", sourceDir);
|
|
295
|
+
consola6.warn(`\u5F53\u524D\u9879\u76EE\u7684vitepress\u6E90\u76EE\u5F55\u4E0D\u5B58\u5728 ${PROMPTS_INDEX_MD_PATH} \u6587\u4EF6`);
|
|
284
296
|
}
|
|
285
297
|
return res;
|
|
286
298
|
}
|
|
@@ -291,44 +303,44 @@ function writeYaml2PromptsIndexMd(userConfig, data) {
|
|
|
291
303
|
try {
|
|
292
304
|
let fileContent = "";
|
|
293
305
|
let existingData = {};
|
|
294
|
-
if (
|
|
295
|
-
fileContent =
|
|
296
|
-
const parsed =
|
|
306
|
+
if (fs5.existsSync(mdPath)) {
|
|
307
|
+
fileContent = fs5.readFileSync(mdPath, "utf-8");
|
|
308
|
+
const parsed = matter2(fileContent);
|
|
297
309
|
if (parsed.data && Object.keys(parsed.data).length > 0) {
|
|
298
310
|
existingData = parsed.data;
|
|
299
|
-
|
|
311
|
+
consola6.log("\u68C0\u6D4B\u5230\u5DF2\u6709 YAML frontmatter\uFF0C\u5C06\u8FDB\u884C\u6570\u636E\u5408\u5E76");
|
|
300
312
|
} else {
|
|
301
|
-
|
|
313
|
+
consola6.log("\u6587\u4EF6\u5B58\u5728\u4F46\u6CA1\u6709 YAML frontmatter\uFF0C\u5C06\u5199\u5165\u65B0\u7684 frontmatter");
|
|
302
314
|
}
|
|
303
315
|
const mergedData = merge({}, existingData, newData);
|
|
304
|
-
const newContent =
|
|
305
|
-
|
|
306
|
-
|
|
316
|
+
const newContent = matter2.stringify(parsed.content, mergedData);
|
|
317
|
+
fs5.writeFileSync(mdPath, newContent, "utf-8");
|
|
318
|
+
consola6.success(`\u5DF2\u5C06YAML\u6570\u636E\u5199\u5165\u5230 ${mdPath}`);
|
|
307
319
|
} else {
|
|
308
|
-
|
|
320
|
+
consola6.warn(`\u6587\u4EF6 ${mdPath} \u4E0D\u5B58\u5728\uFF0C\u5C06\u521B\u5EFA\u65B0\u6587\u4EF6`);
|
|
309
321
|
const dir = path5.dirname(mdPath);
|
|
310
|
-
if (!
|
|
311
|
-
|
|
322
|
+
if (!fs5.existsSync(dir)) {
|
|
323
|
+
fs5.mkdirSync(dir, { recursive: true });
|
|
312
324
|
}
|
|
313
|
-
const newContent =
|
|
314
|
-
|
|
315
|
-
|
|
325
|
+
const newContent = matter2.stringify("", newData);
|
|
326
|
+
fs5.writeFileSync(mdPath, newContent, "utf-8");
|
|
327
|
+
consola6.success(`\u5DF2\u521B\u5EFA\u6587\u4EF6\u5E76\u5199\u5165YAML\u6570\u636E\u5230 ${mdPath}`);
|
|
316
328
|
}
|
|
317
329
|
} catch (error) {
|
|
318
|
-
|
|
330
|
+
consola6.error(`\u5199\u5165 YAML \u6570\u636E\u5230 ${mdPath} \u65F6\u53D1\u751F\u9519\u8BEF:`, error);
|
|
319
331
|
throw error;
|
|
320
332
|
}
|
|
321
333
|
}
|
|
322
334
|
function handlePrompts(userConfig) {
|
|
323
335
|
var _a;
|
|
324
336
|
if (!hasPromptsIndexMd(userConfig)) {
|
|
325
|
-
|
|
337
|
+
consola6.warn(` \u672A\u627E\u5230\u63D0\u793A\u8BCD\u7D22\u5F15\u6587\u4EF6\uFF0C\u4E0D\u6DFB\u52A0\u63D0\u793A\u8BCD\u5BFC\u822A\u680F\u3002 `);
|
|
326
338
|
return;
|
|
327
339
|
}
|
|
328
340
|
writeYaml2PromptsIndexMd(userConfig);
|
|
329
341
|
const nav = (_a = userConfig == null ? void 0 : userConfig.themeConfig) == null ? void 0 : _a.nav;
|
|
330
342
|
if (isUndefined2(nav)) {
|
|
331
|
-
|
|
343
|
+
consola6.error(` \u5F53\u524D\u7684\u7528\u6237\u914D\u7F6E\u4E3A\uFF1A `, userConfig);
|
|
332
344
|
throw new Error(` nav \u9ED8\u8BA4\u63D0\u4F9B\u7684\u5BFC\u822A\u680F\u914D\u7F6E\u4E3A\u7A7A\u3002\u4E0D\u7B26\u5408\u9ED8\u8BA4\u914D\u7F6E\uFF0C\u8BF7\u68C0\u67E5\u3002 `);
|
|
333
345
|
}
|
|
334
346
|
nav.push({ text: "\u63D0\u793A\u8BCD", link: `/${PROMPTS_INDEX_MD_PATH}` });
|
|
@@ -408,7 +420,7 @@ import { copyOrDownloadAsMarkdownButtons } from "vitepress-plugin-llms";
|
|
|
408
420
|
import { MermaidPlugin } from "@leelaa/vitepress-plugin-extended";
|
|
409
421
|
import { defineTeekConfig as defineTeekConfig2 } from "vitepress-theme-teek/config";
|
|
410
422
|
var defaultSidebarOptions = {
|
|
411
|
-
// documentRootPath: "src",
|
|
423
|
+
// documentRootPath: "./src",
|
|
412
424
|
// 侧边栏需要折叠
|
|
413
425
|
collapsed: true,
|
|
414
426
|
// 不需要配置折叠嵌套深度
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ruan-cat/vitepress-preset-config",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"description": "用于给大多数的vitepress项目提供一个预设的配置文件。",
|
|
5
5
|
"homepage": "https://vitepress-preset.ruancat6312.top",
|
|
6
6
|
"types": "./src/config.mts",
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
"@shikijs/vitepress-twoslash": "^3.13.0",
|
|
12
12
|
"consola": "^3.4.2",
|
|
13
13
|
"gray-matter": "^4.0.3",
|
|
14
|
-
"js-yaml": "^4.1.0",
|
|
15
14
|
"lodash-es": "^4.17.21",
|
|
16
15
|
"markdown-it-async": "^2.2.0",
|
|
17
16
|
"markdown-it-mathjax3": "^4.3.2",
|
|
@@ -20,7 +19,7 @@
|
|
|
20
19
|
"vitepress-sidebar": "^1.33.0",
|
|
21
20
|
"vitepress-theme-teek": "^1.4.6",
|
|
22
21
|
"vue": "^3.5.21",
|
|
23
|
-
"@ruan-cat/utils": "^4.
|
|
22
|
+
"@ruan-cat/utils": "^4.15.0"
|
|
24
23
|
},
|
|
25
24
|
"devDependencies": {
|
|
26
25
|
"@types/lodash-es": "^4.17.12",
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import consola from "consola";
|
|
4
|
+
import matter from "gray-matter";
|
|
2
5
|
|
|
3
6
|
import { copyChangelogMd, hasChangelogMd } from "../utils/copy-changelog";
|
|
4
|
-
import {
|
|
7
|
+
import { pageOrderConfig } from "./page-order-config";
|
|
5
8
|
|
|
6
|
-
export interface AddChangelog2docOptions<T = Record<string, any>> {
|
|
9
|
+
export interface AddChangelog2docOptions<T extends Record<string, any> = Record<string, any>> {
|
|
7
10
|
/** 目标文件夹 */
|
|
8
11
|
target: string;
|
|
9
12
|
|
|
10
13
|
/** 被插入到md头部的数据 */
|
|
11
|
-
data
|
|
14
|
+
data?: T;
|
|
12
15
|
}
|
|
13
16
|
|
|
14
17
|
/** 将变更日志添加到指定的文档目录内 并提供参数 */
|
|
15
|
-
export function addChangelog2doc<T
|
|
16
|
-
const { data, target } = options;
|
|
18
|
+
export function addChangelog2doc<T extends Record<string, any>>(options: AddChangelog2docOptions<T>) {
|
|
19
|
+
const { data = pageOrderConfig.changelog, target } = options;
|
|
17
20
|
|
|
18
21
|
if (!hasChangelogMd()) {
|
|
19
22
|
return;
|
|
@@ -22,8 +25,27 @@ export function addChangelog2doc<T>(options: AddChangelog2docOptions<T>) {
|
|
|
22
25
|
copyChangelogMd(target);
|
|
23
26
|
|
|
24
27
|
const mdPath = path.resolve(process.cwd(), target, "CHANGELOG.md");
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
if (fs.existsSync(mdPath)) {
|
|
31
|
+
// 读取 markdown 文件
|
|
32
|
+
const fileContent = fs.readFileSync(mdPath, "utf-8");
|
|
33
|
+
|
|
34
|
+
// 使用 gray-matter 解析文件
|
|
35
|
+
const parsed = matter(fileContent);
|
|
36
|
+
|
|
37
|
+
// 使用 gray-matter 的 stringify 方法生成新的文件内容
|
|
38
|
+
// 直接使用提供的 data,覆盖原有的 frontmatter
|
|
39
|
+
const newContent = matter.stringify(parsed.content, data);
|
|
40
|
+
|
|
41
|
+
// 写入文件
|
|
42
|
+
fs.writeFileSync(mdPath, newContent, "utf-8");
|
|
43
|
+
consola.success(`已将YAML数据写入到 ${mdPath}`);
|
|
44
|
+
} else {
|
|
45
|
+
consola.warn(`文件 ${mdPath} 不存在,无法写入 YAML frontmatter`);
|
|
46
|
+
}
|
|
47
|
+
} catch (error) {
|
|
48
|
+
consola.error(`写入 YAML 数据到 ${mdPath} 时发生错误:`, error);
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
29
51
|
}
|
package/src/config.mts
CHANGED