forked from ourongxing/chatgpt-vercel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genEnv.ts
40 lines (37 loc) · 775 Bytes
/
genEnv.ts
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
import { defaultEnv } from "~/env"
import fs from "node:fs/promises"
const env = Object.entries(defaultEnv).reduce((acc, [key, value]) => {
let v = String(value)
if (v === "[object Object]") v = JSON.stringify(value)
if (v.includes("\n")) v = `'${v}'`
acc.push(`${key}=${v || ""}`)
return acc
}, [] as string[])
await fs.writeFile(".env.example", env.join("\n"))
const envDTS = `interface ImportMetaEnv {
${Object.keys(defaultEnv)
.map(key => ` ${key}?: string`)
.join("\n")}
}
`
await fs.writeFile(
"env.d.ts",
envDTS +
`
interface ImportMeta {
readonly env: ImportMetaEnv
}
`
)
await fs.writeFile(
"env.node.d.ts",
envDTS +
`
declare global {
namespace NodeJS {
interface ProcessEnv extends ImportMetaEnv { }
}
}
export {}
`
)