@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.d.ts
CHANGED
|
@@ -1,5 +1,272 @@
|
|
|
1
1
|
import { ForgeSymbol, ForgeConfig, ForgeResult } from '@forge-ts/core';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* A single generated documentation page.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
interface DocPage {
|
|
8
|
+
/** Relative path from outDir (e.g., "packages/core/index.md") */
|
|
9
|
+
path: string;
|
|
10
|
+
/** Page content (Markdown or MDX) */
|
|
11
|
+
content: string;
|
|
12
|
+
/** Frontmatter fields */
|
|
13
|
+
frontmatter: Record<string, string | number | boolean>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Options controlling the doc site generator.
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
interface SiteGeneratorOptions {
|
|
20
|
+
/** Output format */
|
|
21
|
+
format: "markdown" | "mdx";
|
|
22
|
+
/** SSG target for frontmatter */
|
|
23
|
+
ssgTarget?: "docusaurus" | "mintlify" | "nextra" | "vitepress";
|
|
24
|
+
/** Project name */
|
|
25
|
+
projectName: string;
|
|
26
|
+
/** Project description */
|
|
27
|
+
projectDescription?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Groups symbols by their package based on file path.
|
|
31
|
+
*
|
|
32
|
+
* For monorepos (symbols under `packages/<name>/`) the package name is
|
|
33
|
+
* derived from the directory segment immediately after `packages/`.
|
|
34
|
+
* For non-monorepo projects all symbols fall under the project name.
|
|
35
|
+
*
|
|
36
|
+
* @param symbols - All extracted symbols.
|
|
37
|
+
* @param rootDir - Absolute path to the project root.
|
|
38
|
+
* @returns A map from package name to symbol list.
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* import { groupSymbolsByPackage } from "@forge-ts/gen";
|
|
42
|
+
* const grouped = groupSymbolsByPackage(symbols, "/path/to/project");
|
|
43
|
+
* console.log(grouped.has("core")); // true for monorepo
|
|
44
|
+
* ```
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
declare function groupSymbolsByPackage(symbols: ForgeSymbol[], rootDir: string): Map<string, ForgeSymbol[]>;
|
|
48
|
+
/**
|
|
49
|
+
* Generates a full multi-page documentation site from symbols grouped by package.
|
|
50
|
+
*
|
|
51
|
+
* Produces an index page, a getting-started page, and per-package pages for
|
|
52
|
+
* the API reference, types, functions, and examples.
|
|
53
|
+
*
|
|
54
|
+
* @param symbolsByPackage - Symbols grouped by package name.
|
|
55
|
+
* @param config - The resolved {@link ForgeConfig}.
|
|
56
|
+
* @param options - Site generation options.
|
|
57
|
+
* @returns An array of {@link DocPage} objects ready to be written to disk.
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* import { generateDocSite, groupSymbolsByPackage } from "@forge-ts/gen";
|
|
61
|
+
* const grouped = groupSymbolsByPackage(symbols, config.rootDir);
|
|
62
|
+
* const pages = generateDocSite(grouped, config, { format: "markdown", projectName: "my-project" });
|
|
63
|
+
* console.log(pages.length > 0); // true
|
|
64
|
+
* ```
|
|
65
|
+
* @public
|
|
66
|
+
*/
|
|
67
|
+
declare function generateDocSite(symbolsByPackage: Map<string, ForgeSymbol[]>, config: ForgeConfig, options: SiteGeneratorOptions): DocPage[];
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Supported SSG target identifiers.
|
|
71
|
+
* @public
|
|
72
|
+
*/
|
|
73
|
+
type SSGTarget = "mintlify" | "docusaurus" | "nextra" | "vitepress";
|
|
74
|
+
/**
|
|
75
|
+
* A file to write to disk during scaffolding or generation.
|
|
76
|
+
* @public
|
|
77
|
+
*/
|
|
78
|
+
interface GeneratedFile {
|
|
79
|
+
/** Relative path from the docs output directory. */
|
|
80
|
+
path: string;
|
|
81
|
+
/** File content (string for text). */
|
|
82
|
+
content: string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Style guide configuration for the SSG target.
|
|
86
|
+
* @public
|
|
87
|
+
*/
|
|
88
|
+
interface SSGStyleGuide {
|
|
89
|
+
/** File extension for doc pages. */
|
|
90
|
+
pageExtension: "md" | "mdx";
|
|
91
|
+
/** Whether the target supports MDX components. */
|
|
92
|
+
supportsMdx: boolean;
|
|
93
|
+
/** Whether frontmatter is required on every page. */
|
|
94
|
+
requiresFrontmatter: boolean;
|
|
95
|
+
/** Maximum recommended heading depth. */
|
|
96
|
+
maxHeadingDepth: number;
|
|
97
|
+
/** Component imports to add at top of MDX files (if supportsMdx). */
|
|
98
|
+
defaultImports: string[];
|
|
99
|
+
/** Code block language for TypeScript examples. */
|
|
100
|
+
codeBlockLanguage: "typescript" | "ts" | "tsx";
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Scaffold manifest describing what `init docs` creates.
|
|
104
|
+
* @public
|
|
105
|
+
*/
|
|
106
|
+
interface ScaffoldManifest {
|
|
107
|
+
/** The SSG target this manifest is for. */
|
|
108
|
+
target: SSGTarget;
|
|
109
|
+
/** Files that will be created. */
|
|
110
|
+
files: GeneratedFile[];
|
|
111
|
+
/** npm dependencies to install. */
|
|
112
|
+
dependencies: Record<string, string>;
|
|
113
|
+
/** npm devDependencies to install. */
|
|
114
|
+
devDependencies: Record<string, string>;
|
|
115
|
+
/** Scripts to add to package.json. */
|
|
116
|
+
scripts: Record<string, string>;
|
|
117
|
+
/** Post-scaffold instructions for the user. */
|
|
118
|
+
instructions: string[];
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Context passed to adapter methods.
|
|
122
|
+
* @public
|
|
123
|
+
*/
|
|
124
|
+
interface AdapterContext {
|
|
125
|
+
/** Resolved forge-ts configuration. */
|
|
126
|
+
config: ForgeConfig;
|
|
127
|
+
/** Project name (from package.json or directory). */
|
|
128
|
+
projectName: string;
|
|
129
|
+
/** Project description. */
|
|
130
|
+
projectDescription?: string;
|
|
131
|
+
/** The generated doc pages (from site-generator). */
|
|
132
|
+
pages: DocPage[];
|
|
133
|
+
/** All symbols extracted from the project. */
|
|
134
|
+
symbols: ForgeSymbol[];
|
|
135
|
+
/** Output directory for generated docs. */
|
|
136
|
+
outDir: string;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* The central SSG adapter interface.
|
|
140
|
+
* Every doc platform provider implements this contract.
|
|
141
|
+
* One file per provider. No shared mutable state.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* import { getAdapter } from "@forge-ts/gen";
|
|
146
|
+
* const adapter = getAdapter("mintlify");
|
|
147
|
+
* const files = adapter.transformPages(pages, context);
|
|
148
|
+
* ```
|
|
149
|
+
* @public
|
|
150
|
+
*/
|
|
151
|
+
interface SSGAdapter {
|
|
152
|
+
/** Unique target identifier. */
|
|
153
|
+
readonly target: SSGTarget;
|
|
154
|
+
/** Human-readable display name. */
|
|
155
|
+
readonly displayName: string;
|
|
156
|
+
/** Style guide for this platform. */
|
|
157
|
+
readonly styleGuide: SSGStyleGuide;
|
|
158
|
+
/**
|
|
159
|
+
* Generate the complete scaffold for a new doc site.
|
|
160
|
+
* Called by `forge-ts init docs --target <name>`.
|
|
161
|
+
* Returns all files, dependencies, and scripts needed.
|
|
162
|
+
*
|
|
163
|
+
* @param context - The adapter context for the current project.
|
|
164
|
+
* @returns A {@link ScaffoldManifest} with files, deps, and instructions.
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* import { getAdapter } from "@forge-ts/gen";
|
|
168
|
+
* const adapter = getAdapter("mintlify");
|
|
169
|
+
* const manifest = adapter.scaffold(context);
|
|
170
|
+
* console.log(manifest.files.length);
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
scaffold(context: AdapterContext): ScaffoldManifest;
|
|
174
|
+
/**
|
|
175
|
+
* Transform generic DocPages into platform-specific pages.
|
|
176
|
+
* Adds correct frontmatter, component imports, file extensions.
|
|
177
|
+
* Called during `forge-ts build`.
|
|
178
|
+
*
|
|
179
|
+
* @param pages - The generic doc pages to transform.
|
|
180
|
+
* @param context - The adapter context for the current project.
|
|
181
|
+
* @returns An array of {@link GeneratedFile} objects ready to write.
|
|
182
|
+
* @example
|
|
183
|
+
* ```typescript
|
|
184
|
+
* import { getAdapter } from "@forge-ts/gen";
|
|
185
|
+
* const adapter = getAdapter("docusaurus");
|
|
186
|
+
* const files = adapter.transformPages(pages, context);
|
|
187
|
+
* console.log(files[0].path.endsWith(".mdx")); // true
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
transformPages(pages: DocPage[], context: AdapterContext): GeneratedFile[];
|
|
191
|
+
/**
|
|
192
|
+
* Generate platform-specific configuration files.
|
|
193
|
+
* e.g., mint.json, sidebars.js, _meta.json, .vitepress/config.ts
|
|
194
|
+
* Called during `forge-ts build`.
|
|
195
|
+
*
|
|
196
|
+
* @param context - The adapter context for the current project.
|
|
197
|
+
* @returns An array of {@link GeneratedFile} objects ready to write.
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* import { getAdapter } from "@forge-ts/gen";
|
|
201
|
+
* const adapter = getAdapter("vitepress");
|
|
202
|
+
* const configs = adapter.generateConfig(context);
|
|
203
|
+
* console.log(configs[0].path); // ".vitepress/sidebar.json"
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
generateConfig(context: AdapterContext): GeneratedFile[];
|
|
207
|
+
/**
|
|
208
|
+
* Check if a scaffold already exists in the output directory.
|
|
209
|
+
* Used for safety checks before init or target change.
|
|
210
|
+
*
|
|
211
|
+
* @param outDir - The output directory to inspect.
|
|
212
|
+
* @returns `true` if a scaffold marker file already exists.
|
|
213
|
+
* @example
|
|
214
|
+
* ```typescript
|
|
215
|
+
* import { getAdapter } from "@forge-ts/gen";
|
|
216
|
+
* const adapter = getAdapter("mintlify");
|
|
217
|
+
* const exists = await adapter.detectExisting("./docs");
|
|
218
|
+
* if (exists) console.log("Scaffold already present");
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
detectExisting(outDir: string): Promise<boolean>;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Register an SSG adapter.
|
|
226
|
+
* Called once per provider at module load time.
|
|
227
|
+
*
|
|
228
|
+
* @param adapter - The adapter to register.
|
|
229
|
+
* @example
|
|
230
|
+
* ```typescript
|
|
231
|
+
* import { registerAdapter } from "@forge-ts/gen";
|
|
232
|
+
* registerAdapter(mintlifyAdapter);
|
|
233
|
+
* ```
|
|
234
|
+
* @public
|
|
235
|
+
*/
|
|
236
|
+
declare function registerAdapter(adapter: SSGAdapter): void;
|
|
237
|
+
/**
|
|
238
|
+
* Get a registered adapter by target name.
|
|
239
|
+
* Throws if the target is not registered.
|
|
240
|
+
*
|
|
241
|
+
* @param target - The SSG target identifier.
|
|
242
|
+
* @returns The registered {@link SSGAdapter} for the given target.
|
|
243
|
+
* @throws `Error` if the target is not registered.
|
|
244
|
+
* @example
|
|
245
|
+
* ```typescript
|
|
246
|
+
* import { getAdapter } from "@forge-ts/gen";
|
|
247
|
+
* const adapter = getAdapter("mintlify");
|
|
248
|
+
* ```
|
|
249
|
+
* @public
|
|
250
|
+
*/
|
|
251
|
+
declare function getAdapter(target: SSGTarget): SSGAdapter;
|
|
252
|
+
/**
|
|
253
|
+
* Get all registered adapter targets.
|
|
254
|
+
*
|
|
255
|
+
* @returns An array of all registered {@link SSGTarget} identifiers.
|
|
256
|
+
* @example
|
|
257
|
+
* ```typescript
|
|
258
|
+
* import { getAvailableTargets } from "@forge-ts/gen";
|
|
259
|
+
* const targets = getAvailableTargets(); // ["mintlify", "docusaurus", ...]
|
|
260
|
+
* ```
|
|
261
|
+
* @public
|
|
262
|
+
*/
|
|
263
|
+
declare function getAvailableTargets(): SSGTarget[];
|
|
264
|
+
/**
|
|
265
|
+
* The default SSG target when none is specified.
|
|
266
|
+
* @public
|
|
267
|
+
*/
|
|
268
|
+
declare const DEFAULT_TARGET: SSGTarget;
|
|
269
|
+
|
|
3
270
|
/**
|
|
4
271
|
* Generates an `llms.txt` routing manifest from the extracted symbols.
|
|
5
272
|
*
|
|
@@ -90,72 +357,6 @@ interface ReadmeSyncOptions {
|
|
|
90
357
|
*/
|
|
91
358
|
declare function syncReadme(readmePath: string, symbols: ForgeSymbol[], options?: ReadmeSyncOptions): Promise<boolean>;
|
|
92
359
|
|
|
93
|
-
/**
|
|
94
|
-
* A single generated documentation page.
|
|
95
|
-
* @public
|
|
96
|
-
*/
|
|
97
|
-
interface DocPage {
|
|
98
|
-
/** Relative path from outDir (e.g., "packages/core/index.md") */
|
|
99
|
-
path: string;
|
|
100
|
-
/** Page content (Markdown or MDX) */
|
|
101
|
-
content: string;
|
|
102
|
-
/** Frontmatter fields */
|
|
103
|
-
frontmatter: Record<string, string | number | boolean>;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Options controlling the doc site generator.
|
|
107
|
-
* @public
|
|
108
|
-
*/
|
|
109
|
-
interface SiteGeneratorOptions {
|
|
110
|
-
/** Output format */
|
|
111
|
-
format: "markdown" | "mdx";
|
|
112
|
-
/** SSG target for frontmatter */
|
|
113
|
-
ssgTarget?: "docusaurus" | "mintlify" | "nextra" | "vitepress";
|
|
114
|
-
/** Project name */
|
|
115
|
-
projectName: string;
|
|
116
|
-
/** Project description */
|
|
117
|
-
projectDescription?: string;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Groups symbols by their package based on file path.
|
|
121
|
-
*
|
|
122
|
-
* For monorepos (symbols under `packages/<name>/`) the package name is
|
|
123
|
-
* derived from the directory segment immediately after `packages/`.
|
|
124
|
-
* For non-monorepo projects all symbols fall under the project name.
|
|
125
|
-
*
|
|
126
|
-
* @param symbols - All extracted symbols.
|
|
127
|
-
* @param rootDir - Absolute path to the project root.
|
|
128
|
-
* @returns A map from package name to symbol list.
|
|
129
|
-
* @example
|
|
130
|
-
* ```typescript
|
|
131
|
-
* import { groupSymbolsByPackage } from "@forge-ts/gen";
|
|
132
|
-
* const grouped = groupSymbolsByPackage(symbols, "/path/to/project");
|
|
133
|
-
* console.log(grouped.has("core")); // true for monorepo
|
|
134
|
-
* ```
|
|
135
|
-
* @public
|
|
136
|
-
*/
|
|
137
|
-
declare function groupSymbolsByPackage(symbols: ForgeSymbol[], rootDir: string): Map<string, ForgeSymbol[]>;
|
|
138
|
-
/**
|
|
139
|
-
* Generates a full multi-page documentation site from symbols grouped by package.
|
|
140
|
-
*
|
|
141
|
-
* Produces an index page, a getting-started page, and per-package pages for
|
|
142
|
-
* the API reference, types, functions, and examples.
|
|
143
|
-
*
|
|
144
|
-
* @param symbolsByPackage - Symbols grouped by package name.
|
|
145
|
-
* @param config - The resolved {@link ForgeConfig}.
|
|
146
|
-
* @param options - Site generation options.
|
|
147
|
-
* @returns An array of {@link DocPage} objects ready to be written to disk.
|
|
148
|
-
* @example
|
|
149
|
-
* ```typescript
|
|
150
|
-
* import { generateDocSite, groupSymbolsByPackage } from "@forge-ts/gen";
|
|
151
|
-
* const grouped = groupSymbolsByPackage(symbols, config.rootDir);
|
|
152
|
-
* const pages = generateDocSite(grouped, config, { format: "markdown", projectName: "my-project" });
|
|
153
|
-
* console.log(pages.length > 0); // true
|
|
154
|
-
* ```
|
|
155
|
-
* @public
|
|
156
|
-
*/
|
|
157
|
-
declare function generateDocSite(symbolsByPackage: Map<string, ForgeSymbol[]>, config: ForgeConfig, options: SiteGeneratorOptions): DocPage[];
|
|
158
|
-
|
|
159
360
|
/**
|
|
160
361
|
* A single generated SSG configuration file.
|
|
161
362
|
* @public
|
|
@@ -212,4 +413,4 @@ declare function generateSSGConfigs(pages: DocPage[], target: "docusaurus" | "mi
|
|
|
212
413
|
*/
|
|
213
414
|
declare function generate(config: ForgeConfig): Promise<ForgeResult>;
|
|
214
415
|
|
|
215
|
-
export { type DocPage, type MarkdownOptions, type ReadmeSyncOptions, type SSGConfigFile, type SiteGeneratorOptions, generate, generateDocSite, generateLlmsFullTxt, generateLlmsTxt, generateMarkdown, generateSSGConfigs, groupSymbolsByPackage, syncReadme };
|
|
416
|
+
export { type AdapterContext, DEFAULT_TARGET, type DocPage, type GeneratedFile, type MarkdownOptions, type ReadmeSyncOptions, type SSGAdapter, type SSGConfigFile, type SSGStyleGuide, type SSGTarget, type ScaffoldManifest, type SiteGeneratorOptions, generate, generateDocSite, generateLlmsFullTxt, generateLlmsTxt, generateMarkdown, generateSSGConfigs, getAdapter, getAvailableTargets, groupSymbolsByPackage, registerAdapter, syncReadme };
|