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.
This commit is contained in:
@@ -3,30 +3,28 @@
|
||||
# Author: Matthew Raymer
|
||||
# Description: Build script for TimeSafari Electron application
|
||||
# This script handles the complete build process for the TimeSafari Electron app,
|
||||
# including web asset compilation, TypeScript compilation, and AppImage packaging.
|
||||
# It ensures all dependencies are available and provides detailed build feedback.
|
||||
# including web asset compilation and Capacitor sync.
|
||||
#
|
||||
# Build Process:
|
||||
# 1. Environment setup and dependency checks
|
||||
# 2. Web asset compilation (Vite)
|
||||
# 3. TypeScript compilation
|
||||
# 4. Electron main process build
|
||||
# 5. AppImage packaging
|
||||
# 3. Capacitor sync
|
||||
# 4. Electron start
|
||||
#
|
||||
# Dependencies:
|
||||
# - Node.js and npm
|
||||
# - TypeScript
|
||||
# - Vite
|
||||
# - electron-builder
|
||||
# - @capacitor-community/electron
|
||||
#
|
||||
# Usage: ./experiment.sh
|
||||
#
|
||||
# Exit Codes:
|
||||
# 1 - Required command not found
|
||||
# 2 - TypeScript installation failed
|
||||
# 3 - TypeScript compilation failed
|
||||
# 4 - Build process failed
|
||||
# 5 - AppImage build failed
|
||||
# 3 - Build process failed
|
||||
# 4 - Capacitor sync failed
|
||||
# 5 - Electron start failed
|
||||
|
||||
# Exit on any error
|
||||
set -e
|
||||
@@ -73,18 +71,6 @@ measure_time() {
|
||||
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
|
||||
echo -e "\n${BLUE}=== TimeSafari Electron Build Process ===${NC}\n"
|
||||
log_info "Starting build process at $(date)"
|
||||
@@ -93,6 +79,7 @@ log_info "Starting build process at $(date)"
|
||||
log_info "Checking required dependencies..."
|
||||
check_command node
|
||||
check_command npm
|
||||
check_command git
|
||||
|
||||
# Create application data directory
|
||||
log_info "Setting up application directories..."
|
||||
@@ -135,52 +122,33 @@ log_info "Using git hash: ${GIT_HASH}"
|
||||
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
|
||||
log_error "Web asset build failed!"
|
||||
exit 4
|
||||
fi
|
||||
|
||||
# TypeScript compilation
|
||||
log_info "Compiling TypeScript..."
|
||||
if ! measure_time ./node_modules/.bin/tsc -p tsconfig.electron.json; then
|
||||
log_error "TypeScript compilation failed!"
|
||||
exit 3
|
||||
fi
|
||||
|
||||
# Build electron main process
|
||||
# log_info "Building electron main process..."
|
||||
# if ! measure_time env VITE_GIT_HASH="$GIT_HASH" npx vite build --config vite.config.electron.mts --mode electron; then
|
||||
# log_error "Electron main process build failed!"
|
||||
# exit 4
|
||||
# fi
|
||||
# Sync with Capacitor
|
||||
log_info "Syncing with Capacitor..."
|
||||
if ! measure_time npx cap sync electron; then
|
||||
log_error "Capacitor sync failed!"
|
||||
exit 4
|
||||
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"
|
||||
# Restore capacitor config
|
||||
log_info "Restoring capacitor config..."
|
||||
if ! git checkout electron/capacitor.config.json; then
|
||||
log_error "Failed to restore capacitor config!"
|
||||
exit 4
|
||||
fi
|
||||
|
||||
# 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
|
||||
# Start Electron
|
||||
log_info "Starting Electron..."
|
||||
cd electron/
|
||||
if ! measure_time npm run electron:start; then
|
||||
log_error "Electron start failed!"
|
||||
exit 5
|
||||
fi
|
||||
|
||||
# Print build summary
|
||||
# echo -e "\n${GREEN}=== Build Summary ===${NC}"
|
||||
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
|
||||
|
||||
log_success "Build and start completed successfully!"
|
||||
echo -e "\n${GREEN}=== End of Build Process ===${NC}\n"
|
||||
|
||||
# Exit with success
|
||||
|
||||
Reference in New Issue
Block a user