-
Notifications
You must be signed in to change notification settings - Fork 951
Expand file tree
/
Copy pathsource.config.ts
More file actions
108 lines (105 loc) · 3.22 KB
/
Copy pathsource.config.ts
File metadata and controls
108 lines (105 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import remarkDirective from "remark-directive";
import { remarkDirectiveAdmonition, remarkMdxFiles } from "fumadocs-core/mdx-plugins";
import { remarkImage } from "fumadocs-core/mdx-plugins";
import { defineConfig, defineDocs, frontmatterSchema, metaSchema } from "fumadocs-mdx/config";
import lastModified from "fumadocs-mdx/plugins/last-modified";
import { z } from "zod";
import convert from "npm-to-yarn";
import remarkConsoleUtm from "@/lib/remark-console-utm";
// npm-to-yarn only converts the last line of multi-line strings,
// so we split, convert each line, and rejoin.
function convertLine(cmd: string, pm: "npm" | "pnpm" | "yarn" | "bun"): string {
return cmd
.split("\n")
.map((line) => {
// npm-to-yarn strips @latest from `npm create X@latest` and handles the
// npm-specific `--` separator inconsistently across PMs. Handle this
// pattern directly instead of fighting the library's output.
const m = line.match(/^npm create ([^\s]+@latest)((?:\s+--\s*.*)?)$/);
if (m) {
const pkg = m[1];
const flags = m[2].replace(/^\s+--\s*/, " ").trim();
const f = flags ? ` ${flags}` : "";
switch (pm) {
case "npm":
return line;
case "pnpm":
return `pnpm create ${pkg}${f}`;
case "yarn":
return `yarn create ${pkg}${f}`;
case "bun":
return `bun create ${pkg}${f}`;
}
}
return convert(line.replace(/^npm init -y$/, "npm init"), pm);
})
.join("\n");
}
export const docs = defineDocs({
dir: "content/docs",
docs: {
schema: frontmatterSchema.extend({
image: z.string().optional(),
badge: z.enum(["early-access", "deprecated", "preview"]).optional(),
url: z.string(),
metaTitle: z.string(),
metaDescription: z.string(),
aiPrompt: z.string().optional(),
noindex: z.boolean().optional(),
}),
postprocess: {
includeProcessedMarkdown: true,
},
},
meta: {
schema: metaSchema,
},
});
export default defineConfig({
plugins: [lastModified()],
mdxOptions: {
remarkPlugins: [
remarkDirective,
[
remarkDirectiveAdmonition,
{
types: {
note: "info",
tip: "info",
info: "info",
warn: "warning",
warning: "warning",
danger: "error",
success: "success",
ppg: "ppg",
error: "error",
},
},
],
[remarkImage, { useImport: false }],
remarkMdxFiles,
remarkConsoleUtm,
],
remarkCodeTabOptions: {
parseMdx: true,
},
remarkNpmOptions: {
persist: {
id: "package-manager",
},
packageManagers: [
{
command: (cmd: string) => {
const converted = convertLine(cmd, "bun");
if (!converted) return undefined;
return converted.replace(/^bun x /, "bunx --bun ");
},
name: "bun",
},
{ command: (cmd: string) => convertLine(cmd, "pnpm"), name: "pnpm" },
{ command: (cmd: string) => convertLine(cmd, "yarn"), name: "yarn" },
{ command: (cmd: string) => convertLine(cmd, "npm"), name: "npm" },
],
},
},
});