()
| 589 | } |
| 590 | |
| 591 | async function main(): Promise<void> { |
| 592 | const repoRoot = getRepoRoot(); |
| 593 | const cli = await getProgram(repoRoot); |
| 594 | |
| 595 | const outputArg = process.argv[2]; |
| 596 | |
| 597 | if (!outputArg) { |
| 598 | throw new Error( |
| 599 | "Output directory is required. Usage: generate-cli-docs <output-directory>", |
| 600 | ); |
| 601 | } |
| 602 | |
| 603 | const outputDir = resolve(process.cwd(), outputArg); |
| 604 | await mkdir(outputDir, { recursive: true }); |
| 605 | |
| 606 | const topLevelCommands = cli.commands.filter( |
| 607 | (command) => command.parent === cli && !isHiddenCommand(command), |
| 608 | ); |
| 609 | |
| 610 | if (topLevelCommands.length === 0) { |
| 611 | console.warn("No top-level commands found. Nothing to document."); |
| 612 | return; |
| 613 | } |
| 614 | |
| 615 | const docs = topLevelCommands.map((command) => |
| 616 | buildCommandDoc(command, cli.name()), |
| 617 | ); |
| 618 | const indexDoc = buildIndexDoc(topLevelCommands, cli.name()); |
| 619 | |
| 620 | for (const doc of [...docs, indexDoc]) { |
| 621 | const filePath = join(outputDir, doc.fileName); |
| 622 | await mkdir(dirname(filePath), { recursive: true }); |
| 623 | const formatted = await formatWithPrettier(doc.mdx, filePath); |
| 624 | await writeFile(filePath, formatted, "utf8"); |
| 625 | console.log(`✅ Saved ${doc.commandPath} docs to ${filePath}`); |
| 626 | } |
| 627 | |
| 628 | if (process.env.GITHUB_ACTIONS) { |
| 629 | const commentMarker = "<!-- generate-cli-docs -->"; |
| 630 | const combinedMarkdown = docs |
| 631 | .map((doc) => doc.markdown) |
| 632 | .join("\n\n---\n\n"); |
| 633 | |
| 634 | const commentBody = [ |
| 635 | commentMarker, |
| 636 | "", |
| 637 | "Your PR updates Lingo.dev CLI behavior. Please review the regenerated reference docs below.", |
| 638 | "", |
| 639 | combinedMarkdown, |
| 640 | ].join("\n"); |
| 641 | |
| 642 | await createOrUpdateGitHubComment({ |
| 643 | commentMarker, |
| 644 | body: commentBody, |
| 645 | }); |
| 646 | } |
| 647 | } |
| 648 |
no test coverage detected