Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Local Environment Variables (Secrets)
# 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

# 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
7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ jobs:
- name: Lint
run: npm run lint

- name: Build and test
run: npm run test:build
- name: Build
run: npm run build:ci

- name: Test
run: npm run test:ci

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ yarn-error.log*
# Public config (committed to repo)
!.env.production
!.env.example
!.env.test

# guides tracker
guides-tracker.json
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"build:ci": "npm run build:ts && npm run build:copy",
"build:dev": "pnpm run build:ts && pnpm run build:copy",
"build:ts": "tsup",
"build:test": "tsup --entry 'src/**/*.ts' --entry 'test/**/*.ts'",
"build:copy": "node scripts/copy-assets.js",
"start": "node dist/index.js",
"dev": "tsx watch src/index.ts",
Expand All @@ -23,8 +22,7 @@
"check:fix": "biome check --write .",
"typecheck": "tsc --noEmit",
"test": "pnpm run build:dev && node --test dist/**/*.test.js",
"test:ci": "node --test $(find dist -name '*.test.js')",
"test:build": "npm run build:test && npm run test:ci",
"test:ci": "NODE_ENV=test node --test dist/**/*.test.js",
"prepare": "husky",
"pre-commit": "lint-staged",
"sync-guides": "tsx scripts/sync-guides.js",
Expand Down
19 changes: 11 additions & 8 deletions src/loadEnvFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ function loadEnvFile(filePath: string) {
const nodeEnv = process.env.NODE_ENV || 'development';
console.log(`🌍 Environment: ${nodeEnv}`);

// Load environment-specific config first (public values, production only)
if (nodeEnv === 'production') {
const envFile = join(process.cwd(), '.env.production');
const ENV_FILES = {
test: join(process.cwd(), '.env.test'),
production: join(process.cwd(), '.env.production'),
development: join(process.cwd(), '.env'),
};

const envFile = ENV_FILES[nodeEnv as keyof typeof ENV_FILES];
if (envFile) {
loadEnvFile(envFile);
} else {
console.error(`❌ Environment file ${nodeEnv} not found`);
process.exit(1);
}

// 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);
File renamed without changes.