-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbin.js
More file actions
executable file
·58 lines (49 loc) · 1.64 KB
/
Copy pathbin.js
File metadata and controls
executable file
·58 lines (49 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env node
// Route modules are TypeScript, and the generators import them at runtime.
import "tsx/esm"
import minimist from "minimist"
const argv = minimist(process.argv.slice(2))
if (argv.help || argv.h) {
console.log(
`
nextlove (generate-openapi | generate-route-types | extract-route-specs) [options]
--packageDir <path> Path to the package directory containing the Next.js app
--outputFile <path> Path to the output file
--pathGlob <glob> Glob pattern to find API route files
--apiPrefix <path> Prefix for API routes, default: "/api"
`.trim()
)
process.exit(0)
}
const resolvePackageDir = () => {
if (argv._.length === 2) {
argv.packageDir = argv._[1]
}
if (argv["package-dir"]) {
argv.packageDir = argv["package-dir"]
}
if (!argv["packageDir"]) throw new Error("Missing --packageDir")
}
const report = (result) => {
if (!argv.outputFile) {
console.log(result)
}
}
if (argv._[0] === "generate-openapi") {
resolvePackageDir()
const { generateOpenAPI } = await import("./generators/index.js")
report(await generateOpenAPI(argv))
} else if (argv._[0] === "generate-route-types") {
resolvePackageDir()
const { generateRouteTypes } = await import("./generators/index.js")
report(await generateRouteTypes(argv))
} else if (argv._[0] === "extract-route-specs") {
resolvePackageDir()
if (argv["allowed-import-patterns"]) {
argv.allowedImportPatterns = Array.isArray(argv["allowed-import-patterns"])
? argv["allowed-import-patterns"]
: [argv["allowed-import-patterns"]]
}
const { extractRouteSpecs } = await import("./generators/index.js")
report(await extractRouteSpecs(argv))
}