@forge-ts/gen 0.4.0 → 0.5.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/index.d.ts +268 -67
- package/dist/index.js +702 -19
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,3 +1,674 @@
|
|
|
1
|
+
// src/adapters/registry.ts
|
|
2
|
+
var adapters = /* @__PURE__ */ new Map();
|
|
3
|
+
function registerAdapter(adapter) {
|
|
4
|
+
adapters.set(adapter.target, adapter);
|
|
5
|
+
}
|
|
6
|
+
function getAdapter(target) {
|
|
7
|
+
const adapter = adapters.get(target);
|
|
8
|
+
if (!adapter) {
|
|
9
|
+
const available = [...adapters.keys()].join(", ");
|
|
10
|
+
throw new Error(`Unknown SSG target "${target}". Available targets: ${available}`);
|
|
11
|
+
}
|
|
12
|
+
return adapter;
|
|
13
|
+
}
|
|
14
|
+
function getAvailableTargets() {
|
|
15
|
+
return [...adapters.keys()];
|
|
16
|
+
}
|
|
17
|
+
var DEFAULT_TARGET = "mintlify";
|
|
18
|
+
|
|
19
|
+
// src/adapters/mintlify.ts
|
|
20
|
+
var styleGuide = {
|
|
21
|
+
pageExtension: "mdx",
|
|
22
|
+
supportsMdx: true,
|
|
23
|
+
requiresFrontmatter: true,
|
|
24
|
+
maxHeadingDepth: 3,
|
|
25
|
+
defaultImports: [],
|
|
26
|
+
codeBlockLanguage: "typescript"
|
|
27
|
+
};
|
|
28
|
+
function pageSlug(pagePath) {
|
|
29
|
+
return pagePath.replace(/\.[^.]+$/, "");
|
|
30
|
+
}
|
|
31
|
+
function buildDocsJson(context) {
|
|
32
|
+
const { pages, projectName } = context;
|
|
33
|
+
const topLevel = [];
|
|
34
|
+
const byPackage = /* @__PURE__ */ new Map();
|
|
35
|
+
for (const page of pages) {
|
|
36
|
+
const slug = pageSlug(page.path);
|
|
37
|
+
const packageMatch = /^packages\/([^/]+)\/(.+)$/.exec(slug);
|
|
38
|
+
if (packageMatch) {
|
|
39
|
+
const pkgName = packageMatch[1];
|
|
40
|
+
const list = byPackage.get(pkgName) ?? [];
|
|
41
|
+
list.push(slug);
|
|
42
|
+
byPackage.set(pkgName, list);
|
|
43
|
+
} else {
|
|
44
|
+
topLevel.push(slug);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const navigation = [];
|
|
48
|
+
if (topLevel.length > 0) {
|
|
49
|
+
navigation.push({ group: "Getting Started", pages: topLevel });
|
|
50
|
+
}
|
|
51
|
+
if (byPackage.size > 0) {
|
|
52
|
+
const packageGroups = [];
|
|
53
|
+
for (const [pkgName, slugs] of byPackage) {
|
|
54
|
+
packageGroups.push({ group: pkgName, pages: slugs });
|
|
55
|
+
}
|
|
56
|
+
navigation.push({
|
|
57
|
+
group: "Packages",
|
|
58
|
+
pages: packageGroups
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
name: projectName,
|
|
63
|
+
theme: "venus",
|
|
64
|
+
colors: { primary: "#0ea5e9" },
|
|
65
|
+
navigation
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function addMintlifyFrontmatter(page) {
|
|
69
|
+
const title = String(page.frontmatter.title ?? "");
|
|
70
|
+
const description = page.frontmatter.description ? String(page.frontmatter.description) : void 0;
|
|
71
|
+
const lines = ["---", `title: "${title}"`];
|
|
72
|
+
if (description) {
|
|
73
|
+
lines.push(`description: "${description}"`);
|
|
74
|
+
}
|
|
75
|
+
lines.push("---", "");
|
|
76
|
+
const body = page.content.replace(/^---[\s\S]*?---\n+/, "");
|
|
77
|
+
return lines.join("\n") + body;
|
|
78
|
+
}
|
|
79
|
+
var mintlifyAdapter = {
|
|
80
|
+
target: "mintlify",
|
|
81
|
+
displayName: "Mintlify",
|
|
82
|
+
styleGuide,
|
|
83
|
+
scaffold(context) {
|
|
84
|
+
const docsJson = buildDocsJson(context);
|
|
85
|
+
return {
|
|
86
|
+
target: "mintlify",
|
|
87
|
+
files: [{ path: "docs.json", content: JSON.stringify(docsJson, null, 2) }],
|
|
88
|
+
dependencies: {},
|
|
89
|
+
devDependencies: {},
|
|
90
|
+
scripts: {},
|
|
91
|
+
instructions: [
|
|
92
|
+
"Install Mintlify CLI: npm i -g mint",
|
|
93
|
+
"Preview locally: mint dev",
|
|
94
|
+
"Deploy: Push to GitHub and connect at mintlify.com"
|
|
95
|
+
]
|
|
96
|
+
};
|
|
97
|
+
},
|
|
98
|
+
transformPages(pages, _context) {
|
|
99
|
+
return pages.map((page) => ({
|
|
100
|
+
path: page.path.replace(/\.md$/, ".mdx"),
|
|
101
|
+
content: addMintlifyFrontmatter(page)
|
|
102
|
+
}));
|
|
103
|
+
},
|
|
104
|
+
generateConfig(context) {
|
|
105
|
+
const config = buildDocsJson(context);
|
|
106
|
+
return [
|
|
107
|
+
{
|
|
108
|
+
path: "docs.json",
|
|
109
|
+
content: `${JSON.stringify(config, null, 2)}
|
|
110
|
+
`
|
|
111
|
+
}
|
|
112
|
+
];
|
|
113
|
+
},
|
|
114
|
+
async detectExisting(outDir) {
|
|
115
|
+
const { existsSync: existsSync2 } = await import("fs");
|
|
116
|
+
const { join: join2 } = await import("path");
|
|
117
|
+
return existsSync2(join2(outDir, "docs.json"));
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
registerAdapter(mintlifyAdapter);
|
|
121
|
+
|
|
122
|
+
// src/adapters/docusaurus.ts
|
|
123
|
+
var styleGuide2 = {
|
|
124
|
+
pageExtension: "mdx",
|
|
125
|
+
supportsMdx: true,
|
|
126
|
+
requiresFrontmatter: true,
|
|
127
|
+
maxHeadingDepth: 4,
|
|
128
|
+
defaultImports: [],
|
|
129
|
+
codeBlockLanguage: "typescript"
|
|
130
|
+
};
|
|
131
|
+
function pageSlug2(pagePath) {
|
|
132
|
+
return pagePath.replace(/\.[^.]+$/, "");
|
|
133
|
+
}
|
|
134
|
+
function buildSidebarsTs(pages) {
|
|
135
|
+
const topLevel = [];
|
|
136
|
+
const byPackage = /* @__PURE__ */ new Map();
|
|
137
|
+
for (const page of pages) {
|
|
138
|
+
const slug = pageSlug2(page.path);
|
|
139
|
+
const packageMatch = /^packages\/([^/]+)\/(.+)$/.exec(slug);
|
|
140
|
+
if (packageMatch) {
|
|
141
|
+
const pkgName = packageMatch[1];
|
|
142
|
+
const list = byPackage.get(pkgName) ?? [];
|
|
143
|
+
list.push(slug);
|
|
144
|
+
byPackage.set(pkgName, list);
|
|
145
|
+
} else {
|
|
146
|
+
topLevel.push(slug);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const items = [...topLevel];
|
|
150
|
+
for (const [pkgName, slugs] of byPackage) {
|
|
151
|
+
items.push({
|
|
152
|
+
type: "category",
|
|
153
|
+
label: pkgName,
|
|
154
|
+
items: slugs
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
const sidebarObj = { docs: items };
|
|
158
|
+
const json = JSON.stringify(sidebarObj, null, 2);
|
|
159
|
+
return `import type { SidebarsConfig } from "@docusaurus/plugin-content-docs";
|
|
160
|
+
|
|
161
|
+
const sidebars: SidebarsConfig = ${json};
|
|
162
|
+
|
|
163
|
+
export default sidebars;
|
|
164
|
+
`;
|
|
165
|
+
}
|
|
166
|
+
function buildDocusaurusConfig(context) {
|
|
167
|
+
const { projectName, projectDescription } = context;
|
|
168
|
+
const description = projectDescription ?? `${projectName} documentation`;
|
|
169
|
+
return `import { themes as prismThemes } from "prism-react-renderer";
|
|
170
|
+
import type { Config } from "@docusaurus/types";
|
|
171
|
+
import type * as Preset from "@docusaurus/preset-classic";
|
|
172
|
+
|
|
173
|
+
const config: Config = {
|
|
174
|
+
title: "${projectName}",
|
|
175
|
+
tagline: "${description}",
|
|
176
|
+
url: "https://your-domain.com",
|
|
177
|
+
baseUrl: "/",
|
|
178
|
+
onBrokenLinks: "throw",
|
|
179
|
+
onBrokenMarkdownLinks: "warn",
|
|
180
|
+
i18n: {
|
|
181
|
+
defaultLocale: "en",
|
|
182
|
+
locales: ["en"],
|
|
183
|
+
},
|
|
184
|
+
presets: [
|
|
185
|
+
[
|
|
186
|
+
"classic",
|
|
187
|
+
{
|
|
188
|
+
docs: {
|
|
189
|
+
routeBasePath: "/",
|
|
190
|
+
sidebarPath: "./sidebars.ts",
|
|
191
|
+
},
|
|
192
|
+
blog: false,
|
|
193
|
+
} satisfies Preset.Options,
|
|
194
|
+
],
|
|
195
|
+
],
|
|
196
|
+
themeConfig: {
|
|
197
|
+
prism: {
|
|
198
|
+
theme: prismThemes.github,
|
|
199
|
+
darkTheme: prismThemes.dracula,
|
|
200
|
+
},
|
|
201
|
+
} satisfies Preset.ThemeConfig,
|
|
202
|
+
} satisfies Config;
|
|
203
|
+
|
|
204
|
+
export default config;
|
|
205
|
+
`;
|
|
206
|
+
}
|
|
207
|
+
function buildPackageJson(context) {
|
|
208
|
+
const pkg = {
|
|
209
|
+
name: `${context.projectName}-docs`,
|
|
210
|
+
version: "0.0.0",
|
|
211
|
+
private: true,
|
|
212
|
+
scripts: {
|
|
213
|
+
"docs:dev": "docusaurus start",
|
|
214
|
+
"docs:build": "docusaurus build",
|
|
215
|
+
"docs:serve": "docusaurus serve"
|
|
216
|
+
},
|
|
217
|
+
dependencies: {
|
|
218
|
+
"@docusaurus/core": "^3.9.2",
|
|
219
|
+
"@docusaurus/preset-classic": "^3.9.2",
|
|
220
|
+
"@mdx-js/react": "^3.0.0",
|
|
221
|
+
react: "^19.0.0",
|
|
222
|
+
"react-dom": "^19.0.0",
|
|
223
|
+
"prism-react-renderer": "^2.3.0"
|
|
224
|
+
},
|
|
225
|
+
devDependencies: {
|
|
226
|
+
"@docusaurus/tsconfig": "^3.9.2",
|
|
227
|
+
"@docusaurus/types": "^3.9.2"
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
return `${JSON.stringify(pkg, null, 2)}
|
|
231
|
+
`;
|
|
232
|
+
}
|
|
233
|
+
function addDocusaurusFrontmatter(page) {
|
|
234
|
+
const title = String(page.frontmatter.title ?? "");
|
|
235
|
+
const description = page.frontmatter.description ? String(page.frontmatter.description) : void 0;
|
|
236
|
+
const sidebarLabel = page.frontmatter.sidebar_label ? String(page.frontmatter.sidebar_label) : title;
|
|
237
|
+
const sidebarPosition = page.frontmatter.sidebar_position;
|
|
238
|
+
const lines = ["---", `title: "${title}"`, `sidebar_label: "${sidebarLabel}"`];
|
|
239
|
+
if (sidebarPosition !== void 0) {
|
|
240
|
+
lines.push(`sidebar_position: ${sidebarPosition}`);
|
|
241
|
+
}
|
|
242
|
+
if (description) {
|
|
243
|
+
lines.push(`description: "${description}"`);
|
|
244
|
+
}
|
|
245
|
+
lines.push("---", "");
|
|
246
|
+
const body = page.content.replace(/^---[\s\S]*?---\n+/, "");
|
|
247
|
+
return lines.join("\n") + body;
|
|
248
|
+
}
|
|
249
|
+
var docusaurusAdapter = {
|
|
250
|
+
target: "docusaurus",
|
|
251
|
+
displayName: "Docusaurus",
|
|
252
|
+
styleGuide: styleGuide2,
|
|
253
|
+
scaffold(context) {
|
|
254
|
+
return {
|
|
255
|
+
target: "docusaurus",
|
|
256
|
+
files: [
|
|
257
|
+
{ path: "docusaurus.config.ts", content: buildDocusaurusConfig(context) },
|
|
258
|
+
{ path: "sidebars.ts", content: buildSidebarsTs(context.pages) },
|
|
259
|
+
{ path: "package.json", content: buildPackageJson(context) },
|
|
260
|
+
{ path: "tsconfig.json", content: '{ "extends": "@docusaurus/tsconfig" }\n' }
|
|
261
|
+
],
|
|
262
|
+
dependencies: {
|
|
263
|
+
"@docusaurus/core": "^3.9.2",
|
|
264
|
+
"@docusaurus/preset-classic": "^3.9.2",
|
|
265
|
+
"@mdx-js/react": "^3.0.0",
|
|
266
|
+
react: "^19.0.0",
|
|
267
|
+
"react-dom": "^19.0.0",
|
|
268
|
+
"prism-react-renderer": "^2.3.0"
|
|
269
|
+
},
|
|
270
|
+
devDependencies: {
|
|
271
|
+
"@docusaurus/tsconfig": "^3.9.2",
|
|
272
|
+
"@docusaurus/types": "^3.9.2"
|
|
273
|
+
},
|
|
274
|
+
scripts: {
|
|
275
|
+
"docs:dev": "docusaurus start",
|
|
276
|
+
"docs:build": "docusaurus build",
|
|
277
|
+
"docs:serve": "docusaurus serve"
|
|
278
|
+
},
|
|
279
|
+
instructions: [`Run \`npm run docs:dev\` inside ${context.outDir} to preview your docs`]
|
|
280
|
+
};
|
|
281
|
+
},
|
|
282
|
+
transformPages(pages, _context) {
|
|
283
|
+
return pages.map((page) => ({
|
|
284
|
+
path: page.path.replace(/\.md$/, ".mdx"),
|
|
285
|
+
content: addDocusaurusFrontmatter(page)
|
|
286
|
+
}));
|
|
287
|
+
},
|
|
288
|
+
generateConfig(context) {
|
|
289
|
+
return [
|
|
290
|
+
{
|
|
291
|
+
path: "sidebars.ts",
|
|
292
|
+
content: buildSidebarsTs(context.pages)
|
|
293
|
+
}
|
|
294
|
+
];
|
|
295
|
+
},
|
|
296
|
+
async detectExisting(outDir) {
|
|
297
|
+
const { existsSync: existsSync2 } = await import("fs");
|
|
298
|
+
const { join: join2 } = await import("path");
|
|
299
|
+
return existsSync2(join2(outDir, "sidebars.ts")) || existsSync2(join2(outDir, "docusaurus.config.ts")) || existsSync2(join2(outDir, "docusaurus.config.js"));
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
registerAdapter(docusaurusAdapter);
|
|
303
|
+
|
|
304
|
+
// src/adapters/nextra.ts
|
|
305
|
+
var styleGuide3 = {
|
|
306
|
+
pageExtension: "mdx",
|
|
307
|
+
supportsMdx: true,
|
|
308
|
+
requiresFrontmatter: false,
|
|
309
|
+
maxHeadingDepth: 4,
|
|
310
|
+
defaultImports: [],
|
|
311
|
+
codeBlockLanguage: "typescript"
|
|
312
|
+
};
|
|
313
|
+
function pageSlug3(pagePath) {
|
|
314
|
+
return pagePath.replace(/\.[^.]+$/, "");
|
|
315
|
+
}
|
|
316
|
+
function slugToLabel(slug) {
|
|
317
|
+
return slug.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
318
|
+
}
|
|
319
|
+
function renderMetaJs(meta) {
|
|
320
|
+
const json = JSON.stringify(meta, null, 2);
|
|
321
|
+
return `export default ${json};
|
|
322
|
+
`;
|
|
323
|
+
}
|
|
324
|
+
function buildMetaFiles(pages) {
|
|
325
|
+
const topLevel = [];
|
|
326
|
+
const byPackage = /* @__PURE__ */ new Map();
|
|
327
|
+
for (const page of pages) {
|
|
328
|
+
const slug = pageSlug3(page.path);
|
|
329
|
+
const packageMatch = /^packages\/([^/]+)\/(.+)$/.exec(slug);
|
|
330
|
+
if (packageMatch) {
|
|
331
|
+
const pkgName = packageMatch[1];
|
|
332
|
+
const list = byPackage.get(pkgName) ?? [];
|
|
333
|
+
list.push(slug);
|
|
334
|
+
byPackage.set(pkgName, list);
|
|
335
|
+
} else {
|
|
336
|
+
topLevel.push(slug);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
const files = [];
|
|
340
|
+
const rootMeta = {};
|
|
341
|
+
for (const slug of topLevel) {
|
|
342
|
+
const segment = slug.split("/").pop() ?? slug;
|
|
343
|
+
rootMeta[segment] = slugToLabel(segment);
|
|
344
|
+
}
|
|
345
|
+
if (byPackage.size > 0) {
|
|
346
|
+
rootMeta.packages = "Packages";
|
|
347
|
+
}
|
|
348
|
+
files.push({
|
|
349
|
+
path: "content/_meta.js",
|
|
350
|
+
content: renderMetaJs(rootMeta)
|
|
351
|
+
});
|
|
352
|
+
for (const [pkgName, slugs] of byPackage) {
|
|
353
|
+
const pkgMeta = {};
|
|
354
|
+
for (const slug of slugs) {
|
|
355
|
+
const segment = slug.split("/").pop() ?? slug;
|
|
356
|
+
pkgMeta[segment] = slugToLabel(segment);
|
|
357
|
+
}
|
|
358
|
+
files.push({
|
|
359
|
+
path: `content/packages/${pkgName}/_meta.js`,
|
|
360
|
+
content: renderMetaJs(pkgMeta)
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
if (byPackage.size > 1) {
|
|
364
|
+
const packagesMeta = {};
|
|
365
|
+
for (const pkgName of byPackage.keys()) {
|
|
366
|
+
packagesMeta[pkgName] = pkgName;
|
|
367
|
+
}
|
|
368
|
+
files.push({
|
|
369
|
+
path: "content/packages/_meta.js",
|
|
370
|
+
content: renderMetaJs(packagesMeta)
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
return files;
|
|
374
|
+
}
|
|
375
|
+
function buildAppLayout(context) {
|
|
376
|
+
const { projectName } = context;
|
|
377
|
+
return `import { Layout } from "nextra-theme-docs";
|
|
378
|
+
import { Head } from "nextra/components";
|
|
379
|
+
import { getPageMap } from "nextra/page-map";
|
|
380
|
+
import type { ReactNode } from "react";
|
|
381
|
+
|
|
382
|
+
export const metadata = {
|
|
383
|
+
title: {
|
|
384
|
+
template: \`%s \u2013 ${projectName}\`,
|
|
385
|
+
},
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
export default async function RootLayout({ children }: { children: ReactNode }) {
|
|
389
|
+
const pageMap = await getPageMap();
|
|
390
|
+
return (
|
|
391
|
+
<html lang="en" suppressHydrationWarning>
|
|
392
|
+
<Head />
|
|
393
|
+
<body>
|
|
394
|
+
<Layout pageMap={pageMap} docsRepositoryBase="">
|
|
395
|
+
{children}
|
|
396
|
+
</Layout>
|
|
397
|
+
</body>
|
|
398
|
+
</html>
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
`;
|
|
402
|
+
}
|
|
403
|
+
function buildCatchAllPage() {
|
|
404
|
+
return `import { generateStaticParamsFor, importPage } from "nextra/pages";
|
|
405
|
+
|
|
406
|
+
export const generateStaticParams = generateStaticParamsFor("mdxPath");
|
|
407
|
+
|
|
408
|
+
export async function generateMetadata(props: {
|
|
409
|
+
params: Promise<Record<string, string[]>>;
|
|
410
|
+
}) {
|
|
411
|
+
const params = await props.params;
|
|
412
|
+
const { metadata } = await importPage(params.mdxPath);
|
|
413
|
+
return metadata;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
const Wrapper = importPage;
|
|
417
|
+
export default async function Page(props: {
|
|
418
|
+
params: Promise<Record<string, string[]>>;
|
|
419
|
+
}) {
|
|
420
|
+
const params = await props.params;
|
|
421
|
+
const result = await importPage(params.mdxPath);
|
|
422
|
+
const { default: MDXContent } = result;
|
|
423
|
+
return <MDXContent {...props} params={params} />;
|
|
424
|
+
}
|
|
425
|
+
`;
|
|
426
|
+
}
|
|
427
|
+
function buildMdxComponents() {
|
|
428
|
+
return `import { useMDXComponents as getNextraComponents } from "nextra-theme-docs";
|
|
429
|
+
|
|
430
|
+
export function useMDXComponents(components: Record<string, unknown>) {
|
|
431
|
+
return getNextraComponents(components);
|
|
432
|
+
}
|
|
433
|
+
`;
|
|
434
|
+
}
|
|
435
|
+
function buildNextConfig() {
|
|
436
|
+
return `import nextra from "nextra";
|
|
437
|
+
|
|
438
|
+
const withNextra = nextra({
|
|
439
|
+
contentDirBasePath: "/",
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
export default withNextra({
|
|
443
|
+
output: "export",
|
|
444
|
+
images: { unoptimized: true },
|
|
445
|
+
});
|
|
446
|
+
`;
|
|
447
|
+
}
|
|
448
|
+
function buildPackageJson2(context) {
|
|
449
|
+
const pkg = {
|
|
450
|
+
name: `${context.projectName}-docs`,
|
|
451
|
+
version: "0.0.0",
|
|
452
|
+
private: true,
|
|
453
|
+
scripts: {
|
|
454
|
+
"docs:dev": "next dev",
|
|
455
|
+
"docs:build": "next build",
|
|
456
|
+
"docs:serve": "next start"
|
|
457
|
+
},
|
|
458
|
+
dependencies: {
|
|
459
|
+
next: "^15",
|
|
460
|
+
nextra: "^4",
|
|
461
|
+
"nextra-theme-docs": "^4",
|
|
462
|
+
react: "^19",
|
|
463
|
+
"react-dom": "^19"
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
return `${JSON.stringify(pkg, null, 2)}
|
|
467
|
+
`;
|
|
468
|
+
}
|
|
469
|
+
function addNextraFrontmatter(page) {
|
|
470
|
+
const title = String(page.frontmatter.title ?? "");
|
|
471
|
+
if (!title) {
|
|
472
|
+
return page.content;
|
|
473
|
+
}
|
|
474
|
+
const lines = ["---", `title: "${title}"`, "---", ""];
|
|
475
|
+
const body = page.content.replace(/^---[\s\S]*?---\n+/, "");
|
|
476
|
+
return lines.join("\n") + body;
|
|
477
|
+
}
|
|
478
|
+
var nextraAdapter = {
|
|
479
|
+
target: "nextra",
|
|
480
|
+
displayName: "Nextra",
|
|
481
|
+
styleGuide: styleGuide3,
|
|
482
|
+
scaffold(context) {
|
|
483
|
+
const metaFiles = buildMetaFiles(context.pages);
|
|
484
|
+
return {
|
|
485
|
+
target: "nextra",
|
|
486
|
+
files: [
|
|
487
|
+
{ path: "next.config.ts", content: buildNextConfig() },
|
|
488
|
+
{ path: "package.json", content: buildPackageJson2(context) },
|
|
489
|
+
{ path: "mdx-components.ts", content: buildMdxComponents() },
|
|
490
|
+
{ path: "app/layout.tsx", content: buildAppLayout(context) },
|
|
491
|
+
{ path: "app/[[...mdxPath]]/page.tsx", content: buildCatchAllPage() },
|
|
492
|
+
...metaFiles
|
|
493
|
+
],
|
|
494
|
+
dependencies: {
|
|
495
|
+
next: "^15",
|
|
496
|
+
nextra: "^4",
|
|
497
|
+
"nextra-theme-docs": "^4",
|
|
498
|
+
react: "^19",
|
|
499
|
+
"react-dom": "^19"
|
|
500
|
+
},
|
|
501
|
+
devDependencies: {},
|
|
502
|
+
scripts: {
|
|
503
|
+
"docs:dev": "next dev",
|
|
504
|
+
"docs:build": "next build",
|
|
505
|
+
"docs:serve": "next start"
|
|
506
|
+
},
|
|
507
|
+
instructions: [`Run \`npm run docs:dev\` inside ${context.outDir} to preview your docs`]
|
|
508
|
+
};
|
|
509
|
+
},
|
|
510
|
+
transformPages(pages, _context) {
|
|
511
|
+
return pages.map((page) => ({
|
|
512
|
+
path: page.path.replace(/\.md$/, ".mdx"),
|
|
513
|
+
content: addNextraFrontmatter(page)
|
|
514
|
+
}));
|
|
515
|
+
},
|
|
516
|
+
generateConfig(context) {
|
|
517
|
+
return buildMetaFiles(context.pages);
|
|
518
|
+
},
|
|
519
|
+
async detectExisting(outDir) {
|
|
520
|
+
const { existsSync: existsSync2 } = await import("fs");
|
|
521
|
+
const { join: join2 } = await import("path");
|
|
522
|
+
return existsSync2(join2(outDir, "content/_meta.js")) || existsSync2(join2(outDir, "next.config.ts")) || existsSync2(join2(outDir, "next.config.js"));
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
registerAdapter(nextraAdapter);
|
|
526
|
+
|
|
527
|
+
// src/adapters/vitepress.ts
|
|
528
|
+
var styleGuide4 = {
|
|
529
|
+
pageExtension: "md",
|
|
530
|
+
supportsMdx: false,
|
|
531
|
+
requiresFrontmatter: true,
|
|
532
|
+
maxHeadingDepth: 4,
|
|
533
|
+
defaultImports: [],
|
|
534
|
+
codeBlockLanguage: "typescript"
|
|
535
|
+
};
|
|
536
|
+
function pageSlug4(pagePath) {
|
|
537
|
+
return pagePath.replace(/\.[^.]+$/, "");
|
|
538
|
+
}
|
|
539
|
+
function slugToLabel2(slug) {
|
|
540
|
+
return slug.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
541
|
+
}
|
|
542
|
+
function buildSidebar(pages) {
|
|
543
|
+
const topLevel = [];
|
|
544
|
+
const byPackage = /* @__PURE__ */ new Map();
|
|
545
|
+
for (const page of pages) {
|
|
546
|
+
const slug = pageSlug4(page.path);
|
|
547
|
+
const packageMatch = /^packages\/([^/]+)\/(.+)$/.exec(slug);
|
|
548
|
+
if (packageMatch) {
|
|
549
|
+
const pkgName = packageMatch[1];
|
|
550
|
+
const list = byPackage.get(pkgName) ?? [];
|
|
551
|
+
list.push(slug);
|
|
552
|
+
byPackage.set(pkgName, list);
|
|
553
|
+
} else {
|
|
554
|
+
topLevel.push(slug);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
const sidebar = [];
|
|
558
|
+
if (topLevel.length > 0) {
|
|
559
|
+
const items = topLevel.map((slug) => {
|
|
560
|
+
const segment = slug.split("/").pop() ?? slug;
|
|
561
|
+
const link = slug === "index" ? "/" : `/${slug}`;
|
|
562
|
+
return { text: slugToLabel2(segment), link };
|
|
563
|
+
});
|
|
564
|
+
sidebar.push({ text: "Getting Started", items });
|
|
565
|
+
}
|
|
566
|
+
for (const [pkgName, slugs] of byPackage) {
|
|
567
|
+
const items = slugs.map((slug) => {
|
|
568
|
+
const segment = slug.split("/").pop() ?? slug;
|
|
569
|
+
const isIndex = segment === "index";
|
|
570
|
+
const link = isIndex ? `/packages/${pkgName}/` : `/${slug}`;
|
|
571
|
+
return { text: slugToLabel2(segment), link };
|
|
572
|
+
});
|
|
573
|
+
sidebar.push({ text: pkgName, items });
|
|
574
|
+
}
|
|
575
|
+
return sidebar;
|
|
576
|
+
}
|
|
577
|
+
function buildVitePressConfig(context) {
|
|
578
|
+
const { projectName, projectDescription } = context;
|
|
579
|
+
const description = projectDescription ?? `${projectName} documentation`;
|
|
580
|
+
const sidebar = buildSidebar(context.pages);
|
|
581
|
+
const sidebarJson = JSON.stringify(sidebar, null, 4).split("\n").join("\n ");
|
|
582
|
+
return `import { defineConfig } from "vitepress";
|
|
583
|
+
|
|
584
|
+
// https://vitepress.dev/reference/site-config
|
|
585
|
+
export default defineConfig({
|
|
586
|
+
title: "${projectName}",
|
|
587
|
+
description: "${description}",
|
|
588
|
+
themeConfig: {
|
|
589
|
+
nav: [
|
|
590
|
+
{ text: "Home", link: "/" },
|
|
591
|
+
],
|
|
592
|
+
sidebar: ${sidebarJson},
|
|
593
|
+
socialLinks: [],
|
|
594
|
+
},
|
|
595
|
+
});
|
|
596
|
+
`;
|
|
597
|
+
}
|
|
598
|
+
function buildPackageJson3(context) {
|
|
599
|
+
const pkg = {
|
|
600
|
+
name: `${context.projectName}-docs`,
|
|
601
|
+
version: "0.0.0",
|
|
602
|
+
private: true,
|
|
603
|
+
type: "module",
|
|
604
|
+
scripts: {
|
|
605
|
+
"docs:dev": "vitepress dev",
|
|
606
|
+
"docs:build": "vitepress build",
|
|
607
|
+
"docs:preview": "vitepress preview"
|
|
608
|
+
},
|
|
609
|
+
devDependencies: {
|
|
610
|
+
vitepress: "^2.0.0"
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
return `${JSON.stringify(pkg, null, 2)}
|
|
614
|
+
`;
|
|
615
|
+
}
|
|
616
|
+
function addVitepressFrontmatter(page) {
|
|
617
|
+
const title = String(page.frontmatter.title ?? "");
|
|
618
|
+
const description = page.frontmatter.description ? String(page.frontmatter.description) : void 0;
|
|
619
|
+
const lines = ["---", `title: "${title}"`, "outline: deep"];
|
|
620
|
+
if (description) {
|
|
621
|
+
lines.push(`description: "${description}"`);
|
|
622
|
+
}
|
|
623
|
+
lines.push("---", "");
|
|
624
|
+
const body = page.content.replace(/^---[\s\S]*?---\n+/, "");
|
|
625
|
+
return lines.join("\n") + body;
|
|
626
|
+
}
|
|
627
|
+
var vitepressAdapter = {
|
|
628
|
+
target: "vitepress",
|
|
629
|
+
displayName: "VitePress",
|
|
630
|
+
styleGuide: styleGuide4,
|
|
631
|
+
scaffold(context) {
|
|
632
|
+
return {
|
|
633
|
+
target: "vitepress",
|
|
634
|
+
files: [
|
|
635
|
+
{ path: ".vitepress/config.mts", content: buildVitePressConfig(context) },
|
|
636
|
+
{ path: "package.json", content: buildPackageJson3(context) }
|
|
637
|
+
],
|
|
638
|
+
dependencies: {},
|
|
639
|
+
devDependencies: {
|
|
640
|
+
vitepress: "^2.0.0"
|
|
641
|
+
},
|
|
642
|
+
scripts: {
|
|
643
|
+
"docs:dev": "vitepress dev",
|
|
644
|
+
"docs:build": "vitepress build",
|
|
645
|
+
"docs:preview": "vitepress preview"
|
|
646
|
+
},
|
|
647
|
+
instructions: [`Run \`npm run docs:dev\` inside ${context.outDir} to preview your docs`]
|
|
648
|
+
};
|
|
649
|
+
},
|
|
650
|
+
transformPages(pages, _context) {
|
|
651
|
+
return pages.map((page) => ({
|
|
652
|
+
path: page.path.endsWith(".mdx") ? page.path.replace(/\.mdx$/, ".md") : page.path,
|
|
653
|
+
content: addVitepressFrontmatter(page)
|
|
654
|
+
}));
|
|
655
|
+
},
|
|
656
|
+
generateConfig(context) {
|
|
657
|
+
return [
|
|
658
|
+
{
|
|
659
|
+
path: ".vitepress/config.mts",
|
|
660
|
+
content: buildVitePressConfig(context)
|
|
661
|
+
}
|
|
662
|
+
];
|
|
663
|
+
},
|
|
664
|
+
async detectExisting(outDir) {
|
|
665
|
+
const { existsSync: existsSync2 } = await import("fs");
|
|
666
|
+
const { join: join2 } = await import("path");
|
|
667
|
+
return existsSync2(join2(outDir, ".vitepress"));
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
registerAdapter(vitepressAdapter);
|
|
671
|
+
|
|
1
672
|
// src/llms.ts
|
|
2
673
|
function compactEntry(symbol) {
|
|
3
674
|
if (symbol.signature) {
|
|
@@ -949,14 +1620,14 @@ function generateDocSite(symbolsByPackage, config, options) {
|
|
|
949
1620
|
}
|
|
950
1621
|
|
|
951
1622
|
// src/ssg-config.ts
|
|
952
|
-
function
|
|
1623
|
+
function pageSlug5(pagePath) {
|
|
953
1624
|
return pagePath.replace(/\.[^.]+$/, "");
|
|
954
1625
|
}
|
|
955
1626
|
function partitionPages(pages) {
|
|
956
1627
|
const topLevel = [];
|
|
957
1628
|
const byPackage = /* @__PURE__ */ new Map();
|
|
958
1629
|
for (const page of pages) {
|
|
959
|
-
const slug =
|
|
1630
|
+
const slug = pageSlug5(page.path);
|
|
960
1631
|
const packageMatch = /^packages\/([^/]+)\/(.+)$/.exec(slug);
|
|
961
1632
|
if (packageMatch) {
|
|
962
1633
|
const pkgName = packageMatch[1];
|
|
@@ -969,7 +1640,7 @@ function partitionPages(pages) {
|
|
|
969
1640
|
}
|
|
970
1641
|
return { topLevel, byPackage };
|
|
971
1642
|
}
|
|
972
|
-
function
|
|
1643
|
+
function slugToLabel3(slug) {
|
|
973
1644
|
return slug.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
974
1645
|
}
|
|
975
1646
|
function generateMintlifyConfig(pages, projectName) {
|
|
@@ -1032,7 +1703,7 @@ function generateNextraConfigs(pages, _projectName) {
|
|
|
1032
1703
|
const rootMeta = {};
|
|
1033
1704
|
for (const slug of topLevel) {
|
|
1034
1705
|
const segment = slug.split("/").pop() ?? slug;
|
|
1035
|
-
rootMeta[segment] =
|
|
1706
|
+
rootMeta[segment] = slugToLabel3(segment);
|
|
1036
1707
|
}
|
|
1037
1708
|
if (byPackage.size > 0) {
|
|
1038
1709
|
rootMeta.packages = "Packages";
|
|
@@ -1046,7 +1717,7 @@ function generateNextraConfigs(pages, _projectName) {
|
|
|
1046
1717
|
const pkgMeta = {};
|
|
1047
1718
|
for (const slug of slugs) {
|
|
1048
1719
|
const segment = slug.split("/").pop() ?? slug;
|
|
1049
|
-
pkgMeta[segment] =
|
|
1720
|
+
pkgMeta[segment] = slugToLabel3(segment);
|
|
1050
1721
|
}
|
|
1051
1722
|
files.push({
|
|
1052
1723
|
path: `packages/${pkgName}/_meta.json`,
|
|
@@ -1074,7 +1745,7 @@ function generateVitePressConfig(pages, _projectName) {
|
|
|
1074
1745
|
const items = topLevel.map((slug) => {
|
|
1075
1746
|
const segment = slug.split("/").pop() ?? slug;
|
|
1076
1747
|
const link = slug === "index" ? "/" : `/${slug}`;
|
|
1077
|
-
return { text:
|
|
1748
|
+
return { text: slugToLabel3(segment), link };
|
|
1078
1749
|
});
|
|
1079
1750
|
sidebar.push({ text: "Getting Started", items });
|
|
1080
1751
|
}
|
|
@@ -1083,7 +1754,7 @@ function generateVitePressConfig(pages, _projectName) {
|
|
|
1083
1754
|
const segment = slug.split("/").pop() ?? slug;
|
|
1084
1755
|
const isIndex = segment === "index";
|
|
1085
1756
|
const link = isIndex ? `/packages/${pkgName}/` : `/${slug}`;
|
|
1086
|
-
return { text:
|
|
1757
|
+
return { text: slugToLabel3(segment), link };
|
|
1087
1758
|
});
|
|
1088
1759
|
sidebar.push({ text: pkgName, items });
|
|
1089
1760
|
}
|
|
@@ -1113,7 +1784,7 @@ function generateSSGConfigs(pages, target, projectName) {
|
|
|
1113
1784
|
|
|
1114
1785
|
// src/index.ts
|
|
1115
1786
|
import { mkdir, writeFile as writeFile2 } from "fs/promises";
|
|
1116
|
-
import { join } from "path";
|
|
1787
|
+
import { dirname, join } from "path";
|
|
1117
1788
|
import { createWalker } from "@forge-ts/core";
|
|
1118
1789
|
async function generate(config) {
|
|
1119
1790
|
const start = Date.now();
|
|
@@ -1129,25 +1800,33 @@ async function generate(config) {
|
|
|
1129
1800
|
}
|
|
1130
1801
|
const projectName = config.rootDir.split("/").pop() ?? "Project";
|
|
1131
1802
|
const symbolsByPackage = groupSymbolsByPackage(symbols, config.rootDir);
|
|
1803
|
+
const target = config.gen.ssgTarget ?? DEFAULT_TARGET;
|
|
1804
|
+
const adapter = getAdapter(target);
|
|
1132
1805
|
for (const format of config.gen.formats) {
|
|
1133
1806
|
const pages = generateDocSite(symbolsByPackage, config, {
|
|
1134
1807
|
format,
|
|
1135
1808
|
ssgTarget: config.gen.ssgTarget,
|
|
1136
1809
|
projectName
|
|
1137
1810
|
});
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1811
|
+
const adapterContext = {
|
|
1812
|
+
config,
|
|
1813
|
+
projectName,
|
|
1814
|
+
pages,
|
|
1815
|
+
symbols,
|
|
1816
|
+
outDir: config.outDir
|
|
1817
|
+
};
|
|
1818
|
+
const transformedPages = adapter.transformPages(pages, adapterContext);
|
|
1819
|
+
for (const file of transformedPages) {
|
|
1820
|
+
const filePath = join(config.outDir, file.path);
|
|
1821
|
+
await mkdir(dirname(filePath), { recursive: true });
|
|
1822
|
+
await writeFile2(filePath, file.content, "utf8");
|
|
1143
1823
|
}
|
|
1144
1824
|
if (config.gen.ssgTarget) {
|
|
1145
|
-
const configFiles =
|
|
1146
|
-
for (const
|
|
1147
|
-
const
|
|
1148
|
-
|
|
1149
|
-
await
|
|
1150
|
-
await writeFile2(configPath, configFile.content, "utf8");
|
|
1825
|
+
const configFiles = adapter.generateConfig(adapterContext);
|
|
1826
|
+
for (const file of configFiles) {
|
|
1827
|
+
const filePath = join(config.outDir, file.path);
|
|
1828
|
+
await mkdir(dirname(filePath), { recursive: true });
|
|
1829
|
+
await writeFile2(filePath, file.content, "utf8");
|
|
1151
1830
|
}
|
|
1152
1831
|
}
|
|
1153
1832
|
}
|
|
@@ -1169,13 +1848,17 @@ async function generate(config) {
|
|
|
1169
1848
|
};
|
|
1170
1849
|
}
|
|
1171
1850
|
export {
|
|
1851
|
+
DEFAULT_TARGET,
|
|
1172
1852
|
generate,
|
|
1173
1853
|
generateDocSite,
|
|
1174
1854
|
generateLlmsFullTxt,
|
|
1175
1855
|
generateLlmsTxt,
|
|
1176
1856
|
generateMarkdown,
|
|
1177
1857
|
generateSSGConfigs,
|
|
1858
|
+
getAdapter,
|
|
1859
|
+
getAvailableTargets,
|
|
1178
1860
|
groupSymbolsByPackage,
|
|
1861
|
+
registerAdapter,
|
|
1179
1862
|
syncReadme
|
|
1180
1863
|
};
|
|
1181
1864
|
//# sourceMappingURL=index.js.map
|