-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
executable file
·63 lines (49 loc) · 1.68 KB
/
index.js
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
#!/usr/bin/env node
// @ts-check
import { Command, InvalidArgumentError } from "commander"
import * as y from "yoctocolors"
import { ask, init, secret, add } from "./commands/index.js"
// import pkg from "./package.json" assert { type: "json" }
import fs from "node:fs/promises"
import { join } from "node:path"
import { fileURLToPath } from "node:url"
const __dirname = fileURLToPath(new URL(".", import.meta.url))
const pkg = JSON.parse(
await fs.readFile(join(__dirname, "./package.json"), "utf-8")
)
const { name, description, version } = pkg
try {
// TODO: Remove when Node.js 18 is not maintained anymore
// @ts-expect-error
globalThis.crypto ??= (await import("crypto")).webcrypto
} catch {}
const program = new Command()
program
.name(name)
.description(description.replace("Auth.js", y.magenta(y.bold("Auth.js"))))
.version(version)
program
.command("ask")
.option("--stream", "Stream the response.")
.option("--raw", "Show the Markdown response without formatting.")
.description("Ask about docs, API, or auth concepts.")
.action(ask.action)
program
.command("init")
.argument("[framework]", "The framework to use.")
.option("-e, --example", "Clone a full example.")
.description("Initialize a project.")
.action(init.action)
program
.command("secret")
.option("--raw", "Output the string without any formatting.")
.option("--copy", 'Copy AUTH_SECRET="value".')
.description("Generate a random string and add it to the .env file.")
.action(secret.action)
program
.command("add")
.argument("[provider]", "The authentication provider.")
.description('Register a new authentication provider')
.action(add.action)
program.parse()
export { program }