-
Notifications
You must be signed in to change notification settings - Fork 1
/
env.ts
63 lines (56 loc) · 1.37 KB
/
env.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
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 { join } from "path";
import { existsSync } from "fs";
import * as Sentry from "@sentry/node";
import { parseEnv, z } from "znv";
const isDev = process.env["NODE_ENV"] !== "production";
if (isDev) {
require("dotenv").config();
}
export const {
MASTODON_TOKEN,
BSKY_USERNAME,
BSKY_PASSWORD,
SENTRY_DSN,
DATA_DIR,
} = parseEnv(process.env, {
MASTODON_TOKEN: {
schema: z.string().min(1),
defaults: { development: "_" },
},
BSKY_USERNAME: {
schema: z.string().min(1),
defaults: { development: "_" },
},
BSKY_PASSWORD: {
schema: z.string().min(1),
defaults: { development: "_" },
},
SENTRY_DSN: {
schema: z.string().min(1).optional(),
},
// The resource dir is currently checked in to the repo.
DATA_DIR: z
.string()
.min(1)
.default(() => join(__dirname, "..", "persist")),
});
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"],
}),
],
});
}
if (!existsSync(DATA_DIR)) {
throw new Error(`Data directory '${DATA_DIR}' doesn't exist!`);
}
export const MASTODON_SERVER = "https://mastodon.social";