- Make unified config lazy-loaded to avoid initialization issues - Replace direct config exports with getter functions - Rewrite utils/env.ts to use unified config instead of scattered access - Add show-config.js helper script for configuration management - Type-safe configuration access throughout the app - Smart defaults for all environments with environment overrides - Eliminates scattered process.env and import.meta.env access
188 lines
5.5 KiB
JavaScript
188 lines
5.5 KiB
JavaScript
#!/usr/bin/env bun
|
|
|
|
/**
|
|
* Configuration Helper Script
|
|
*
|
|
* This script shows the current unified configuration and provides
|
|
* examples of environment variables that can be set to override defaults.
|
|
*
|
|
* Usage:
|
|
* bun show-config.js # Show current config
|
|
* bun show-config.js --env # Show as environment variables
|
|
* bun show-config.js --help # Show help
|
|
*/
|
|
|
|
/* eslint-disable no-console */
|
|
|
|
import { unifiedConfig, exportAsEnvVars } from './config/unified.config';
|
|
|
|
const args = process.argv.slice(2);
|
|
const showEnv = args.includes('--env');
|
|
const showHelp = args.includes('--help');
|
|
|
|
if (showHelp) {
|
|
console.log(`
|
|
Configuration Helper - Single Source of Truth
|
|
|
|
USAGE:
|
|
bun show-config.js Show current unified config
|
|
bun show-config.js --env Show as environment variables
|
|
bun show-config.js --help Show this help
|
|
|
|
DESCRIPTION:
|
|
This app uses a unified configuration system as the single source of truth.
|
|
All settings come from config/unified.config.ts with environment overrides.
|
|
|
|
COMMON ENVIRONMENT OVERRIDES:
|
|
# Application
|
|
NODE_ENV=production
|
|
APP_NAME="My Custom App Name"
|
|
APP_BASE_URL=https://myapp.com
|
|
|
|
# Database (required for production)
|
|
VITE_COUCHDB_URL=http://localhost:5984
|
|
VITE_COUCHDB_USER=admin
|
|
VITE_COUCHDB_PASSWORD=secure-password
|
|
|
|
# Authentication (required for production)
|
|
JWT_SECRET=your-secure-jwt-secret
|
|
SESSION_SECRET=your-secure-session-secret
|
|
|
|
# Email (optional)
|
|
VITE_MAILGUN_API_KEY=key-abc123
|
|
VITE_MAILGUN_DOMAIN=mg.example.com
|
|
|
|
# OAuth (optional)
|
|
VITE_GOOGLE_CLIENT_ID=your-google-client-id
|
|
VITE_GITHUB_CLIENT_ID=your-github-client-id
|
|
|
|
HOW IT WORKS:
|
|
1. Unified config provides smart defaults for all environments
|
|
2. Environment variables override specific settings when needed
|
|
3. No more scattered .env files or hardcoded values
|
|
4. Type-safe configuration throughout the app
|
|
|
|
EXAMPLES:
|
|
# Development with custom database
|
|
VITE_COUCHDB_URL=http://dev-db:5984 bun run dev
|
|
|
|
# Production build with custom settings
|
|
NODE_ENV=production APP_NAME="Prod App" make docker-build
|
|
|
|
# Check current config
|
|
bun show-config.js
|
|
`);
|
|
process.exit(0);
|
|
}
|
|
|
|
console.log('🔧 Unified Configuration - Single Source of Truth\n');
|
|
|
|
if (showEnv) {
|
|
console.log('📋 Current Configuration as Environment Variables:\n');
|
|
const envVars = exportAsEnvVars();
|
|
|
|
// Group by category for better readability
|
|
const categories = {
|
|
Application: [
|
|
'APP_NAME',
|
|
'APP_VERSION',
|
|
'APP_BASE_URL',
|
|
'NODE_ENV',
|
|
'PORT',
|
|
],
|
|
Database: [
|
|
'VITE_COUCHDB_URL',
|
|
'VITE_COUCHDB_USER',
|
|
'VITE_COUCHDB_PASSWORD',
|
|
'COUCHDB_DATABASE_NAME',
|
|
],
|
|
Authentication: ['JWT_SECRET', 'JWT_EXPIRES_IN', 'SESSION_SECRET'],
|
|
Email: [
|
|
'EMAIL_PROVIDER',
|
|
'VITE_MAILGUN_API_KEY',
|
|
'VITE_MAILGUN_DOMAIN',
|
|
'MAILGUN_FROM_NAME',
|
|
'MAILGUN_FROM_EMAIL',
|
|
],
|
|
OAuth: [
|
|
'VITE_GOOGLE_CLIENT_ID',
|
|
'GOOGLE_CLIENT_SECRET',
|
|
'VITE_GITHUB_CLIENT_ID',
|
|
'GITHUB_CLIENT_SECRET',
|
|
],
|
|
Features: ['ENABLE_EMAIL_VERIFICATION', 'ENABLE_OAUTH', 'DEBUG_MODE'],
|
|
Logging: ['LOG_LEVEL', 'LOG_FORMAT'],
|
|
};
|
|
|
|
Object.entries(categories).forEach(([category, keys]) => {
|
|
console.log(`${category}:`);
|
|
keys.forEach(key => {
|
|
if (envVars[key] !== undefined) {
|
|
const value = envVars[key];
|
|
// Mask sensitive values
|
|
const maskedValue =
|
|
key.includes('SECRET') ||
|
|
key.includes('PASSWORD') ||
|
|
key.includes('API_KEY')
|
|
? '***masked***'
|
|
: value;
|
|
console.log(` ${key}=${maskedValue}`);
|
|
}
|
|
});
|
|
console.log('');
|
|
});
|
|
} else {
|
|
console.log('📊 Current Unified Configuration:\n');
|
|
|
|
// Show key configuration sections
|
|
console.log('Application:');
|
|
console.log(` Name: ${unifiedConfig.app.name}`);
|
|
console.log(` Environment: ${unifiedConfig.app.environment}`);
|
|
console.log(` Base URL: ${unifiedConfig.app.baseUrl}`);
|
|
console.log(` Port: ${unifiedConfig.app.port}`);
|
|
console.log('');
|
|
|
|
console.log('Database:');
|
|
console.log(` URL: ${unifiedConfig.database.url}`);
|
|
console.log(` Username: ${unifiedConfig.database.username}`);
|
|
console.log(
|
|
` Password: ${unifiedConfig.database.password ? '***set***' : '***not set***'}`
|
|
);
|
|
console.log(` Mock Mode: ${unifiedConfig.database.useMock}`);
|
|
console.log('');
|
|
|
|
console.log('Authentication:');
|
|
console.log(
|
|
` JWT Secret: ${unifiedConfig.auth.jwtSecret ? '***set***' : '***not set***'}`
|
|
);
|
|
console.log(` JWT Expires: ${unifiedConfig.auth.jwtExpiresIn}`);
|
|
console.log('');
|
|
|
|
console.log('Features:');
|
|
console.log(
|
|
` Email Verification: ${unifiedConfig.features.enableEmailVerification}`
|
|
);
|
|
console.log(` OAuth: ${unifiedConfig.features.enableOAuth}`);
|
|
console.log(` Debug Mode: ${unifiedConfig.features.debugMode}`);
|
|
console.log('');
|
|
|
|
console.log('Email:');
|
|
console.log(` Provider: ${unifiedConfig.email.provider}`);
|
|
console.log(
|
|
` From: ${unifiedConfig.email.fromName} <${unifiedConfig.email.fromEmail}>`
|
|
);
|
|
console.log('');
|
|
|
|
console.log('Logging:');
|
|
console.log(` Level: ${unifiedConfig.logging.level}`);
|
|
console.log(` Format: ${unifiedConfig.logging.format}`);
|
|
console.log('');
|
|
}
|
|
|
|
console.log('💡 Tips:');
|
|
console.log(' • Use --env to see current config as environment variables');
|
|
console.log(' • Use --help to see configuration documentation');
|
|
console.log(' • Set environment variables to override defaults');
|
|
console.log(' • All configuration comes from config/unified.config.ts');
|
|
console.log('');
|