Skip to content

Commit

Permalink
Removed dotenv dependency to streamline configuration handling
Browse files Browse the repository at this point in the history
  • Loading branch information
micthiesen committed Oct 26, 2024
1 parent 2e6d5ae commit 9e52814
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"dependencies": {
"@micthiesen/mitools": "^1.1.1",
"date-fns": "^4.1.0",
"dotenv": "^16.4.5",
"html-entities": "^2.5.2",
"node-cron": "^3.0.3",
"p-queue": "^8.0.1",
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 6 additions & 9 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
import { baseConfigSchema } from "@micthiesen/mitools";
import dotenv from "dotenv";
import { z } from "zod";

// Load environment variables from .env file if it exists
dotenv.config();

// Define a Zod schema for the environment variables
const stringBoolean = (value: string): boolean => value.toLowerCase() === "true";
const envSchema = baseConfigSchema.extend({
const configSchema = baseConfigSchema.extend({
YT_CHANNEL_NAMES: z
.string()
.optional()
.transform((val) => (val ? val.split(",") : [])),
OFFLINE_NOTIFICATIONS: z.string().optional().default("true").transform(stringBoolean),
});

export type Config = z.infer<typeof envSchema>;
export type Config = z.infer<typeof configSchema>;

const config = envSchema.parse(process.env);
const config = configSchema.parse(process.env);
console.log(
"Config:",
Object.fromEntries(
Object.entries(config).map(([key, value]) => [
key,
key.includes("TOKEN") || key.includes("KEY") ? "***" : value,
key.includes("TOKEN") || key.includes("KEY") || key.includes("USER")
? "***"
: value,
]),
),
);
Expand Down

0 comments on commit 9e52814

Please sign in to comment.