diff --git a/BUILDING.md b/BUILDING.md index fd25df7d..e65e74ab 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -2,6 +2,130 @@ This guide explains how to build TimeSafari for different platforms using the comprehensive build system. +## ๐Ÿš€ Quick Start for Developers + +### Most Common Commands + +```bash +# ๐Ÿ–ฅ๏ธ Web Development +npm run build:web:dev # Start development server with hot reload +npm run build:web:prod # Production build + +# ๐Ÿ“ฑ Mobile Development +npm run build:ios # iOS build (opens Xcode) +npm run build:android # Android build (opens Android Studio) + +# ๐Ÿ–ฅ๏ธ Desktop Development +npm run build:electron:dev # Electron development (runs app) + +# ๐Ÿงช Testing +npm run test:web # Web tests +npm run test:mobile # Mobile tests + +# ๐Ÿงน Cleaning +npm run clean:all # Clean all platforms +``` + +### Development Workflow + +#### 1. First-Time Setup +```bash +# Install dependencies +npm install + +# Verify environment +npm run test:web # Run web tests to verify setup +``` + +#### 2. Daily Development +```bash +# Start web development server +npm run build:web:dev # Opens http://localhost:8080 + +# For mobile development +npm run build:ios # Opens Xcode with iOS project +npm run build:android # Opens Android Studio with Android project + +# For desktop development +npm run build:electron:dev # Runs Electron app directly +``` + +#### 3. Testing Your Changes +```bash +# Test web functionality +npm run test:web # Run web tests + +# Test mobile functionality +npm run test:mobile # Run mobile tests + +# Test on actual devices +npm run build:ios:test:run # Build and run on iOS simulator +npm run build:android:test:run # Build and run on Android emulator +``` + +#### 4. Production Builds +```bash +# Build for production +npm run build:web:prod # Web production build +npm run build:ios:prod # iOS production build +npm run build:android:prod # Android production build +npm run build:electron:prod # Electron production build +``` + +### Environment Configuration + +#### Quick Environment Setup +```bash +# Copy environment template (if available) +cp .env.example .env.development + +# Edit environment variables for your setup +# Key variables to configure: +# - VITE_DEFAULT_ENDORSER_API_SERVER +# - VITE_DEFAULT_PARTNER_API_SERVER +# - VITE_DEFAULT_IMAGE_API_SERVER +``` + +#### Platform-Specific Development +- **Web**: Uses `localhost:3000` for APIs by default +- **iOS Simulator**: Uses `localhost:3000` for APIs +- **Android Emulator**: Uses `10.0.2.2:3000` for APIs +- **Physical Devices**: Use your computer's IP address (e.g., `192.168.1.100:3000`) + +### Troubleshooting Quick Fixes + +#### Common Issues +```bash +# Clean and rebuild +npm run clean:all +npm install +npm run build:web:dev + +# Reset mobile projects +npm run clean:ios +npm run clean:android +npm run build:ios # Regenerates iOS project +npm run build:android # Regenerates Android project + +# Check environment +npm run test:web # Verifies web setup +``` + +#### Platform-Specific Issues +- **iOS**: Ensure Xcode and Command Line Tools are installed +- **Android**: Ensure Android Studio and SDK are configured +- **Electron**: Ensure platform-specific build tools are installed + +### Next Steps + +1. **Read the full documentation** below for detailed information +2. **Check prerequisites** for your target platforms +3. **Configure environment variables** for your development setup +4. **Run tests** to verify your environment +5. **Start developing** with the commands above + +--- + ## Prerequisites - Node.js 18+ and npm @@ -30,45 +154,35 @@ npm install ## Web Development -### Local Development +### Web Development Commands ```bash -npm run dev -``` +# Local development +npm run build:web:dev # Start development server with hot reload -### Web Build for Server - -1. Run the production build: +# Web builds +npm run build:web # Development build (starts dev server with hot reload) +npm run build:web:test # Test environment build (optimized for testing) +npm run build:web:prod # Production build (optimized for production) +npm run build:web:serve # Build and serve locally (builds then serves) -```bash -rm -rf dist -npm run build:web +# Docker builds +npm run build:web:docker # Development build with Docker containerization +npm run build:web:docker:test # Test build with Docker containerization +npm run build:web:docker:prod # Production build with Docker containerization ``` -The built files will be in the `dist` directory. - -2. To test the production build locally: +### Local Development -You'll likely want to use test locations for the Endorser & image & partner servers; see "DEFAULT_ENDORSER_API_SERVER" & "DEFAULT_IMAGE_API_SERVER" & "DEFAULT_PARTNER_API_SERVER" below. +Start the development server using `npm run build:web:dev` or `npm run build:web` (both start the development server with hot reload). -```bash -npm run serve -``` - -### Web Build Commands +### Web Build for Server -```bash -# Development builds -npm run build:web:dev # Development build with hot reload -npm run build:web:test # Test environment build -npm run build:web:prod # Production build -npm run build:web:serve # Production build with serve +1. Run the production build using `npm run build:web:prod` +2. The built files will be in the `dist` directory +3. To test the production build locally, use `npm run build:web:serve` (builds then serves) -# Docker builds -npm run build:web:docker # Docker development build -npm run build:web:docker:test # Docker test build -npm run build:web:docker:prod # Docker production build -``` +You'll likely want to use test locations for the Endorser & image & partner servers; see "DEFAULT_ENDORSER_API_SERVER" & "DEFAULT_IMAGE_API_SERVER" & "DEFAULT_PARTNER_API_SERVER" below. ### Web Build Script Details @@ -127,7 +241,7 @@ All web build commands use the `./scripts/build-web.sh` script, which provides: * Update the ClickUp tasks & CHANGELOG.md & the version in package.json, run `npm install`. -* Run a build to make sure package-lock version is updated, linting works, etc: `npm install && npm run build` +* Run a build to make sure package-lock version is updated, linting works, etc: `npm install && npm run build:web` * Commit everything (since the commit hash is used the app). @@ -164,9 +278,9 @@ rsync -azvu -e "ssh -i ~/.ssh/..." dist ubuntutest@test.timesafari.app:time-safa * `pkgx +npm sh` -* `cd crowd-funder-for-time-pwa && git checkout master && git pull && git checkout 1.0.2 && npm install && npm run build:web && cd -` +* `cd crowd-funder-for-time-pwa && git checkout master && git pull && git checkout 1.0.2 && npm install && npm run build:web:prod && cd -` -(The plain `npm run build:web` uses the .env.production file.) +(The plain `npm run build:web:prod` uses the .env.production file.) * Back up the time-safari/dist folder & deploy: `mv time-safari/dist time-safari-dist-prev-2 && mv crowd-funder-for-time-pwa/dist time-safari/` @@ -181,6 +295,17 @@ The application can be containerized using Docker for consistent deployment acro - Docker installed on your system - Docker Compose (optional, for multi-container setups) +### Docker Commands + +```bash +# Docker operations +npm run docker:up # Start Docker services +npm run docker:up:test # Start test environment +npm run docker:up:prod # Start production environment +npm run docker:down # Stop Docker services +npm run docker:logs # View logs +``` + ### Building the Docker Image 1. Build the Docker image: @@ -231,17 +356,6 @@ Run with Docker Compose: docker-compose up -d ``` -### Docker Commands - -```bash -# Docker operations -npm run docker:up # Start Docker services -npm run docker:up:test # Start test environment -npm run docker:up:prod # Start production environment -npm run docker:down # Stop Docker services -npm run docker:logs # View logs -``` - ### Production Deployment For production deployment, consider the following: @@ -288,42 +402,47 @@ docker run -d \ TimeSafari's Electron build system provides comprehensive desktop application packaging and distribution capabilities across Windows, macOS, and Linux platforms. The system supports multiple build modes, environment configurations, and package formats. -### Quick Start - -#### Development Build +### Electron Build Commands ```bash -# Start development build (runs app) -npm run build:electron:dev +# Development builds +npm run build:electron:dev # Development build (builds and runs app) +npm run build:electron:dev:run # Development build with auto-run (builds and runs app) -# Development build only -npm run build:electron --dev +# Production builds +npm run build:electron:prod # Production build for all platforms +npm run build:electron:prod:run # Production build with auto-run (builds and runs app) +npm run build:electron:windows:prod # Windows production build +npm run build:electron:mac:prod # macOS production build +npm run build:electron:linux:prod # Linux production build + +# Package-specific builds +npm run build:electron:appimage:prod # AppImage for Linux +npm run build:electron:deb:prod # DEB package for Debian/Ubuntu +npm run build:electron:dmg:prod # DMG for macOS + +# Platform-specific builds +npm run build:electron:windows # Windows build (production) +npm run build:electron:mac # macOS build (production) +npm run build:electron:linux # Linux build (production) + +# Additional operations +npm run clean:electron # Clean Electron build artifacts ``` -#### Production Build +### Quick Start -```bash -# Production build for all platforms -npm run build:electron:prod +#### Development Build -# Platform-specific production builds -npm run build:electron:windows:prod -npm run build:electron:mac:prod -npm run build:electron:linux:prod -``` +Start development build using `npm run build:electron:dev` (builds and runs the app directly). -#### Package-Specific Builds +#### Production Build -```bash -# AppImage for Linux -npm run build:electron:appimage:prod +Run production builds using the commands above. Production builds create platform-specific packages. -# DEB package for Debian/Ubuntu -npm run build:electron:deb:prod +#### Package-Specific Builds -# DMG for macOS -npm run build:electron:dmg:prod -``` +Create platform-specific packages using the commands above. These build the app and create installable packages. ### Single Instance Enforcement @@ -350,13 +469,13 @@ The Electron app enforces single-instance operation to prevent: ```bash # Direct script usage (no npm chaining) -./scripts/build-electron.sh --dev # Development build -./scripts/build-electron.sh --test # Test build -./scripts/build-electron.sh --prod # Production build -./scripts/build-electron.sh --prod --windows # Windows production -./scripts/build-electron.sh --test --appimage # Linux AppImage test -./scripts/build-electron.sh --dev --mac # macOS development -./scripts/build-electron.sh --prod --dmg # macOS DMG production +./scripts/build-electron.sh --dev # Development build (builds and runs app) +./scripts/build-electron.sh --test # Test build (builds packages) +./scripts/build-electron.sh --prod # Production build (builds packages) +./scripts/build-electron.sh --prod --windows # Windows production build +./scripts/build-electron.sh --test --appimage # Linux AppImage test build +./scripts/build-electron.sh --dev --mac # macOS development build +./scripts/build-electron.sh --prod --dmg # macOS DMG production build ``` ### Build Architecture @@ -407,7 +526,7 @@ The Electron build process follows a multi-stage approach: #### Testing Mode **Purpose**: Staging and testing environments -**Command**: `npm run build:electron -- --mode test` +**Command**: `npm run build:electron:test` **Features**: - Test API endpoints @@ -418,7 +537,7 @@ The Electron build process follows a multi-stage approach: #### Production Mode **Purpose**: Production deployment -**Command**: `npm run build:electron -- --mode production` +**Command**: `npm run build:electron:prod` **Features**: - Production optimizations @@ -569,7 +688,6 @@ npm run build:electron:dmg:prod ```bash # Development builds npm run build:electron:dev # Development build and run -npm run build:electron --dev # Development build only # Testing builds npm run build:electron:test # Test environment build @@ -642,11 +760,6 @@ All npm scripts use the underlying `./scripts/build-electron.sh` script: ```bash # Cleanup scripts npm run clean:electron # Clean Electron build artifacts - -# Development scripts -npm run electron:dev # Start development server -npm run electron:dev-full # Full development workflow -npm run electron:setup # Setup Electron environment ``` ### Build Output Structure @@ -751,13 +864,13 @@ Note: If you get a security warning when running the app: ```bash # Clean and rebuild npm run clean:electron -cd electron && npm run build +npm run build:electron:dev ``` **Native Module Issues**: ```bash # Rebuild native modules -cd electron && npm run build +npm run build:electron:dev ``` **Asset Copy Issues**: @@ -822,6 +935,34 @@ For detailed documentation, see [docs/electron-build-patterns.md](docs/electron- Prerequisites: macOS with Xcode installed +#### iOS Build Commands + +```bash +# Standard builds +npm run build:ios # Development build (builds and opens Xcode) +npm run build:ios:dev # Development build (builds and opens Xcode) +npm run build:ios:test # Test build (builds for testing environment) +npm run build:ios:prod # Production build (builds for production environment) + +# Auto-run builds +npm run build:ios:test:run # Test build with auto-run (builds then runs on simulator) +npm run build:ios:prod:run # Production build with auto-run (builds then runs on simulator) + +# Debug and release builds +npm run build:ios:debug # Debug build (builds debug app bundle) +npm run build:ios:debug:run # Debug build with auto-run (builds then runs on simulator) +npm run build:ios:release # Release build (builds release app bundle) +npm run build:ios:release:run # Release build with auto-run (builds then runs on device) + +# Additional operations +npm run build:ios:studio # Build and open in Xcode Studio +npm run build:ios:ipa # Build and generate IPA file +npm run build:ios:clean # Clean build artifacts only +npm run build:ios:sync # Sync Capacitor only +npm run build:ios:assets # Generate assets only +npm run build:ios:deploy # Build and deploy to connected device +``` + #### Automated Build Script The recommended way to build for iOS is using the automated build script: @@ -842,39 +983,13 @@ The recommended way to build for iOS is using the automated build script: The script handles all the necessary steps including: - Environment setup and validation -- Web asset building +- Web asset building (Capacitor mode) - Capacitor synchronization - iOS asset generation -- Version number updates -- Xcode project opening - -#### iOS Build Commands - -```bash -# Standard builds -npm run build:ios # Standard build and open Xcode -npm run build:ios:dev # Development build -npm run build:ios:test # Test build -npm run build:ios:prod # Production build - -# Auto-run builds -npm run build:ios:test:run # Test build with auto-run -npm run build:ios:prod:run # Production build with auto-run - -# Debug and release builds -npm run build:ios:debug # Debug build -npm run build:ios:debug:run # Debug build with auto-run -npm run build:ios:release # Release build -npm run build:ios:release:run # Release build with auto-run - -# Additional operations -npm run build:ios:studio # Open in Xcode Studio -npm run build:ios:ipa # Generate IPA file -npm run build:ios:clean # Clean build artifacts -npm run build:ios:sync # Sync Capacitor -npm run build:ios:assets # Generate assets -npm run build:ios:deploy # Deploy to device/simulator -``` +- iOS app building (debug/release) +- Xcode project opening (optional) +- Auto-run on simulator (optional) +- Device deployment (optional) #### Manual Build Process @@ -958,6 +1073,35 @@ If you need to build manually or want to understand the individual steps: Prerequisites: Android Studio with Java SDK installed +#### Android Build Commands + +```bash +# Standard builds +npm run build:android # Development build (builds and opens Android Studio) +npm run build:android:dev # Development build (builds and opens Android Studio) +npm run build:android:test # Test build (builds for testing environment) +npm run build:android:prod # Production build (builds for production environment) + +# Auto-run builds +npm run build:android:test:run # Test build with auto-run (builds then runs on emulator) +npm run build:android:prod:run # Production build with auto-run (builds then runs on emulator) + +# Debug and release builds +npm run build:android:debug # Debug build (builds debug APK) +npm run build:android:debug:run # Debug build with auto-run (builds then runs on emulator) +npm run build:android:release # Release build (builds release APK) +npm run build:android:release:run # Release build with auto-run (builds then runs on device) + +# Additional operations +npm run build:android:studio # Build and open in Android Studio +npm run build:android:apk # Build and generate APK file +npm run build:android:aab # Build and generate AAB (Android App Bundle) +npm run build:android:clean # Clean build artifacts only +npm run build:android:sync # Sync Capacitor only +npm run build:android:assets # Generate assets only +npm run build:android:deploy # Build and deploy to connected device +``` + #### Automated Build Script The recommended way to build for Android is using the automated build script: @@ -976,35 +1120,6 @@ The recommended way to build for Android is using the automated build script: ./scripts/build-android.sh --help ``` -#### Android Build Commands - -```bash -# Standard builds -npm run build:android # Standard build and open Android Studio -npm run build:android:dev # Development build -npm run build:android:test # Test build -npm run build:android:prod # Production build - -# Auto-run builds -npm run build:android:test:run # Test build with auto-run -npm run build:android:prod:run # Production build with auto-run - -# Debug and release builds -npm run build:android:debug # Debug build -npm run build:android:debug:run # Debug build with auto-run -npm run build:android:release # Release build -npm run build:android:release:run # Release build with auto-run - -# Additional operations -npm run build:android:studio # Open in Android Studio -npm run build:android:apk # Generate APK -npm run build:android:aab # Generate AAB (App Bundle) -npm run build:android:clean # Clean build artifacts -npm run build:android:sync # Sync Capacitor -npm run build:android:assets # Generate assets -npm run build:android:deploy # Deploy to device/emulator -``` - #### Manual Build Process 1. Build the web assets: @@ -1088,42 +1203,40 @@ npm run build:capacitor:sync ## Testing -### Web Testing +### Testing Commands ```bash -# Run web tests -npm run test:web +# Web testing +npm run test:web # Run web tests + +# Mobile testing +npm run test:mobile # Run mobile tests +npm run test:android # Android tests +npm run test:ios # iOS tests + +# Device checks +npm run check:android-device # Check Android device connection +npm run check:ios-device # Check iOS device/simulator + +# Test prerequisites +npm run test:prerequisites # Test prerequisites ``` -### Mobile Testing +### Web Testing -```bash -# Run mobile tests -npm run test:mobile +Run web tests using the command above. -# Android tests -npm run test:android +### Mobile Testing -# iOS tests -npm run test:ios -``` +Run mobile tests using the commands above. ### Device Checks -```bash -# Check Android device connection -npm run check:android-device - -# Check iOS device/simulator -npm run check:ios-device -``` +Check device connections using the commands above. ### Test Prerequisites -```bash -# Test prerequisites -npm run test:prerequisites -``` +Set up test prerequisites using the command above. ## Auto-Run System @@ -1147,48 +1260,32 @@ npm run auto-run:electron ## Cleaning -```bash -# Clean Android -npm run clean:android - -# Clean iOS -npm run clean:ios +### Cleaning Commands -# Clean Electron -npm run clean:electron +```bash +# Clean platform-specific build artifacts +npm run clean:android # Clean Android +npm run clean:ios # Clean iOS +npm run clean:electron # Clean Electron ``` -## Fastlane Integration +### Platform Cleaning -### iOS Fastlane +Use the commands above to clean build artifacts for each platform. -```bash -# Beta release -npm run fastlane:ios:beta - -# App Store release -npm run fastlane:ios:release -``` +## Code Quality -### Android Fastlane +### Code Quality Commands ```bash -# Beta release -npm run fastlane:android:beta - -# Play Store release -npm run fastlane:android:release +# Linting and code quality +npm run lint # Lint code +npm run lint-fix # Fix linting issues ``` -## Code Quality - -```bash -# Lint code -npm run lint +### Code Quality Tools -# Fix linting issues -npm run lint-fix -``` +Use the commands above to check and fix code quality issues. ## Build Architecture @@ -1219,17 +1316,43 @@ npm run lint-fix ### Environment Files -- `.env.development` - Development environment -- `.env.test` - Testing environment -- `.env.production` - Production environment +The build system supports multiple environment file patterns for different scenarios: + +#### Primary Environment Files +- `.env.development` - Development environment (local development) +- `.env.test` - Testing environment (staging/testing) +- `.env.production` - Production environment (production deployment) + +#### Fallback and Local Files +- `.env` - General fallback environment file (loaded if mode-specific file doesn't exist) +- `.env.local` - Local development overrides (gitignored) +- `.env.*.local` - Mode-specific local overrides (gitignored) + +### Environment Variable Precedence (Highest to Lowest) + +1. **Shell Script Overrides** (Highest Priority) + - Platform-specific overrides in build scripts + - Android: `http://10.0.2.2:3000` (emulator) or custom IP (physical device) + - iOS: `http://localhost:3000` (simulator) or custom IP (physical device) + +2. **Environment-Specific .env Files** (High Priority) + - `.env.development`, `.env.test`, `.env.production` + - Loaded based on build mode + +3. **Fallback .env File** (Medium Priority) + - General `.env` file (if mode-specific file doesn't exist) + +4. **Hardcoded Constants** (Lowest Priority) + - Default values in `src/constants/app.ts` ### Key Environment Variables +#### API Server Configuration ```bash -# API Servers +# API Servers (Environment-specific) VITE_DEFAULT_ENDORSER_API_SERVER=https://api.endorser.ch -VITE_DEFAULT_IMAGE_API_SERVER=https://image-api.timesafari.app VITE_DEFAULT_PARTNER_API_SERVER=https://partner-api.endorser.ch +VITE_DEFAULT_IMAGE_API_SERVER=https://image-api.timesafari.app # Platform Configuration VITE_PLATFORM=web|electron|capacitor @@ -1237,8 +1360,90 @@ VITE_APP_SERVER=https://timesafari.app # Feature Flags VITE_PASSKEYS_ENABLED=true +VITE_BVC_MEETUPS_PROJECT_CLAIM_ID=https://endorser.ch/entity/01HWE8FWHQ1YGP7GFZYYPS272F ``` +#### Environment-Specific Configurations + +**Development Environment** (`.env.development`): +```bash +# Development API Servers (Local) +VITE_DEFAULT_ENDORSER_API_SERVER=http://localhost:3000 +VITE_DEFAULT_PARTNER_API_SERVER=http://localhost:3000 +VITE_DEFAULT_IMAGE_API_SERVER=https://test-image-api.timesafari.app +VITE_APP_SERVER=http://localhost:8080 +``` + +**Test Environment** (`.env.test`): +```bash +# Test API Servers +VITE_DEFAULT_ENDORSER_API_SERVER=https://test-api.endorser.ch +VITE_DEFAULT_PARTNER_API_SERVER=https://test-partner-api.endorser.ch +VITE_DEFAULT_IMAGE_API_SERVER=https://test-image-api.timesafari.app +VITE_APP_SERVER=https://test.timesafari.app +``` + +**Production Environment** (`.env.production`): +```bash +# Production API Servers +VITE_DEFAULT_ENDORSER_API_SERVER=https://api.endorser.ch +VITE_DEFAULT_PARTNER_API_SERVER=https://partner-api.endorser.ch +VITE_DEFAULT_IMAGE_API_SERVER=https://image-api.timesafari.app +VITE_APP_SERVER=https://timesafari.app +``` + +### Platform-Specific Overrides + +#### Android Development +- **Emulator**: Uses `http://10.0.2.2:3000` (Android emulator default) +- **Physical Device**: Uses custom IP address (e.g., `http://192.168.1.100:3000`) + +#### iOS Development +- **Simulator**: Uses `http://localhost:3000` (iOS simulator default) +- **Physical Device**: Uses custom IP address (e.g., `http://192.168.1.100:3000`) + +### Environment Loading Process + +1. **Build Script Initialization** + ```bash + # scripts/common.sh - setup_build_env() + if [ "$BUILD_MODE" = "development" ]; then + export VITE_DEFAULT_ENDORSER_API_SERVER="http://localhost:3000" + export VITE_DEFAULT_PARTNER_API_SERVER="http://localhost:3000" + fi + ``` + +2. **Platform-Specific Overrides** + ```bash + # scripts/build-android.sh + if [ "$BUILD_MODE" = "development" ]; then + export VITE_DEFAULT_ENDORSER_API_SERVER="http://10.0.2.2:3000" + export VITE_DEFAULT_PARTNER_API_SERVER="http://10.0.2.2:3000" + fi + ``` + +3. **Environment File Loading** + ```bash + # scripts/build-web.sh + local env_file=".env.$BUILD_MODE" # .env.development, .env.test, .env.production + if [ -f "$env_file" ]; then + load_env_file "$env_file" + fi + + # Fallback to .env + if [ -f ".env" ]; then + load_env_file ".env" + fi + ``` + +4. **Application Usage** + ```typescript + // src/constants/app.ts + export const DEFAULT_ENDORSER_API_SERVER = + import.meta.env.VITE_DEFAULT_ENDORSER_API_SERVER || + AppString.PROD_ENDORSER_API_SERVER; + ``` + ## Troubleshooting ### Common Issues @@ -1255,7 +1460,7 @@ npm run build:electron:dev ```bash # Rebuild native modules -cd electron && npm run build +npm run build:electron:dev ``` #### Asset Issues @@ -1391,16 +1596,27 @@ pwaConfig: { #### Environment Configuration **Environment Files:** -- `.env.development` - Development environment -- `.env.test` - Testing environment -- `.env.production` - Production environment +The build system supports multiple environment file patterns: + +- `.env.development` - Development environment (local development) +- `.env.test` - Testing environment (staging/testing) +- `.env.production` - Production environment (production deployment) +- `.env` - General fallback environment file (loaded if mode-specific file doesn't exist) +- `.env.local` - Local development overrides (gitignored) +- `.env.*.local` - Mode-specific local overrides (gitignored) + +**Environment Variable Precedence (Highest to Lowest):** +1. **Shell Script Overrides** - Platform-specific overrides in build scripts +2. **Environment-Specific .env Files** - `.env.development`, `.env.test`, `.env.production` +3. **Fallback .env File** - General `.env` file (if mode-specific file doesn't exist) +4. **Hardcoded Constants** - Default values in `src/constants/app.ts` **Key Environment Variables:** ```bash -# API Servers +# API Servers (Environment-specific) VITE_DEFAULT_ENDORSER_API_SERVER=https://api.endorser.ch -VITE_DEFAULT_IMAGE_API_SERVER=https://image-api.timesafari.app VITE_DEFAULT_PARTNER_API_SERVER=https://partner-api.endorser.ch +VITE_DEFAULT_IMAGE_API_SERVER=https://image-api.timesafari.app # Platform Configuration VITE_PLATFORM=web|electron|capacitor @@ -1408,8 +1624,13 @@ VITE_APP_SERVER=https://timesafari.app # Feature Flags VITE_PASSKEYS_ENABLED=true +VITE_BVC_MEETUPS_PROJECT_CLAIM_ID=https://endorser.ch/entity/01HWE8FWHQ1YGP7GFZYYPS272F ``` +**Platform-Specific Overrides:** +- **Android Development**: `http://10.0.2.2:3000` (emulator) or custom IP (physical device) +- **iOS Development**: `http://localhost:3000` (simulator) or custom IP (physical device) + #### Build Output Structure **Web Build:** @@ -1720,9 +1941,71 @@ setup_app_directories # Setup application directories print_header "title" # Print formatted header ``` +### A.6 Cleaning Commands + +**File**: `package.json` scripts +**Author**: Matthew Raymer +**Description**: Platform-specific and comprehensive cleaning commands + +**Purpose**: Provides commands to clean build artifacts for individual platforms or all platforms at once. + +**Available Commands**: +```bash +# Platform-specific cleaning +npm run clean:ios # Clean iOS build artifacts +npm run clean:android # Clean Android build artifacts +npm run clean:electron # Clean Electron build artifacts + +# Comprehensive cleaning +npm run clean:all # Clean all platforms (iOS, Android, Electron) + +# Build-specific cleaning (via scripts) +npm run build:ios:clean # Clean iOS build artifacts (via build script) +npm run build:android:clean # Clean Android build artifacts (via build script) +npm run build:electron:clean # Clean Electron build artifacts (via build script) +``` + +**Command Details**: + +**clean:ios**: +- Removes iOS build directories (`ios/App/build`, `ios/App/Pods`, etc.) +- Cleans DerivedData and Capacitor artifacts +- Safe to run multiple times + +**clean:android**: +- Uninstalls app from connected devices +- Cleans Android build artifacts +- Safe to run multiple times + +**clean:electron**: +- Cleans Electron build artifacts (`electron/build`, `electron/dist`, `electron/app`) +- Removes TypeScript compilation artifacts +- Safe to run multiple times + +**clean:all**: +- Executes all platform-specific clean commands in sequence +- Stops on first failure (uses `&&` operator) +- Most convenient for complete cleanup + +**Usage Examples**: +```bash +# Clean everything before a fresh build +npm run clean:all + +# Clean specific platform +npm run clean:ios # iOS only +npm run clean:android # Android only +npm run clean:electron # Electron only + +# Clean and rebuild +npm run clean:all +npm install +npm run build:web:dev +``` + ## Appendix B: Vite Configuration Files Reference -This appendix provides detailed documentation for all Vite configuration files. +This appendix provides detailed documentation for all Vite configuration files used in the TimeSafari build system. ### B.1 vite.config.common.mts @@ -1730,12 +2013,12 @@ This appendix provides detailed documentation for all Vite configuration files. **Author**: Matthew Raymer **Description**: Common Vite configuration shared across all platforms -**Purpose**: Provides base configuration that is extended by platform-specific configs. +**Purpose**: Provides base configuration that is extended by platform-specific configs with unified environment handling and platform detection. **Key Features**: - **Platform Detection**: Automatically detects and configures for web/capacitor/electron - **Environment Setup**: Loads environment variables and sets platform flags -- **Path Aliases**: Configures TypeScript path resolution +- **Path Aliases**: Configures TypeScript path resolution and module aliases - **Build Optimization**: Platform-specific build optimizations - **Dependency Management**: Handles platform-specific dependencies @@ -1747,15 +2030,61 @@ export async function createBuildConfig(platform: string): Promise { const isElectron = platform === "electron"; const isNative = isCapacitor || isElectron; + // Set platform - PWA is always enabled for web platforms + process.env.VITE_PLATFORM = platform; + return { base: "/", plugins: [vue()], - server: { /* CORS and dev server config */ }, - build: { /* Platform-specific build config */ }, - worker: { /* Web worker configuration */ }, - define: { /* Environment variables and flags */ }, - resolve: { /* Path aliases and module resolution */ }, - optimizeDeps: { /* Dependency optimization */ } + server: { + port: parseInt(process.env.VITE_PORT || "8080"), + fs: { strict: false }, + // CORS headers disabled to allow images from any domain + }, + build: { + outDir: "dist", + assetsDir: 'assets', + chunkSizeWarningLimit: 1000, + rollupOptions: { + external: isNative ? ['@capacitor/app'] : [], + output: { + format: 'esm', + generatedCode: { preset: 'es2015' }, + manualChunks: undefined + } + } + }, + define: { + 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV), + 'process.env.VITE_PLATFORM': JSON.stringify(platform), + __IS_MOBILE__: JSON.stringify(isCapacitor), + __IS_ELECTRON__: JSON.stringify(isElectron), + __USE_QR_READER__: JSON.stringify(!isCapacitor), + // ... additional platform-specific defines + }, + resolve: { + alias: { + '@': path.resolve(__dirname, 'src'), + '@nostr/tools': path.resolve(__dirname, 'node_modules/@nostr/tools'), + 'path': path.resolve(__dirname, './src/utils/node-modules/path.js'), + 'fs': path.resolve(__dirname, './src/utils/node-modules/fs.js'), + 'crypto': path.resolve(__dirname, './src/utils/node-modules/crypto.js'), + // ... additional aliases + } + }, + optimizeDeps: { + include: [ + '@nostr/tools', + '@jlongster/sql.js', + 'absurd-sql', + // ... additional dependencies + ], + exclude: isNative ? [ + 'register-service-worker', + 'workbox-window', + // ... native exclusions + ] : [] + } }; } ``` @@ -1780,7 +2109,6 @@ export async function createBuildConfig(platform: string): Promise { **Purpose**: Configures Vite for web builds with environment-specific optimizations and PWA features. **Key Features**: - - **Environment-Specific Configuration**: Different settings for dev/test/prod - **PWA Integration**: Progressive Web App support with service worker - **Build Optimization**: Manual chunk splitting for better caching @@ -1790,7 +2118,6 @@ export async function createBuildConfig(platform: string): Promise { **Environment Configurations**: **Development Mode**: - ```typescript { build: { @@ -1807,7 +2134,6 @@ export async function createBuildConfig(platform: string): Promise { ``` **Test Mode**: - ```typescript { build: { @@ -1824,7 +2150,6 @@ export async function createBuildConfig(platform: string): Promise { ``` **Production Mode**: - ```typescript { build: { @@ -1850,7 +2175,6 @@ export async function createBuildConfig(platform: string): Promise { ``` **PWA Configuration**: - ```typescript VitePWA({ registerType: 'autoUpdate', @@ -1876,7 +2200,6 @@ VitePWA({ **Purpose**: Configures Vite for Electron builds with desktop-specific optimizations and native module support. **Key Features**: - - **Electron-Specific Entry Point**: Uses `main.electron.ts` instead of `main.web.ts` - **Native Module Support**: Handles Electron-specific dependencies - **Desktop Optimizations**: Larger chunk sizes and desktop-specific settings @@ -1884,7 +2207,6 @@ VitePWA({ - **External Dependencies**: Properly handles Electron and native modules **Configuration Structure**: - ```typescript export default defineConfig(async () => { const baseConfig = await createBuildConfig("electron"); @@ -1922,13 +2244,11 @@ export default defineConfig(async () => { ``` **Plugins**: - - **electron-entry-point**: Replaces main entry point for Electron - **electron-config**: Handles Electron-specific configurations - **suppress-source-maps**: Suppresses source map loading errors **External Dependencies**: - - `electron`: Electron runtime - `@capacitor-community/electron`: Capacitor Electron plugin - `better-sqlite3-multiple-ciphers`: Native SQLite module @@ -1942,7 +2262,6 @@ export default defineConfig(async () => { **Purpose**: Provides minimal configuration for Capacitor builds, inheriting from common config. **Configuration**: - ```typescript import { defineConfig } from "vite"; import { createBuildConfig } from "./vite.config.common.mts"; @@ -1951,7 +2270,6 @@ export default defineConfig(async () => createBuildConfig('capacitor')); ``` **Key Features**: - - **Minimal Configuration**: Inherits all settings from common config - **Mobile Platform**: Automatically configures for mobile-specific settings - **PWA Disabled**: Progressive Web App features disabled for native apps @@ -2007,7 +2325,6 @@ share_target: { ``` **Alias Configuration**: - - `@`: Source directory alias - `buffer`: Buffer polyfill - `dexie-export-import`: Database import/export utilities @@ -2083,4 +2400,4 @@ All scripts use consistent error handling: --- -**Note**: This documentation is maintained alongside the build system. For the most up-to-date information, refer to the actual script files and Vite configuration files in the repository. +**Note**: This documentation is maintained alongside the build system. For the most up-to-date information, refer to the actual script files and Vite configuration files in the repository. \ No newline at end of file diff --git a/package.json b/package.json index 2274ed91..cd34bc17 100644 --- a/package.json +++ b/package.json @@ -92,6 +92,7 @@ "clean:android": "adb uninstall app.timesafari.app || true", "clean:ios": "rm -rf ios/App/build ios/App/Pods ios/App/output ios/App/App/public ios/DerivedData ios/capacitor-cordova-ios-plugins ios/App/App/capacitor.config.json ios/App/App/config.xml || true", "clean:electron": "./scripts/build-electron.sh --clean", + "clean:all": "npm run clean:ios && npm run clean:android && npm run clean:electron", "build:android": "./scripts/build-android.sh", "build:android:dev": "./scripts/build-android.sh --dev", "build:android:test": "./scripts/build-android.sh --test",