-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv.ts
More file actions
27 lines (25 loc) · 838 Bytes
/
env.ts
File metadata and controls
27 lines (25 loc) · 838 Bytes
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
import "dotenv/config";
import { z } from "zod";
import { GitHubArchiverZodParseError } from "./error.ts";
const envSchema = z
.object({
LOG_LEVEL: z.enum(["fatal", "error", "warn", "info", "debug", "trace", "silent"]).default("info"),
LOG_COLOR: z
.string()
.transform((val) => val.toLowerCase() === "true")
.default(false),
GH_TOKEN: z.string(),
GH_PATH: z.string().default("gh"),
GIT_PATH: z.string().default("git"),
HEARTBEAT_PATH: z.string().optional(),
COMPLETION_STATUS_PATH: z.string().optional(),
TZ: z.string().default("UTC"),
})
.catchall(z.string());
export const parseEnv = async () => {
const parsed = await envSchema.safeParseAsync(process.env);
if (parsed.success) {
return parsed.data;
}
throw new GitHubArchiverZodParseError("Failed to parse environment variables", parsed.error);
};