From b05e2a5622eab84df7df2ae5986511af5109b50f Mon Sep 17 00:00:00 2001 From: Wiktoria Van Harneveldt Date: Tue, 4 Nov 2025 14:44:29 +0100 Subject: [PATCH 01/15] chore: update development script to set NODE_ENV for improved environment handling --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7d00706..e5b6092 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "build:ts": "tsup", "build:copy": "node scripts/copy-assets.js", "start": "node dist/index.js", - "dev": "tsx watch src/index.ts", + "dev": "NODE_ENV=development tsx watch src/index.ts", "deploy": "tsx src/util/deploy.ts", "docker:build": "NODE_VERSION=$(cat .nvmrc | tr -d 'v') docker compose build", "docker:dev": "NODE_VERSION=$(cat .nvmrc | tr -d 'v') docker compose --profile dev up", From 48f31b95736a5b75d82f7ae21a2246f19e0447ae Mon Sep 17 00:00:00 2001 From: Wiktoria Van Harneveldt Date: Tue, 4 Nov 2025 14:45:10 +0100 Subject: [PATCH 02/15] feat: add development environment support for configuration management --- src/env.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/env.ts b/src/env.ts index cc90dea..b24c109 100644 --- a/src/env.ts +++ b/src/env.ts @@ -14,6 +14,14 @@ function requireEnv(key: string): string { return value; } +function useDevEnv(key: string): string | undefined { + const isDev = process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test'; + if (isDev) { + return optionalEnv(key); + } + return undefined; +} + // Single source of truth for all configuration export const config = { discord: { @@ -33,6 +41,9 @@ export const config = { channelId: requireEnv('GUIDES_CHANNEL_ID'), trackerPath: optionalEnv('GUIDES_TRACKER_PATH'), }, + roleIds: { + examleRole: useDevEnv('EXAMPLE_ROLE_ID') ?? '12345', + }, // Add more config sections as needed: // database: { // url: requireEnv('DATABASE_URL'), From 0e09848ba457b5c4f50fbccfcd5e73ec8894076b Mon Sep 17 00:00:00 2001 From: Wiktoria Van Harneveldt Date: Tue, 4 Nov 2025 18:46:12 +0100 Subject: [PATCH 03/15] feat: add environment configuration files for development and production --- .env.development | 16 ++++++++++++++++ .env.example | 19 ++++++++++++------- .env.production | 16 ++++++++++++++++ .gitignore | 6 ++++-- 4 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 .env.development create mode 100644 .env.production diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..4c369d4 --- /dev/null +++ b/.env.development @@ -0,0 +1,16 @@ +# Development Environment Configuration +# Public values - safe to commit to repository +# These are Discord IDs for your development/test server + +# Discord Server ID (your dev server) +SERVER_ID=1403539983821963274 + +# Channel IDs (from your dev server) +GUIDES_CHANNEL_ID=1426998962635804712 +REPEL_LOG_CHANNEL_ID=1403540596035027045 + +# Role IDs (from your dev server) +REPEL_ROLE_ID=1403545113904414842 +MODERATORS_ROLE_IDS=1428151937534005379 + +# Note: DISCORD_TOKEN & CLIENT_ID should be in .env.local (not committed) diff --git a/.env.example b/.env.example index 6323e1b..dae88eb 100644 --- a/.env.example +++ b/.env.example @@ -1,9 +1,14 @@ -DISCORD_TOKEN="" # Your bot token -CLIENT_ID="" # Your bot's application ID +# Local Environment Variables (Secrets) +# Copy this file to .env.local and fill in your actual values +# .env.local is gitignored and should NEVER be committed -SERVER_ID= # Discord Server ID where the bot will operate -MODERATORS_ROLE_IDS= # Comma separated list of role IDs that are Moderators(Mods, Admins, etc) +# Discord Bot Token & Application ID (REQUIRED) +# Get this from: https://discord.com/developers/applications +DISCORD_TOKEN=your-bot-token-here +CLIENT_ID=your-bot-application-id -REPEL_LOG_CHANNEL_ID= # Channel ID where the bot will log repel actions -REPEL_ROLE_ID= # Role ID assigned to users who can use the repel command -GUIDES_CHANNEL_ID="" # The ID of the channel where guides will be posted +# Optional: Override any public config values for local testing +# Uncomment and modify as needed: +# SERVER_ID=override-server-id +# CLIENT_ID=override-client-id +# GUIDES_CHANNEL_ID=override-channel-id diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..5994b78 --- /dev/null +++ b/.env.production @@ -0,0 +1,16 @@ +# Production Environment Configuration +# Public values - safe to commit to repository +# These are Discord IDs that are publicly visible anyway + +# Discord Server ID +SERVER_ID=your-prod-server-id + +# Channel IDs +GUIDES_CHANNEL_ID=your-prod-guides-channel-id +REPEL_LOG_CHANNEL_ID=your-prod-repel-log-channel-id + +# Role IDs +REPEL_ROLE_ID=your-prod-repel-role-id +MODERATORS_ROLE_IDS=your-prod-moderator-role-id-1,your-prod-moderator-role-id-2 + +# Note: DISCORD_TOKEN & CLIENT_ID should be in .env.local (not committed) diff --git a/.gitignore b/.gitignore index e6f1a18..fcc9ff1 100644 --- a/.gitignore +++ b/.gitignore @@ -12,10 +12,12 @@ yarn-debug.log* yarn-error.log* # Env files -!.env.example -.env .env.local .env.*.local +# Allow environment-specific configs (public, non-secret) +!.env.development +!.env.production +!.env.example # guides tracker guides-tracker.json \ No newline at end of file From 4e7beee5c2ee1a66f890cece20a442759cd2d269 Mon Sep 17 00:00:00 2001 From: Wiktoria Van Harneveldt Date: Tue, 4 Nov 2025 18:46:23 +0100 Subject: [PATCH 04/15] chore: simplify development script by removing NODE_ENV setting --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e5b6092..7d00706 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "build:ts": "tsup", "build:copy": "node scripts/copy-assets.js", "start": "node dist/index.js", - "dev": "NODE_ENV=development tsx watch src/index.ts", + "dev": "tsx watch src/index.ts", "deploy": "tsx src/util/deploy.ts", "docker:build": "NODE_VERSION=$(cat .nvmrc | tr -d 'v') docker compose build", "docker:dev": "NODE_VERSION=$(cat .nvmrc | tr -d 'v') docker compose --profile dev up", From d967a7a3fa30756b6194081262f9f025ca32a8c6 Mon Sep 17 00:00:00 2001 From: Wiktoria Van Harneveldt Date: Tue, 4 Nov 2025 18:46:33 +0100 Subject: [PATCH 05/15] feat: enhance environment loading by adding dynamic file selection and logging --- src/loadEnvFile.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/loadEnvFile.ts b/src/loadEnvFile.ts index d402947..4766ffe 100644 --- a/src/loadEnvFile.ts +++ b/src/loadEnvFile.ts @@ -4,6 +4,7 @@ import { join } from 'node:path'; // Simple .env loader without external dependencies function loadEnvFile(filePath: string) { if (!existsSync(filePath)) { + console.warn(`Warning: File ${filePath} not found`); return; } @@ -24,12 +25,22 @@ function loadEnvFile(filePath: string) { } } } + console.log(`✅ Loaded: ${filePath}`); } catch (error) { console.warn(`Warning: Could not load ${filePath}`); - console.warn('Make sure a valid .env.local file exists.'); console.warn(error); } } -// Load local environment file if it exists -loadEnvFile(join(process.cwd(), '.env.local')); +// Determine environment (defaults to development) +const nodeEnv = process.env.NODE_ENV || 'development'; +console.log(`🌍 Environment: ${nodeEnv}`); + +// Load environment-specific config first (public values) +const envFile = join(process.cwd(), `.env.${nodeEnv}`); +loadEnvFile(envFile); + +// Load local overrides and secrets second (overrides public config) +// Required in both dev and prod for DISCORD_TOKEN +const localEnvFile = join(process.cwd(), '.env.local'); +loadEnvFile(localEnvFile); From d9aea1fed619d04eef81934c1e8810bc61a110da Mon Sep 17 00:00:00 2001 From: Wiktoria Van Harneveldt Date: Tue, 4 Nov 2025 18:46:40 +0100 Subject: [PATCH 06/15] feat: add NODE_ENV settings and environment config files for production and development --- .github/workflows/deploy.yml | 10 ++++------ Dockerfile | 3 +++ docker-compose.yml | 5 +++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 58e6a74..125eb7d 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -38,21 +38,19 @@ jobs: export NODE_VERSION=$(cat .nvmrc | sed 's/v//') echo "Using Node version: $NODE_VERSION" - # Create .env.local file with secrets + # Create .env.local file with secrets only + # Public config comes from .env.production (committed to repo) + # NODE_ENV=production is set in docker-compose.yml cat > .env.local << EOF DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} CLIENT_ID=${{ secrets.CLIENT_ID }} - GUIDES_CHANNEL_ID=${{ secrets.GUIDES_CHANNEL_ID }} - SERVER_ID=${{ secrets.SERVER_ID }} - REPEL_LOG_CHANNEL_ID=${{ secrets.REPEL_LOG_CHANNEL_ID }} - REPEL_ROLE_ID=${{ secrets.REPEL_ROLE_ID }} - MODERATORS_ROLE_IDS=${{ secrets.MODERATORS_ROLE_IDS }} EOF # Stop any existing containers docker compose down || true # Build and start production container with profile + # NODE_ENV=production is explicitly set in docker-compose.yml bot-prod service docker compose --profile prod up -d --build # Check status diff --git a/Dockerfile b/Dockerfile index 60f7635..799aa81 100644 --- a/Dockerfile +++ b/Dockerfile @@ -41,6 +41,9 @@ COPY --from=deps /app/node_modules ./node_modules COPY --from=build /app/dist ./dist COPY package.json ./ +# Copy environment config files (public, non-secret) +COPY .env.production .env.development ./ + # Create data directory and set permissions for node user RUN mkdir -p /app/data && chown -R node:node /app/data diff --git a/docker-compose.yml b/docker-compose.yml index 0978750..39af049 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,6 +11,7 @@ services: env_file: - .env.local environment: + - NODE_ENV=production - GUIDES_TRACKER_PATH=/app/data/guides-tracker.json volumes: # Persist guides tracker data @@ -30,6 +31,7 @@ services: env_file: - .env.local environment: + - NODE_ENV=development - GUIDES_TRACKER_PATH=/app/data/guides-tracker.json volumes: # Mount source code for hot reload @@ -40,6 +42,9 @@ services: # Mount package files (in case dependencies change) - ./package.json:/app/package.json:ro - ./pnpm-lock.yaml:/app/pnpm-lock.yaml:ro + # Mount environment config files + - ./.env.development:/app/.env.development:ro + - ./.env.production:/app/.env.production:ro # Persist guides tracker data - guides-data:/app/data profiles: From 3502031321a906842cab34064d67458c923f9bd8 Mon Sep 17 00:00:00 2001 From: Wiktoria Van Harneveldt Date: Tue, 4 Nov 2025 19:35:38 +0100 Subject: [PATCH 07/15] refactor: remove unused development environment function and related configuration --- src/env.ts | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/env.ts b/src/env.ts index b24c109..cc90dea 100644 --- a/src/env.ts +++ b/src/env.ts @@ -14,14 +14,6 @@ function requireEnv(key: string): string { return value; } -function useDevEnv(key: string): string | undefined { - const isDev = process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test'; - if (isDev) { - return optionalEnv(key); - } - return undefined; -} - // Single source of truth for all configuration export const config = { discord: { @@ -41,9 +33,6 @@ export const config = { channelId: requireEnv('GUIDES_CHANNEL_ID'), trackerPath: optionalEnv('GUIDES_TRACKER_PATH'), }, - roleIds: { - examleRole: useDevEnv('EXAMPLE_ROLE_ID') ?? '12345', - }, // Add more config sections as needed: // database: { // url: requireEnv('DATABASE_URL'), From 3b8470325b294d0a385a14e26419d632c3b68fce Mon Sep 17 00:00:00 2001 From: Wiktoria Van Harneveldt Date: Tue, 4 Nov 2025 21:19:17 +0100 Subject: [PATCH 08/15] chore: update docker-compose configuration --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 39af049..f16890f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,8 +12,9 @@ services: - .env.local environment: - NODE_ENV=production - - GUIDES_TRACKER_PATH=/app/data/guides-tracker.json volumes: + # Mount environment config file + - ./.env.production:/app/.env.production:ro # Persist guides tracker data - guides-data:/app/data profiles: @@ -32,7 +33,6 @@ services: - .env.local environment: - NODE_ENV=development - - GUIDES_TRACKER_PATH=/app/data/guides-tracker.json volumes: # Mount source code for hot reload - ./src:/app/src:ro From 384c452fe1e4ab42f600a13aa658900569503491 Mon Sep 17 00:00:00 2001 From: Wiktoria Van Harneveldt Date: Tue, 4 Nov 2025 21:19:45 +0100 Subject: [PATCH 09/15] chore: update production environment variables for development server --- .env.production | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.env.production b/.env.production index 5994b78..fb3ab4c 100644 --- a/.env.production +++ b/.env.production @@ -2,15 +2,18 @@ # Public values - safe to commit to repository # These are Discord IDs that are publicly visible anyway -# Discord Server ID -SERVER_ID=your-prod-server-id +# Discord Server ID (your dev server) +SERVER_ID=434487340535382016 -# Channel IDs -GUIDES_CHANNEL_ID=your-prod-guides-channel-id -REPEL_LOG_CHANNEL_ID=your-prod-repel-log-channel-id +# Channel IDs (from your dev server) +GUIDES_CHANNEL_ID=1429492053825290371 +REPEL_LOG_CHANNEL_ID=1403558160144531589 -# Role IDs -REPEL_ROLE_ID=your-prod-repel-role-id -MODERATORS_ROLE_IDS=your-prod-moderator-role-id-1,your-prod-moderator-role-id-2 +# Role IDs (from your dev server) +REPEL_ROLE_ID=1002411741776461844 +MODERATORS_ROLE_IDS=849481536654803004 + +# Other +GUIDES_TRACKER_PATH=/app/data/guides-tracker.json # Note: DISCORD_TOKEN & CLIENT_ID should be in .env.local (not committed) From fb0448365efc8e265f403e8fd40fed4539179321 Mon Sep 17 00:00:00 2001 From: Wiktoria Van Harneveldt Date: Tue, 4 Nov 2025 21:21:54 +0100 Subject: [PATCH 10/15] chore: update .gitignore to include .env.development.example and adjust environment variable exclusions --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index fcc9ff1..2ac2a4a 100644 --- a/.gitignore +++ b/.gitignore @@ -12,12 +12,13 @@ yarn-debug.log* yarn-error.log* # Env files +.env.development .env.local .env.*.local # Allow environment-specific configs (public, non-secret) -!.env.development !.env.production !.env.example +!.env.development.example # guides tracker guides-tracker.json \ No newline at end of file From b911e2aa30bc86077f6f1187f90284f60ed88932 Mon Sep 17 00:00:00 2001 From: Wiktoria Van Harneveldt Date: Tue, 4 Nov 2025 21:22:23 +0100 Subject: [PATCH 11/15] chore: remove .env.development file --- .env.development | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 .env.development diff --git a/.env.development b/.env.development deleted file mode 100644 index 4c369d4..0000000 --- a/.env.development +++ /dev/null @@ -1,16 +0,0 @@ -# Development Environment Configuration -# Public values - safe to commit to repository -# These are Discord IDs for your development/test server - -# Discord Server ID (your dev server) -SERVER_ID=1403539983821963274 - -# Channel IDs (from your dev server) -GUIDES_CHANNEL_ID=1426998962635804712 -REPEL_LOG_CHANNEL_ID=1403540596035027045 - -# Role IDs (from your dev server) -REPEL_ROLE_ID=1403545113904414842 -MODERATORS_ROLE_IDS=1428151937534005379 - -# Note: DISCORD_TOKEN & CLIENT_ID should be in .env.local (not committed) From 8d620fffbc70dfda5642a9a3282ba09181d8afbe Mon Sep 17 00:00:00 2001 From: Wiktoria Van Harneveldt Date: Tue, 4 Nov 2025 21:22:45 +0100 Subject: [PATCH 12/15] chore: add example development environment configuration file --- .env.development.example | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .env.development.example diff --git a/.env.development.example b/.env.development.example new file mode 100644 index 0000000..78a70d8 --- /dev/null +++ b/.env.development.example @@ -0,0 +1,19 @@ +# Development Environment Configuration +# Public values - safe to commit to repository +# These are Discord IDs for your development/test server + +# Discord Server ID (your dev server) +SERVER_ID=your-server-id + +# Channel IDs (from your dev server) +GUIDES_CHANNEL_ID=your-guide-channel-id +REPEL_LOG_CHANNEL_ID=your-repel-log-channel-id + +# Role IDs (from your dev server) +REPEL_ROLE_ID=your-repel-role-id +MODERATORS_ROLE_IDS=your-moderator-role-id + +# Other +GUIDES_TRACKER_PATH=guides-tracker.json + +# Note: DISCORD_TOKEN & CLIENT_ID should be in .env.local (not committed) From 85835e381b66cdcc3eb41bc3b606727ab0464771 Mon Sep 17 00:00:00 2001 From: Wiktoria Van Harneveldt Date: Wed, 5 Nov 2025 17:41:07 +0100 Subject: [PATCH 13/15] chore: standardize environment configuration by replacing .env.local with .env --- .github/workflows/deploy.yml | 4 ++-- DOCKER.md | 10 +++++----- Dockerfile | 4 ++-- README.md | 6 +++--- docker-compose.yml | 5 ++--- docs/GUIDE_SYNC.md | 2 +- src/env.ts | 2 +- src/loadEnvFile.ts | 14 ++++++++------ 8 files changed, 24 insertions(+), 23 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 125eb7d..a92a697 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -38,10 +38,10 @@ jobs: export NODE_VERSION=$(cat .nvmrc | sed 's/v//') echo "Using Node version: $NODE_VERSION" - # Create .env.local file with secrets only + # Create .env file with secrets # Public config comes from .env.production (committed to repo) # NODE_ENV=production is set in docker-compose.yml - cat > .env.local << EOF + cat > .env << EOF DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} CLIENT_ID=${{ secrets.CLIENT_ID }} EOF diff --git a/DOCKER.md b/DOCKER.md index d800001..2011742 100644 --- a/DOCKER.md +++ b/DOCKER.md @@ -6,7 +6,7 @@ This document explains how to run the webdev-bot using Docker. - Docker installed (version 20.10 or higher) - Docker Compose installed (version 2.0 or higher) -- `.env.local` file with required environment variables +- `.env` file with required environment variables ## Node Version Management @@ -14,7 +14,7 @@ The Docker setup uses `.nvmrc` as the single source of truth for the Node.js ver ## Environment Variables -Before running the bot, create a `.env.local` file in the project root with the following variables: +Before running the bot, create a `.env` file in the project root with the following variables: ```env DISCORD_TOKEN=your_discord_bot_token @@ -104,7 +104,7 @@ Run the production container manually (after building with the NODE_VERSION arg) ```bash docker run -d \ --name webdev-bot \ - --env-file .env.local \ + --env-file .env \ --restart unless-stopped \ webdev-bot:latest ``` @@ -114,7 +114,7 @@ Run the development container manually (after building with the NODE_VERSION arg ```bash docker run -it \ --name webdev-bot-dev \ - --env-file .env.local \ + --env-file .env \ -v $(pwd)/src:/app/src:ro \ webdev-bot:dev ``` @@ -183,7 +183,7 @@ docker compose build --no-cache ## Best Practices -1. **Never commit `.env.local`** - Keep your secrets secure +1. **Never commit `.env`** - Keep your secrets secure 2. **Use production profile for deployment** - Smaller, more secure images 3. **Keep development profile for local testing** - Faster iteration with hot reload 4. **Node version is managed in `.nvmrc`** - Update `.nvmrc` to change Node version for Docker diff --git a/Dockerfile b/Dockerfile index 799aa81..6830afc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -41,8 +41,8 @@ COPY --from=deps /app/node_modules ./node_modules COPY --from=build /app/dist ./dist COPY package.json ./ -# Copy environment config files (public, non-secret) -COPY .env.production .env.development ./ +# Copy environment config file (public, non-secret) +COPY .env.production ./ # Create data directory and set permissions for node user RUN mkdir -p /app/data && chown -R node:node /app/data diff --git a/README.md b/README.md index 7ee3074..560c23b 100644 --- a/README.md +++ b/README.md @@ -52,10 +52,10 @@ A comprehensive Discord bot designed specifically for the Web Dev Discord server pnpm install ``` -3. Create a `.env.local` file based on `.env.example` and fill in the required environment variables: +3. Create a `.env` file based on `.env.example` and fill in the required environment variables: ```bash - cp .env.example .env.local - # Edit .env.local to add your Discord bot token and other configurations + cp .env.example .env + # Edit .env to add your Discord bot token and other configurations ``` 4. Build and start the bot: diff --git a/docker-compose.yml b/docker-compose.yml index f16890f..bd5b017 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,7 +9,7 @@ services: container_name: webdev-bot-prod restart: unless-stopped env_file: - - .env.local + - .env environment: - NODE_ENV=production volumes: @@ -30,7 +30,7 @@ services: container_name: webdev-bot-dev restart: unless-stopped env_file: - - .env.local + - .env environment: - NODE_ENV=development volumes: @@ -43,7 +43,6 @@ services: - ./package.json:/app/package.json:ro - ./pnpm-lock.yaml:/app/pnpm-lock.yaml:ro # Mount environment config files - - ./.env.development:/app/.env.development:ro - ./.env.production:/app/.env.production:ro # Persist guides tracker data - guides-data:/app/data diff --git a/docs/GUIDE_SYNC.md b/docs/GUIDE_SYNC.md index f4b203e..ec873dd 100644 --- a/docs/GUIDE_SYNC.md +++ b/docs/GUIDE_SYNC.md @@ -4,7 +4,7 @@ The bot automatically synchronizes guide markdown files from `src/commands/guide ## Setup -Add to your `.env.local` file: +Add to your `.env` file: ``` GUIDES_CHANNEL_ID=1234567890123456789 ``` diff --git a/src/env.ts b/src/env.ts index cc90dea..4cd4398 100644 --- a/src/env.ts +++ b/src/env.ts @@ -8,7 +8,7 @@ function requireEnv(key: string): string { const value = process.env[key]; if (!value) { console.error(`❌ Required environment variable ${key} is not set`); - console.error('Please check your .env.local file or CI/CD configuration'); + console.error('Please check your .env file or CI/CD configuration'); process.exit(1); } return value; diff --git a/src/loadEnvFile.ts b/src/loadEnvFile.ts index 4766ffe..793ec4f 100644 --- a/src/loadEnvFile.ts +++ b/src/loadEnvFile.ts @@ -36,11 +36,13 @@ function loadEnvFile(filePath: string) { const nodeEnv = process.env.NODE_ENV || 'development'; console.log(`🌍 Environment: ${nodeEnv}`); -// Load environment-specific config first (public values) -const envFile = join(process.cwd(), `.env.${nodeEnv}`); -loadEnvFile(envFile); +// Load environment-specific config first (public values, production only) +if (nodeEnv === 'production') { + const envFile = join(process.cwd(), '.env.production'); + loadEnvFile(envFile); +} -// Load local overrides and secrets second (overrides public config) -// Required in both dev and prod for DISCORD_TOKEN -const localEnvFile = join(process.cwd(), '.env.local'); +// Load .env file with secrets and local config (overrides public config if any) +// Required for DISCORD_TOKEN and other secrets +const localEnvFile = join(process.cwd(), '.env'); loadEnvFile(localEnvFile); From 8292591e71b442803018ff79b1f49896130fa04f Mon Sep 17 00:00:00 2001 From: Wiktoria Van Harneveldt Date: Wed, 5 Nov 2025 17:44:18 +0100 Subject: [PATCH 14/15] chore: consolidate environment configuration by removing .env.development.example and updating .env.example --- .env.development.example | 19 ------------------- .env.example | 24 +++++++++++++++++------- .gitignore | 14 ++++++++------ 3 files changed, 25 insertions(+), 32 deletions(-) delete mode 100644 .env.development.example diff --git a/.env.development.example b/.env.development.example deleted file mode 100644 index 78a70d8..0000000 --- a/.env.development.example +++ /dev/null @@ -1,19 +0,0 @@ -# Development Environment Configuration -# Public values - safe to commit to repository -# These are Discord IDs for your development/test server - -# Discord Server ID (your dev server) -SERVER_ID=your-server-id - -# Channel IDs (from your dev server) -GUIDES_CHANNEL_ID=your-guide-channel-id -REPEL_LOG_CHANNEL_ID=your-repel-log-channel-id - -# Role IDs (from your dev server) -REPEL_ROLE_ID=your-repel-role-id -MODERATORS_ROLE_IDS=your-moderator-role-id - -# Other -GUIDES_TRACKER_PATH=guides-tracker.json - -# Note: DISCORD_TOKEN & CLIENT_ID should be in .env.local (not committed) diff --git a/.env.example b/.env.example index dae88eb..a5d0f74 100644 --- a/.env.example +++ b/.env.example @@ -1,14 +1,24 @@ # Local Environment Variables (Secrets) -# Copy this file to .env.local and fill in your actual values -# .env.local is gitignored and should NEVER be committed +# Copy this file to .env and fill in your actual values +# .env is gitignored and should NEVER be committed # Discord Bot Token & Application ID (REQUIRED) # Get this from: https://discord.com/developers/applications DISCORD_TOKEN=your-bot-token-here CLIENT_ID=your-bot-application-id -# Optional: Override any public config values for local testing -# Uncomment and modify as needed: -# SERVER_ID=override-server-id -# CLIENT_ID=override-client-id -# GUIDES_CHANNEL_ID=override-channel-id +# Override any public config values for local testing + +# Discord Server ID (your dev server) +SERVER_ID=your-server-id + +# Channel IDs (from your dev server) +GUIDES_CHANNEL_ID=your-guide-channel-id +REPEL_LOG_CHANNEL_ID=your-repel-log-channel-id + +# Role IDs (from your dev server) +REPEL_ROLE_ID=your-repel-role-id +MODERATORS_ROLE_IDS=your-moderator-role-id + +# Other +GUIDES_TRACKER_PATH=guides-tracker.json \ No newline at end of file diff --git a/.gitignore b/.gitignore index 2ac2a4a..67b2b83 100644 --- a/.gitignore +++ b/.gitignore @@ -12,13 +12,15 @@ yarn-debug.log* yarn-error.log* # Env files -.env.development -.env.local -.env.*.local -# Allow environment-specific configs (public, non-secret) +.env +.env.* + +# Public config (committed to repo) !.env.production !.env.example -!.env.development.example # guides tracker -guides-tracker.json \ No newline at end of file +guides-tracker.json + +# Docker +docker-compose.yml \ No newline at end of file From 0dbe7caf34633cf17ba92a1a62ccf7915cac0d09 Mon Sep 17 00:00:00 2001 From: Wiktoria Van Harneveldt Date: Wed, 5 Nov 2025 17:45:07 +0100 Subject: [PATCH 15/15] chore: clean up environment configuration by removing commented-out sections --- src/env.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/env.ts b/src/env.ts index 4cd4398..b595138 100644 --- a/src/env.ts +++ b/src/env.ts @@ -33,13 +33,6 @@ export const config = { channelId: requireEnv('GUIDES_CHANNEL_ID'), trackerPath: optionalEnv('GUIDES_TRACKER_PATH'), }, - // Add more config sections as needed: - // database: { - // url: requireEnv('DATABASE_URL'), - // }, - // api: { - // openaiKey: optionalEnv('OPENAI_API_KEY'), - // }, }; export type Config = typeof config;