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