-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
65 lines (52 loc) · 1.54 KB
/
cli.js
File metadata and controls
65 lines (52 loc) · 1.54 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
59
60
61
62
63
64
65
#!/usr/bin/env -S deno run -A
import { resolve } from "@std/path"
import { parseArgs } from "@std/cli/parse-args"
import { main } from "./src/main.js"
function getVersion() {
try {
const json = JSON.parse(Deno.readTextFileSync("./deno.json"))
return json.version ?? "unknown"
} catch {
return "unknown"
}
}
function printHelp() {
console.log(`
Usage: genalia <module|directory> [options]
Options:
--out <outputDir> Specify output directory (default: ./dist)
--ignore <patterns> Ignore files or directories matching glob patterns (comma separated, default: **/.*)
--version Show version information
--help Show this help message
`)
}
if (import.meta.main) {
try {
const args = parseArgs(Deno.args, {
string: ["out", "ignore"],
boolean: ["version", "help"],
alias: { o: "out", V: "version", h: "help", i: "ignore"},
})
if (args.help) {
printHelp()
Deno.exit(0)
}
if (args.version) {
console.log(`genalia ${getVersion()}`)
Deno.exit(0)
}
const positionals = args._
if (positionals.length < 1) {
throw new Error("Missing required argument.\nUsage: genalia <module|directory> [--out <outputDir>]")
}
const inputPath = String(positionals[0])
const outDir = args.out ?? "./dist"
const ignore = args.ignore ?? "**/.*"
const options = { ignore }
await main(resolve(inputPath), resolve(outDir), options)
Deno.exit(0)
} catch (error) {
console.error("Error:", error.message)
Deno.exit(1)
}
}