|
1
|
import filterFiles from "../utils/filter-files.js" |
|
2
|
import path from "path" |
|
3
|
import DocblockGenerator from "../classes/generators/docblock.js" |
|
4
|
import getMonorepoRoot from "../utils/get-monorepo-root.js" |
|
5
|
import { GitManager } from "../classes/helpers/git-manager.js" |
|
6
|
import OasGenerator from "../classes/generators/oas.js" |
|
7
|
import { CommonCliOptions } from "../types/index.js" |
|
8
|
import DmlGenerator from "../classes/generators/dml.js" |
|
9
|
import RouteExamplesGenerator from "../classes/generators/route-examples.js" |
|
10
|
import EventsGenerator from "../classes/generators/events.js" |
|
11
|
|
|
12
|
export default async function ({ type, tag, ...options }: CommonCliOptions) { |
|
13
|
const gitManager = new GitManager() |
|
14
|
|
|
15
|
console.log(`Get files in commits since ${tag || "last release"}`) |
|
16
|
|
|
17
|
const files = tag |
|
18
|
? await gitManager.getCommitFilesSinceRelease(tag) |
|
19
|
: await gitManager.getCommitFilesSinceLastRelease() |
|
20
|
|
|
21
|
// filter changed files |
|
22
|
let filteredFiles = filterFiles(files) |
|
23
|
|
|
24
|
if (!filteredFiles.length) { |
|
25
|
console.log("No applicable files changed. Canceling...") |
|
26
|
return |
|
27
|
} |
|
28
|
|
|
29
|
console.log( |
|
30
|
`${filteredFiles.length} files have changed. Running generator on them...` |
|
31
|
) |
|
32
|
|
|
33
|
filteredFiles = filteredFiles.map((filePath) => |
|
34
|
path.resolve(getMonorepoRoot(), filePath) |
|
35
|
) |
|
36
|
|
|
37
|
if (type === "all" || type === "docs") { |
|
38
|
const docblockGenerator = new DocblockGenerator({ |
|
39
|
paths: filteredFiles, |
|
40
|
...options, |
|
41
|
}) |
|
42
|
|
|
43
|
await docblockGenerator.run() |
|
44
|
} |
|
45
|
|
|
46
|
if (type === "all" || type === "oas") { |
|
47
|
const oasGenerator = new OasGenerator({ |
|
48
|
paths: filteredFiles, |
|
49
|
...options, |
|
50
|
}) |
|
51
|
|
|
52
|
await oasGenerator.run() |
|
53
|
} |
|
54
|
|
|
55
|
if (type === "all" || type === "dml") { |
|
56
|
const dmlGenerator = new DmlGenerator({ |
|
57
|
paths: filteredFiles, |
|
58
|
...options, |
|
59
|
}) |
|
60
|
|
|
61
|
await dmlGenerator.run() |
|
62
|
} |
|
63
|
|
|
64
|
if (type === "all" || type === "route-examples") { |
|
65
|
const routeExamplesGenerator = new RouteExamplesGenerator({ |
|
66
|
paths: filteredFiles, |
|
67
|
...options, |
|
68
|
}) |
|
69
|
|
|
70
|
await routeExamplesGenerator.run() |
|
71
|
} |
|
72
|
|
|
73
|
if (type === "all" || type === "events") { |
|
74
|
const eventsGenerator = new EventsGenerator({ |
|
75
|
paths: filteredFiles, |
|
76
|
...options, |
|
77
|
}) |
|
78
|
|
|
79
|
await eventsGenerator.run() |
|
80
|
} |
|
81
|
|
|
82
|
console.log(`Finished generating docs for ${filteredFiles.length} files.`) |
|
83
|
} |