@forge-ts/gen 0.4.0 → 0.6.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 CHANGED
@@ -1,5 +1,325 @@
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
+ * When true, this page is scaffolding intended for human/agent editing.
16
+ * Stub pages are created only on the first build and never overwritten,
17
+ * preserving manual edits across subsequent `forge-ts build` runs.
18
+ * Auto-generated pages (stub=false) are always regenerated from source.
19
+ */
20
+ stub?: boolean;
21
+ }
22
+ /**
23
+ * Options controlling the doc site generator.
24
+ * @public
25
+ */
26
+ interface SiteGeneratorOptions {
27
+ /** Output format */
28
+ format: "markdown" | "mdx";
29
+ /** SSG target for frontmatter */
30
+ ssgTarget?: "docusaurus" | "mintlify" | "nextra" | "vitepress";
31
+ /** Project name */
32
+ projectName: string;
33
+ /** Project description */
34
+ projectDescription?: string;
35
+ /** Repository URL (auto-detected from package.json). */
36
+ repositoryUrl?: string;
37
+ /** npm package name for install commands. */
38
+ packageName?: string;
39
+ }
40
+ /**
41
+ * Groups symbols by their package based on file path.
42
+ *
43
+ * For monorepos (symbols under `packages/<name>/`) the package name is
44
+ * derived from the directory segment immediately after `packages/`.
45
+ * For non-monorepo projects all symbols fall under the project name.
46
+ *
47
+ * @param symbols - All extracted symbols.
48
+ * @param rootDir - Absolute path to the project root.
49
+ * @returns A map from package name to symbol list.
50
+ * @example
51
+ * ```typescript
52
+ * import { groupSymbolsByPackage } from "@forge-ts/gen";
53
+ * const grouped = groupSymbolsByPackage(symbols, "/path/to/project");
54
+ * console.log(grouped.has("core")); // true for monorepo
55
+ * ```
56
+ * @public
57
+ */
58
+ declare function groupSymbolsByPackage(symbols: ForgeSymbol[], rootDir: string): Map<string, ForgeSymbol[]>;
59
+ /**
60
+ * Generates a full multi-page documentation site from symbols grouped by package.
61
+ *
62
+ * Follows a 5-stage information architecture:
63
+ * 1. ORIENT — Landing page, Getting Started
64
+ * 2. LEARN — Concepts (stub)
65
+ * 3. BUILD — Guides (stub)
66
+ * 4. REFERENCE — API Reference, Types, Configuration, Changelog
67
+ * 5. COMMUNITY — FAQ, Contributing (stubs)
68
+ *
69
+ * @param symbolsByPackage - Symbols grouped by package name.
70
+ * @param config - The resolved {@link ForgeConfig}.
71
+ * @param options - Site generation options.
72
+ * @returns An array of {@link DocPage} objects ready to be written to disk.
73
+ * @example
74
+ * ```typescript
75
+ * import { generateDocSite, groupSymbolsByPackage } from "@forge-ts/gen";
76
+ * const grouped = groupSymbolsByPackage(symbols, config.rootDir);
77
+ * const pages = generateDocSite(grouped, config, { format: "markdown", projectName: "my-project" });
78
+ * console.log(pages.length > 0); // true
79
+ * ```
80
+ * @public
81
+ */
82
+ declare function generateDocSite(symbolsByPackage: Map<string, ForgeSymbol[]>, config: ForgeConfig, options: SiteGeneratorOptions): DocPage[];
83
+
84
+ /**
85
+ * Supported SSG target identifiers.
86
+ * @public
87
+ */
88
+ type SSGTarget = "mintlify" | "docusaurus" | "nextra" | "vitepress";
89
+ /**
90
+ * A file to write to disk during scaffolding or generation.
91
+ * @public
92
+ */
93
+ interface GeneratedFile {
94
+ /** Relative path from the docs output directory. */
95
+ path: string;
96
+ /** File content (string for text). */
97
+ content: string;
98
+ /**
99
+ * When true, this file is scaffolding intended for human/agent editing.
100
+ * Stub files are created only on the first build and never overwritten,
101
+ * preserving manual edits across subsequent `forge-ts build` runs.
102
+ * Callers should check this flag and skip writing if the file exists.
103
+ */
104
+ stub?: boolean;
105
+ }
106
+ /**
107
+ * Style guide configuration for the SSG target.
108
+ * @public
109
+ */
110
+ interface SSGStyleGuide {
111
+ /** File extension for doc pages. */
112
+ pageExtension: "md" | "mdx";
113
+ /** Whether the target supports MDX components. */
114
+ supportsMdx: boolean;
115
+ /** Whether frontmatter is required on every page. */
116
+ requiresFrontmatter: boolean;
117
+ /** Maximum recommended heading depth. */
118
+ maxHeadingDepth: number;
119
+ /** Component imports to add at top of MDX files (if supportsMdx). */
120
+ defaultImports: string[];
121
+ /** Code block language for TypeScript examples. */
122
+ codeBlockLanguage: "typescript" | "ts" | "tsx";
123
+ }
124
+ /**
125
+ * Scaffold manifest describing what `init docs` creates.
126
+ * @public
127
+ */
128
+ interface ScaffoldManifest {
129
+ /** The SSG target this manifest is for. */
130
+ target: SSGTarget;
131
+ /** Files that will be created. */
132
+ files: GeneratedFile[];
133
+ /** npm dependencies to install. */
134
+ dependencies: Record<string, string>;
135
+ /** npm devDependencies to install. */
136
+ devDependencies: Record<string, string>;
137
+ /** Scripts to add to package.json. */
138
+ scripts: Record<string, string>;
139
+ /** Post-scaffold instructions for the user. */
140
+ instructions: string[];
141
+ }
142
+ /**
143
+ * Context passed to adapter methods.
144
+ * @public
145
+ */
146
+ interface AdapterContext {
147
+ /** Resolved forge-ts configuration. */
148
+ config: ForgeConfig;
149
+ /** Project name (from package.json or directory). */
150
+ projectName: string;
151
+ /** Project description. */
152
+ projectDescription?: string;
153
+ /** The generated doc pages (from site-generator). */
154
+ pages: DocPage[];
155
+ /** All symbols extracted from the project. */
156
+ symbols: ForgeSymbol[];
157
+ /** Output directory for generated docs. */
158
+ outDir: string;
159
+ }
160
+ /**
161
+ * Command to start a local dev server for doc preview.
162
+ * @public
163
+ */
164
+ interface DevServerCommand {
165
+ /** The binary to execute (e.g., "npx", "node"). */
166
+ bin: string;
167
+ /** Arguments to pass to the binary. */
168
+ args: string[];
169
+ /** Working directory to run from. */
170
+ cwd: string;
171
+ /** Human-readable label for the command. */
172
+ label: string;
173
+ /** The URL the dev server will be available at. */
174
+ url: string;
175
+ }
176
+ /**
177
+ * The central SSG adapter interface.
178
+ * Every doc platform provider implements this contract.
179
+ * One file per provider. No shared mutable state.
180
+ *
181
+ * @example
182
+ * ```typescript
183
+ * import { getAdapter } from "@forge-ts/gen";
184
+ * const adapter = getAdapter("mintlify");
185
+ * const files = adapter.transformPages(pages, context);
186
+ * ```
187
+ * @public
188
+ */
189
+ interface SSGAdapter {
190
+ /** Unique target identifier. */
191
+ readonly target: SSGTarget;
192
+ /** Human-readable display name. */
193
+ readonly displayName: string;
194
+ /** Style guide for this platform. */
195
+ readonly styleGuide: SSGStyleGuide;
196
+ /**
197
+ * Generate the complete scaffold for a new doc site.
198
+ * Called by `forge-ts init docs --target <name>`.
199
+ * Returns all files, dependencies, and scripts needed.
200
+ *
201
+ * @param context - The adapter context for the current project.
202
+ * @returns A {@link ScaffoldManifest} with files, deps, and instructions.
203
+ * @example
204
+ * ```typescript
205
+ * import { getAdapter } from "@forge-ts/gen";
206
+ * const adapter = getAdapter("mintlify");
207
+ * const manifest = adapter.scaffold(context);
208
+ * console.log(manifest.files.length);
209
+ * ```
210
+ */
211
+ scaffold(context: AdapterContext): ScaffoldManifest;
212
+ /**
213
+ * Transform generic DocPages into platform-specific pages.
214
+ * Adds correct frontmatter, component imports, file extensions.
215
+ * Called during `forge-ts build`.
216
+ *
217
+ * @param pages - The generic doc pages to transform.
218
+ * @param context - The adapter context for the current project.
219
+ * @returns An array of {@link GeneratedFile} objects ready to write.
220
+ * @example
221
+ * ```typescript
222
+ * import { getAdapter } from "@forge-ts/gen";
223
+ * const adapter = getAdapter("docusaurus");
224
+ * const files = adapter.transformPages(pages, context);
225
+ * console.log(files[0].path.endsWith(".mdx")); // true
226
+ * ```
227
+ */
228
+ transformPages(pages: DocPage[], context: AdapterContext): GeneratedFile[];
229
+ /**
230
+ * Generate platform-specific configuration files.
231
+ * e.g., mint.json, sidebars.js, _meta.json, .vitepress/config.ts
232
+ * Called during `forge-ts build`.
233
+ *
234
+ * @param context - The adapter context for the current project.
235
+ * @returns An array of {@link GeneratedFile} objects ready to write.
236
+ * @example
237
+ * ```typescript
238
+ * import { getAdapter } from "@forge-ts/gen";
239
+ * const adapter = getAdapter("vitepress");
240
+ * const configs = adapter.generateConfig(context);
241
+ * console.log(configs[0].path); // ".vitepress/sidebar.json"
242
+ * ```
243
+ */
244
+ generateConfig(context: AdapterContext): GeneratedFile[];
245
+ /**
246
+ * Get the command to start the local dev server for this platform.
247
+ * Called by `forge-ts docs dev`.
248
+ *
249
+ * @param outDir - The docs output directory.
250
+ * @returns The shell command and args to spawn, plus a display label.
251
+ * @example
252
+ * ```typescript
253
+ * import { getAdapter } from "@forge-ts/gen";
254
+ * const adapter = getAdapter("mintlify");
255
+ * const cmd = adapter.getDevCommand("./docs");
256
+ * // { bin: "npx", args: ["@mintlify/cli", "dev"], cwd: "./docs" }
257
+ * ```
258
+ */
259
+ getDevCommand(outDir: string): DevServerCommand;
260
+ /**
261
+ * Check if a scaffold already exists in the output directory.
262
+ * Used for safety checks before init or target change.
263
+ *
264
+ * @param outDir - The output directory to inspect.
265
+ * @returns `true` if a scaffold marker file already exists.
266
+ * @example
267
+ * ```typescript
268
+ * import { getAdapter } from "@forge-ts/gen";
269
+ * const adapter = getAdapter("mintlify");
270
+ * const exists = await adapter.detectExisting("./docs");
271
+ * if (exists) console.log("Scaffold already present");
272
+ * ```
273
+ */
274
+ detectExisting(outDir: string): Promise<boolean>;
275
+ }
276
+
277
+ /**
278
+ * Register an SSG adapter.
279
+ * Called once per provider at module load time.
280
+ *
281
+ * @param adapter - The adapter to register.
282
+ * @example
283
+ * ```typescript
284
+ * import { registerAdapter } from "@forge-ts/gen";
285
+ * registerAdapter(mintlifyAdapter);
286
+ * ```
287
+ * @public
288
+ */
289
+ declare function registerAdapter(adapter: SSGAdapter): void;
290
+ /**
291
+ * Get a registered adapter by target name.
292
+ * Throws if the target is not registered.
293
+ *
294
+ * @param target - The SSG target identifier.
295
+ * @returns The registered {@link SSGAdapter} for the given target.
296
+ * @throws `Error` if the target is not registered.
297
+ * @example
298
+ * ```typescript
299
+ * import { getAdapter } from "@forge-ts/gen";
300
+ * const adapter = getAdapter("mintlify");
301
+ * ```
302
+ * @public
303
+ */
304
+ declare function getAdapter(target: SSGTarget): SSGAdapter;
305
+ /**
306
+ * Get all registered adapter targets.
307
+ *
308
+ * @returns An array of all registered {@link SSGTarget} identifiers.
309
+ * @example
310
+ * ```typescript
311
+ * import { getAvailableTargets } from "@forge-ts/gen";
312
+ * const targets = getAvailableTargets(); // ["mintlify", "docusaurus", ...]
313
+ * ```
314
+ * @public
315
+ */
316
+ declare function getAvailableTargets(): SSGTarget[];
317
+ /**
318
+ * The default SSG target when none is specified.
319
+ * @public
320
+ */
321
+ declare const DEFAULT_TARGET: SSGTarget;
322
+
3
323
  /**
4
324
  * Generates an `llms.txt` routing manifest from the extracted symbols.
5
325
  *
@@ -91,70 +411,55 @@ interface ReadmeSyncOptions {
91
411
  declare function syncReadme(readmePath: string, symbols: ForgeSymbol[], options?: ReadmeSyncOptions): Promise<boolean>;
92
412
 
93
413
  /**
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.
414
+ * A generated skill package following the agentskills.io directory structure.
415
+ * Contains SKILL.md plus optional references and scripts files.
416
+ *
107
417
  * @public
108
418
  */
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;
419
+ interface SkillPackage {
420
+ /** The skill directory name (lowercase, hyphens only, max 64 chars). */
421
+ directoryName: string;
422
+ /** Files to write inside the skill directory. */
423
+ files: Array<{
424
+ path: string;
425
+ content: string;
426
+ }>;
118
427
  }
119
428
  /**
120
- * Groups symbols by their package based on file path.
429
+ * Generates an agentskills.io-compliant skill package for ANY TypeScript project.
121
430
  *
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.
431
+ * All content is derived from the project's exported symbols and metadata.
432
+ * No hardcoded project-specific content. Works for any project that forge-ts analyzes.
125
433
  *
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.
434
+ * @param symbols - All symbols from the project.
435
+ * @param config - The resolved forge-ts config.
436
+ * @returns A {@link SkillPackage} describing the directory and its files.
129
437
  * @example
130
438
  * ```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
439
+ * import { generateSkillPackage } from "@forge-ts/gen";
440
+ * const pkg = generateSkillPackage(symbols, config);
441
+ * console.log(pkg.directoryName); // "my-lib"
442
+ * console.log(pkg.files.map(f => f.path));
443
+ * // ["SKILL.md", "references/API-REFERENCE.md", ...]
134
444
  * ```
135
445
  * @public
136
446
  */
137
- declare function groupSymbolsByPackage(symbols: ForgeSymbol[], rootDir: string): Map<string, ForgeSymbol[]>;
447
+ declare function generateSkillPackage(symbols: ForgeSymbol[], config: ForgeConfig): SkillPackage;
138
448
  /**
139
- * Generates a full multi-page documentation site from symbols grouped by package.
449
+ * Generates a SKILL.md string following the Agent Skills specification.
450
+ * Generic for any TypeScript project — content derived from symbols.
140
451
  *
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.
452
+ * @param symbols - All symbols from the project.
453
+ * @param config - The resolved forge-ts config.
454
+ * @returns The SKILL.md content as a string.
148
455
  * @example
149
456
  * ```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
457
+ * import { generateSkillMd } from "@forge-ts/gen";
458
+ * const skill = generateSkillMd(symbols, config);
154
459
  * ```
155
460
  * @public
156
461
  */
157
- declare function generateDocSite(symbolsByPackage: Map<string, ForgeSymbol[]>, config: ForgeConfig, options: SiteGeneratorOptions): DocPage[];
462
+ declare function generateSkillMd(symbols: ForgeSymbol[], config: ForgeConfig): string;
158
463
 
159
464
  /**
160
465
  * A single generated SSG configuration file.
@@ -196,10 +501,35 @@ declare function generateSSGConfigs(pages: DocPage[], target: "docusaurus" | "mi
196
501
  * @public
197
502
  */
198
503
 
504
+ /**
505
+ * Options for the generation pipeline.
506
+ *
507
+ * @public
508
+ */
509
+ interface GenerateOptions {
510
+ /**
511
+ * When true, overwrite stub pages even if they already exist on disk.
512
+ * Normally stub pages (concepts, guides, faq, contributing, changelog)
513
+ * are only created on the first build to preserve manual edits.
514
+ * Use this to reset stubs to their scaffolding state.
515
+ *
516
+ * @example
517
+ * ```typescript
518
+ * await generate(config, { forceStubs: true });
519
+ * ```
520
+ */
521
+ forceStubs?: boolean;
522
+ }
199
523
  /**
200
524
  * Runs the full generation pipeline: walk → render → write.
201
525
  *
526
+ * Auto-generated pages are always regenerated from source code.
527
+ * Stub pages (scaffolding for human/agent editing) are only created
528
+ * if they don't already exist, preserving manual edits across builds.
529
+ * Pass `{ forceStubs: true }` to overwrite stubs.
530
+ *
202
531
  * @param config - The resolved {@link ForgeConfig} for the project.
532
+ * @param options - Optional generation flags (e.g., forceStubs).
203
533
  * @returns A {@link ForgeResult} describing the outcome.
204
534
  * @example
205
535
  * ```typescript
@@ -210,6 +540,6 @@ declare function generateSSGConfigs(pages: DocPage[], target: "docusaurus" | "mi
210
540
  * @public
211
541
  * @packageDocumentation
212
542
  */
213
- declare function generate(config: ForgeConfig): Promise<ForgeResult>;
543
+ declare function generate(config: ForgeConfig, options?: GenerateOptions): Promise<ForgeResult>;
214
544
 
215
- export { type DocPage, type MarkdownOptions, type ReadmeSyncOptions, type SSGConfigFile, type SiteGeneratorOptions, generate, generateDocSite, generateLlmsFullTxt, generateLlmsTxt, generateMarkdown, generateSSGConfigs, groupSymbolsByPackage, syncReadme };
545
+ export { type AdapterContext, DEFAULT_TARGET, type DevServerCommand, type DocPage, type GenerateOptions, type GeneratedFile, type MarkdownOptions, type ReadmeSyncOptions, type SSGAdapter, type SSGConfigFile, type SSGStyleGuide, type SSGTarget, type ScaffoldManifest, type SiteGeneratorOptions, type SkillPackage, generate, generateDocSite, generateLlmsFullTxt, generateLlmsTxt, generateMarkdown, generateSSGConfigs, generateSkillMd, generateSkillPackage, getAdapter, getAvailableTargets, groupSymbolsByPackage, registerAdapter, syncReadme };