1 #!/usr/bin/env node
2 import "dotenv/config"
3 import { Command, Option } from "commander"
4 import run from "./commands/run.js"
5 import runGitChanges from "./commands/run-git-changes.js"
6 import runGitCommit from "./commands/run-git-commit.js"
7 import runRelease from "./commands/run-release.js"
8 import cleanOas from "./commands/clean-oas.js"
9 import cleanDml from "./commands/clean-dml.js"
10
11 const program = new Command()
12
13 program.name("docs-generator").description("Generate TSDoc doc-blocks")
14
15 // define common options
16 const typeOption = new Option("--type <type>", "The type of docs to generate.")
17 .choices(["all", "docs", "oas", "dml", "route-examples", "events"])
18 .default("all")
19
20 const generateExamplesOption = new Option(
21 "--generate-examples",
22 "Whether to generate examples"
23 ).default(false)
24
25 program
26 .command("run")
27 .description("Generate TSDoc doc-blocks for specified files.")
28 .argument("<files...>", "One or more TypeScript file or directory paths.")
29 .option(
30 "--dry-run",
31 "Whether to run the command without writing the changes."
32 )
33 .addOption(typeOption)
34 .addOption(generateExamplesOption)
35 .action(run)
36
37 program
38 .command("run:changes")
39 .description("Generate TSDoc doc-blocks for changed files in git.")
40 .addOption(typeOption)
41 .addOption(generateExamplesOption)
42 .action(runGitChanges)
43
44 program
45 .command("run:commit")
46 .description("Generate TSDoc doc-blocks for changed files in a commit.")
47 .argument("<commitSha>", "The SHA of a commit.")
48 .addOption(typeOption)
49 .addOption(generateExamplesOption)
50 .action(runGitCommit)
51
52 program
53 .command("run:release")
54 .description(
55 "Generate TSDoc doc-blocks for files part of the latest release. It will retrieve the files of commits between the latest two releases."
56 )
57 .addOption(typeOption)
58 .addOption(generateExamplesOption)
59 .option(
60 "--tag <tag>",
61 "Specify a release tag to use rather than the latest release."
62 )
63 .action(runRelease)
64
65 program
66 .command("clean:oas")
67 .description(
68 "Check generated OAS under the `oas-output/operations` directory and remove any OAS that no longer exists."
69 )
70 .action(cleanOas)
71
72 program
73 .command("clean:dml")
74 .description(
75 "Check generated DML files under the `dml-output` directory and remove any data models that no longer exists."
76 )
77 .action(cleanDml)
78
79 program.parse()