Browse Source

refactor(experiment.sh): streamline build process for Capacitor-based Electron app

- Remove all commented-out legacy build steps (TypeScript compilation, AppImage packaging)
- Add Capacitor sync and Electron start sequence
- Update script documentation and dependencies
- Add proper error handling for Capacitor workflow
- Add git command check for capacitor config restoration
- Remove unused AppImage-related functions

This change aligns the build process with our Capacitor-based Electron architecture,
replacing the direct file copying approach with Capacitor's sync mechanism.
sql-absurd-sql-further
Matthew Raymer 3 days ago
parent
commit
d426f9c4ac
  1. 88
      experiment.sh

88
experiment.sh

@ -3,30 +3,28 @@
# Author: Matthew Raymer # Author: Matthew Raymer
# Description: Build script for TimeSafari Electron application # Description: Build script for TimeSafari Electron application
# This script handles the complete build process for the TimeSafari Electron app, # This script handles the complete build process for the TimeSafari Electron app,
# including web asset compilation, TypeScript compilation, and AppImage packaging. # including web asset compilation and Capacitor sync.
# It ensures all dependencies are available and provides detailed build feedback.
# #
# Build Process: # Build Process:
# 1. Environment setup and dependency checks # 1. Environment setup and dependency checks
# 2. Web asset compilation (Vite) # 2. Web asset compilation (Vite)
# 3. TypeScript compilation # 3. Capacitor sync
# 4. Electron main process build # 4. Electron start
# 5. AppImage packaging
# #
# Dependencies: # Dependencies:
# - Node.js and npm # - Node.js and npm
# - TypeScript # - TypeScript
# - Vite # - Vite
# - electron-builder # - @capacitor-community/electron
# #
# Usage: ./experiment.sh # Usage: ./experiment.sh
# #
# Exit Codes: # Exit Codes:
# 1 - Required command not found # 1 - Required command not found
# 2 - TypeScript installation failed # 2 - TypeScript installation failed
# 3 - TypeScript compilation failed # 3 - Build process failed
# 4 - Build process failed # 4 - Capacitor sync failed
# 5 - AppImage build failed # 5 - Electron start failed
# Exit on any error # Exit on any error
set -e set -e
@ -73,18 +71,6 @@ measure_time() {
log_success "Completed in ${duration} seconds" log_success "Completed in ${duration} seconds"
} }
# Function to find the AppImage
find_appimage() {
local appimage_path
appimage_path=$(find dist-electron-packages -name "*.AppImage" -type f -print -quit)
if [ -n "$appimage_path" ]; then
echo "$appimage_path"
else
log_warn "AppImage not found in expected location"
echo "dist-electron-packages/*.AppImage"
fi
}
# Print build header # Print build header
echo -e "\n${BLUE}=== TimeSafari Electron Build Process ===${NC}\n" echo -e "\n${BLUE}=== TimeSafari Electron Build Process ===${NC}\n"
log_info "Starting build process at $(date)" log_info "Starting build process at $(date)"
@ -93,6 +79,7 @@ log_info "Starting build process at $(date)"
log_info "Checking required dependencies..." log_info "Checking required dependencies..."
check_command node check_command node
check_command npm check_command npm
check_command git
# Create application data directory # Create application data directory
log_info "Setting up application directories..." log_info "Setting up application directories..."
@ -135,52 +122,33 @@ log_info "Using git hash: ${GIT_HASH}"
log_info "Building web assets with Vite..." log_info "Building web assets with Vite..."
if ! measure_time env VITE_GIT_HASH="$GIT_HASH" npx vite build --config vite.config.app.electron.mts --mode electron; then if ! measure_time env VITE_GIT_HASH="$GIT_HASH" npx vite build --config vite.config.app.electron.mts --mode electron; then
log_error "Web asset build failed!" log_error "Web asset build failed!"
exit 3
fi
# Sync with Capacitor
log_info "Syncing with Capacitor..."
if ! measure_time npx cap sync electron; then
log_error "Capacitor sync failed!"
exit 4 exit 4
fi fi
# TypeScript compilation # Restore capacitor config
log_info "Compiling TypeScript..." log_info "Restoring capacitor config..."
if ! measure_time ./node_modules/.bin/tsc -p tsconfig.electron.json; then if ! git checkout electron/capacitor.config.json; then
log_error "TypeScript compilation failed!" log_error "Failed to restore capacitor config!"
exit 3 exit 4
fi fi
# Build electron main process # Start Electron
# log_info "Building electron main process..." log_info "Starting Electron..."
# if ! measure_time env VITE_GIT_HASH="$GIT_HASH" npx vite build --config vite.config.electron.mts --mode electron; then cd electron/
# log_error "Electron main process build failed!" if ! measure_time npm run electron:start; then
# exit 4 log_error "Electron start failed!"
# fi exit 5
fi
# Organize files
# log_info "Organizing build artifacts..."
#mkdir -p dist-electron/www
#cp -r dist/* dist-electron/www/ || log_error "Failed to copy web assets"
#mkdir -p dist-electron/resources
#cp src/electron/preload.js dist-electron/resources/preload.js || log_error "Failed to copy preload script"
# Build the AppImage
#log_info "Building AppImage package..."
#if ! measure_time npx electron-builder --linux AppImage; then
# log_error "AppImage build failed!"
# exit 5
#fi
# Print build summary # Print build summary
# echo -e "\n${GREEN}=== Build Summary ===${NC}" log_success "Build and start completed successfully!"
log_success "Build completed successfully!"
# log_info "Build artifacts location: $(pwd)/dist-electron"
# log_info "AppImage location: $(find_appimage)"
# Check for build warnings
# if grep -q "default Electron icon is used" dist-electron-packages/builder-effective-config.yaml; then
# log_warn "Using default Electron icon - consider adding a custom icon"
# fi
# if grep -q "chunks are larger than 1000 kB" dist-electron-packages/builder-effective-config.yaml; then
# log_warn "Large chunks detected - consider implementing code splitting"
# fi
echo -e "\n${GREEN}=== End of Build Process ===${NC}\n" echo -e "\n${GREEN}=== End of Build Process ===${NC}\n"
# Exit with success # Exit with success

Loading…
Cancel
Save