-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathenv.ts
More file actions
63 lines (57 loc) · 1.31 KB
/
env.ts
File metadata and controls
63 lines (57 loc) · 1.31 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
/* eslint-disable node/no-process-env */
import fs from "fs";
import { z, parseEnv } from "znv";
import * as Sentry from "@sentry/node";
export const isDev = process.env["NODE_ENV"] !== "production";
if (isDev) {
(await import("dotenv")).config();
}
export const {
PERSIST_DIR,
MASTODON_TOKEN,
BSKY_USERNAME,
BSKY_PASSWORD,
SENTRY_DSN,
} = parseEnv(process.env, {
PERSIST_DIR: z.string().min(1).default("persist"),
MASTODON_TOKEN: {
schema: z.string().min(1),
defaults: {
development: "dev",
},
},
BSKY_USERNAME: {
schema: z.string().min(1),
defaults: {
development: "unused",
},
},
BSKY_PASSWORD: {
schema: z.string().min(1),
defaults: {
development: "unused",
},
},
SENTRY_DSN: {
schema: z.string().min(1).optional(),
},
});
if (!fs.existsSync(PERSIST_DIR)) {
throw new Error(`Persistence directory '${PERSIST_DIR}' doesn't exist!`);
}
export const MASTODON_SERVER = "https://mastodon.social";
if (!SENTRY_DSN && !isDev) {
console.warn(
`Sentry DSN is invalid! Error reporting to Sentry will be disabled.`,
);
} else {
Sentry.init({
dsn: SENTRY_DSN,
environment: isDev ? "dev" : "prod",
integrations: [
Sentry.captureConsoleIntegration({
levels: ["warn", "error", "debug", "assert"],
}),
],
});
}