490 lines
15 KiB
Bash
Executable File
490 lines
15 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# MoreMinimore App Building Script
|
|
# This script builds the MoreMinimore application with proper configuration
|
|
# Usage: ./scripts/build-moreminimore-app.sh [options]
|
|
|
|
set -e # Exit on any error
|
|
|
|
echo "🚀 Starting MoreMinimore app build process..."
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
PURPLE='\033[0;35m'
|
|
CYAN='\033[0;36m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Default configuration
|
|
PRODUCTION_BUILD=false
|
|
CLEAN_ONLY=false
|
|
SKIP_DEPS=false
|
|
VERBOSE=false
|
|
|
|
# Function to print colored output
|
|
print_status() {
|
|
echo -e "${BLUE}[INFO]${NC} $1"
|
|
}
|
|
|
|
print_success() {
|
|
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
|
}
|
|
|
|
print_warning() {
|
|
echo -e "${YELLOW}[WARNING]${NC} $1"
|
|
}
|
|
|
|
print_error() {
|
|
echo -e "${RED}[ERROR]${NC} $1"
|
|
}
|
|
|
|
print_step() {
|
|
echo -e "${PURPLE}[STEP]${NC} $1"
|
|
}
|
|
|
|
print_command() {
|
|
echo -e "${CYAN}[CMD]${NC} $1"
|
|
}
|
|
|
|
# Function to display help
|
|
show_help() {
|
|
cat << EOF
|
|
MoreMinimore App Building Script
|
|
|
|
USAGE:
|
|
./scripts/build-moreminimore-app.sh [OPTIONS]
|
|
|
|
OPTIONS:
|
|
--production Build for production (requires code signing setup)
|
|
--clean-only Only clean build artifacts, don't build
|
|
--skip-deps Skip dependency installation
|
|
--verbose Enable verbose output
|
|
--help, -h Show this help message
|
|
|
|
EXAMPLES:
|
|
# Development build (no code signing)
|
|
./scripts/build-moreminimore-app.sh
|
|
|
|
# Production build (requires Apple Developer credentials)
|
|
./scripts/build-moreminimore-app.sh --production
|
|
|
|
# Clean build artifacts only
|
|
./scripts/build-moreminimore-app.sh --clean-only
|
|
|
|
# Verbose build output
|
|
./scripts/build-moreminimore-app.sh --verbose
|
|
|
|
REQUIREMENTS:
|
|
- Node.js and npm
|
|
- MoreMinimore logo at assets/moreminimorelogo.png
|
|
- For production builds: Apple Developer credentials
|
|
|
|
OUTPUT:
|
|
Development builds: out/make/zip/darwin/arm64/
|
|
Production builds: out/make/ with platform-specific installers
|
|
|
|
EOF
|
|
}
|
|
|
|
# Function to parse command line arguments
|
|
parse_arguments() {
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
--production)
|
|
PRODUCTION_BUILD=true
|
|
shift
|
|
;;
|
|
--clean-only)
|
|
CLEAN_ONLY=true
|
|
shift
|
|
;;
|
|
--skip-deps)
|
|
SKIP_DEPS=true
|
|
shift
|
|
;;
|
|
--verbose)
|
|
VERBOSE=true
|
|
shift
|
|
;;
|
|
--help|-h)
|
|
show_help
|
|
exit 0
|
|
;;
|
|
*)
|
|
print_error "Unknown option: $1"
|
|
show_help
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
}
|
|
|
|
# Function to check if we're in the right directory
|
|
check_directory() {
|
|
if [ ! -f "package.json" ] || [ ! -d "src" ]; then
|
|
print_error "Please run this script from the project root directory"
|
|
exit 1
|
|
fi
|
|
print_success "✓ Running from correct directory"
|
|
}
|
|
|
|
# Function to setup build environment
|
|
setup_environment() {
|
|
print_step "Setting up build environment..."
|
|
|
|
if [ "$PRODUCTION_BUILD" = true ]; then
|
|
print_status "Production build mode - code signing enabled"
|
|
print_warning "Production builds require Apple Developer credentials"
|
|
print_warning "Ensure the following environment variables are set:"
|
|
echo " - APPLE_TEAM_ID"
|
|
echo " - APPLE_ID"
|
|
echo " - APPLE_PASSWORD"
|
|
echo " - SM_CODE_SIGNING_CERT_SHA1_HASH"
|
|
echo ""
|
|
|
|
# Check if production credentials are available
|
|
if [ -z "$APPLE_TEAM_ID" ] || [ -z "$APPLE_ID" ]; then
|
|
print_error "Production build requires Apple Developer credentials"
|
|
print_error "Please set the required environment variables or use development build"
|
|
print_error "Run: ./scripts/build-moreminimore-app.sh (without --production)"
|
|
exit 1
|
|
fi
|
|
else
|
|
print_status "Development build mode - code signing disabled"
|
|
export E2E_TEST_BUILD=true
|
|
print_success "✓ E2E_TEST_BUILD=true (code signing disabled)"
|
|
fi
|
|
|
|
# Set verbose mode if requested
|
|
if [ "$VERBOSE" = true ]; then
|
|
export DEBUG=electron-forge:*
|
|
print_success "✓ Verbose mode enabled"
|
|
fi
|
|
}
|
|
|
|
# Function to check prerequisites
|
|
check_prerequisites() {
|
|
print_step "Checking prerequisites..."
|
|
|
|
# Check Node.js
|
|
if ! command -v node &> /dev/null; then
|
|
print_error "Node.js is not installed"
|
|
exit 1
|
|
fi
|
|
local node_version=$(node --version)
|
|
print_success "✓ Node.js $node_version"
|
|
|
|
# Check npm
|
|
if ! command -v npm &> /dev/null; then
|
|
print_error "npm is not installed"
|
|
exit 1
|
|
fi
|
|
local npm_version=$(npm --version)
|
|
print_success "✓ npm $npm_version"
|
|
|
|
# Check package.json
|
|
if [ ! -f "package.json" ]; then
|
|
print_error "package.json not found"
|
|
exit 1
|
|
fi
|
|
print_success "✓ package.json found"
|
|
|
|
# Check source logo
|
|
if [ ! -f "assets/moreminimorelogo.png" ]; then
|
|
print_error "Source logo not found: assets/moreminimorelogo.png"
|
|
print_error "Please ensure your MoreMinimore logo is available"
|
|
exit 1
|
|
fi
|
|
print_success "✓ Source logo found"
|
|
|
|
# Check generated logos
|
|
if [ ! -f "assets/logo.svg" ] || [ ! -f "assets/icon/logo.icns" ]; then
|
|
print_warning "Generated logos not found. Running logo update..."
|
|
bash -c 'source scripts/update-and-debrand.sh && update_logos'
|
|
print_success "✓ Logos generated"
|
|
else
|
|
print_success "✓ Generated logos found"
|
|
fi
|
|
}
|
|
|
|
# Function to install dependencies
|
|
install_dependencies() {
|
|
if [ "$SKIP_DEPS" = true ]; then
|
|
print_status "Skipping dependency installation"
|
|
return
|
|
fi
|
|
|
|
print_step "Installing dependencies..."
|
|
print_command "npm install"
|
|
|
|
if [ "$VERBOSE" = true ]; then
|
|
npm install
|
|
else
|
|
npm install --silent
|
|
fi
|
|
|
|
print_success "✓ Dependencies installed"
|
|
}
|
|
|
|
# Function to clean build artifacts
|
|
clean_build() {
|
|
print_step "Cleaning build artifacts..."
|
|
|
|
# Remove out directory
|
|
if [ -d "out" ]; then
|
|
rm -rf out
|
|
print_success "✓ Removed out directory"
|
|
fi
|
|
|
|
# Remove scaffold node_modules
|
|
if [ -d "scaffold/node_modules" ]; then
|
|
rm -rf scaffold/node_modules
|
|
print_success "✓ Removed scaffold node_modules"
|
|
fi
|
|
|
|
# Clean npm cache if verbose
|
|
if [ "$VERBOSE" = true ]; then
|
|
npm run clean --if-present
|
|
print_success "✓ Ran npm clean"
|
|
fi
|
|
}
|
|
|
|
# Function to prepare for build
|
|
prepare_build() {
|
|
print_step "Preparing for build..."
|
|
|
|
# Ensure we have the latest debranding
|
|
if [ ! -f "src/custom/index.ts" ] || ! grep -q "REMOVE_LIMIT_ENABLED" src/custom/index.ts; then
|
|
print_status "Applying custom features..."
|
|
bash -c 'source scripts/update-and-debrand.sh && apply_custom_features'
|
|
print_success "✓ Custom features applied"
|
|
fi
|
|
|
|
# Validate Moreminimore provider configuration
|
|
validate_moreminimore_provider
|
|
|
|
# Verify TypeScript compilation
|
|
print_status "Checking TypeScript compilation..."
|
|
if npm run ts 2>/dev/null; then
|
|
print_success "✓ TypeScript compilation successful"
|
|
else
|
|
print_error "TypeScript compilation failed"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Function to validate Moreminimore provider configuration
|
|
validate_moreminimore_provider() {
|
|
print_status "Validating Moreminimore provider configuration..."
|
|
|
|
# Check if Moreminimore provider exists in language model constants
|
|
if [ -f "src/ipc/shared/language_model_constants.ts" ]; then
|
|
if grep -q "moreminimore:" src/ipc/shared/language_model_constants.ts; then
|
|
print_success "✓ Moreminimore provider found in language_model_constants.ts"
|
|
else
|
|
print_warning "Moreminimore provider not found in language_model_constants.ts"
|
|
print_status "Adding Moreminimore provider..."
|
|
bash -c 'source scripts/update-and-debrand.sh && add_moreminimore_provider'
|
|
fi
|
|
else
|
|
print_error "language_model_constants.ts not found"
|
|
exit 1
|
|
fi
|
|
|
|
# Check if Moreminimore case exists in get_model_client.ts
|
|
if [ -f "src/ipc/utils/get_model_client.ts" ]; then
|
|
if grep -q 'case "moreminimore":' src/ipc/utils/get_model_client.ts; then
|
|
print_success "✓ Moreminimore case found in get_model_client.ts"
|
|
else
|
|
print_warning "Moreminimore case not found in get_model_client.ts"
|
|
print_status "Adding Moreminimore case..."
|
|
bash -c 'source scripts/update-and-debrand.sh && update_backend_model_client'
|
|
fi
|
|
else
|
|
print_error "get_model_client.ts not found"
|
|
exit 1
|
|
fi
|
|
|
|
# Check if provider settings UI is updated
|
|
if [ -f "src/components/settings/ProviderSettingsPage.tsx" ]; then
|
|
if grep -q "provider !== \"moreminimore\"" src/components/settings/ProviderSettingsPage.tsx; then
|
|
print_success "✓ Provider settings UI updated for Moreminimore"
|
|
else
|
|
print_warning "Provider settings UI not updated for Moreminimore"
|
|
print_status "Updating provider settings UI..."
|
|
bash -c 'source scripts/update-and-debrand.sh && update_provider_settings_ui'
|
|
fi
|
|
fi
|
|
|
|
print_success "✓ Moreminimore provider validation completed"
|
|
}
|
|
|
|
# Function to build application
|
|
build_application() {
|
|
print_step "Building MoreMinimore application..."
|
|
|
|
local build_command="npm run make"
|
|
print_command "$build_command"
|
|
|
|
if [ "$VERBOSE" = true ]; then
|
|
$build_command
|
|
else
|
|
# Capture output but show progress
|
|
local build_output
|
|
if build_output=$($build_command 2>&1); then
|
|
print_success "✓ Build completed successfully"
|
|
else
|
|
print_error "Build failed"
|
|
if [ "$VERBOSE" = false ]; then
|
|
echo "$build_output" | tail -20
|
|
fi
|
|
exit 1
|
|
fi
|
|
fi
|
|
}
|
|
|
|
# Function to verify build
|
|
verify_build() {
|
|
print_step "Verifying build output..."
|
|
|
|
# Check if out directory exists and has content
|
|
if [ ! -d "out" ]; then
|
|
print_error "Build output directory not found"
|
|
exit 1
|
|
fi
|
|
|
|
# Look for build artifacts based on platform
|
|
local build_found=false
|
|
|
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
# macOS
|
|
if [ -f "out/make/zip/darwin/arm64/MoreMinimore-darwin-arm64-"*".zip" ]; then
|
|
build_found=true
|
|
local app_file=$(ls out/make/zip/darwin/arm64/MoreMinimore-darwin-arm64-*.zip | head -1)
|
|
print_success "✓ macOS build found: $(basename "$app_file")"
|
|
fi
|
|
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
|
# Linux
|
|
if [ -f "out/make/deb/x64/moreminimore_"*".deb" ]; then
|
|
build_found=true
|
|
local app_file=$(ls out/make/deb/x64/moreminimore_*.deb | head -1)
|
|
print_success "✓ Linux build found: $(basename "$app_file")"
|
|
fi
|
|
elif [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]]; then
|
|
# Windows
|
|
if [ -f "out/make/squirrel.windows/x64/MoreMinimoreSetup-"*".exe" ]; then
|
|
build_found=true
|
|
local app_file=$(ls out/make/squirrel.windows/x64/MoreMinimoreSetup-*.exe | head -1)
|
|
print_success "✓ Windows build found: $(basename "$app_file")"
|
|
fi
|
|
fi
|
|
|
|
if [ "$build_found" = false ]; then
|
|
print_warning "No platform-specific build artifacts found, but out directory exists"
|
|
print_status "Build artifacts:"
|
|
find out -type f -name "*.exe" -o -name "*.deb" -o -name "*.zip" -o -name "*.dmg" | head -10
|
|
fi
|
|
|
|
# Show build directory size
|
|
if command -v du &> /dev/null; then
|
|
local build_size=$(du -sh out | cut -f1)
|
|
print_success "✓ Build directory size: $build_size"
|
|
fi
|
|
}
|
|
|
|
# Function to show results
|
|
show_results() {
|
|
print_step "Build completed successfully!"
|
|
echo ""
|
|
echo -e "${GREEN}🎉 MoreMinimore application built successfully!${NC}"
|
|
echo ""
|
|
|
|
if [ "$PRODUCTION_BUILD" = true ]; then
|
|
echo -e "${YELLOW}Build Type:${NC} Production (code signed)"
|
|
else
|
|
echo -e "${YELLOW}Build Type:${NC} Development (no code signing)"
|
|
fi
|
|
|
|
echo ""
|
|
echo -e "${BLUE}Build Artifacts:${NC}"
|
|
echo "📁 out/"
|
|
|
|
# Show specific build files
|
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
echo " └── 📦 out/make/zip/darwin/arm64/MoreMinimore-*.zip"
|
|
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
|
echo " └── 📦 out/make/deb/x64/moreminimore_*.deb"
|
|
elif [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]]; then
|
|
echo " └── 📦 out/make/squirrel.windows/x64/MoreMinimoreSetup-*.exe"
|
|
fi
|
|
|
|
echo ""
|
|
echo -e "${BLUE}Next Steps:${NC}"
|
|
echo "1. Install and test the application"
|
|
echo "2. For distribution, consider code signing (production builds)"
|
|
echo "3. Upload to your distribution platform"
|
|
echo ""
|
|
|
|
if [ "$PRODUCTION_BUILD" = false ]; then
|
|
echo -e "${YELLOW}Note:${NC} This is a development build without code signing."
|
|
echo "For production distribution, use: ./scripts/build-moreminimore-app.sh --production"
|
|
echo ""
|
|
fi
|
|
}
|
|
|
|
# Function to handle errors
|
|
handle_error() {
|
|
local exit_code=$?
|
|
if [ $exit_code -ne 0 ]; then
|
|
print_error "Build failed with exit code $exit_code"
|
|
echo ""
|
|
echo -e "${YELLOW}Troubleshooting:${NC}"
|
|
echo "1. Ensure all dependencies are installed: npm install"
|
|
echo "2. Check TypeScript compilation: npm run ts"
|
|
echo "3. Verify logo files exist: ls -la assets/"
|
|
echo "4. For production builds, check Apple Developer credentials"
|
|
echo "5. Run with --verbose for detailed output"
|
|
echo ""
|
|
echo "For help: ./scripts/build-moreminimore-app.sh --help"
|
|
exit $exit_code
|
|
fi
|
|
}
|
|
|
|
# Main execution
|
|
main() {
|
|
# Set up error handling
|
|
trap handle_error ERR
|
|
|
|
# Parse command line arguments
|
|
parse_arguments "$@"
|
|
|
|
# Show header
|
|
echo "========================================"
|
|
echo "🚀 MoreMinimore App Builder"
|
|
echo "========================================"
|
|
echo ""
|
|
|
|
# Execute build steps
|
|
check_directory
|
|
setup_environment
|
|
check_prerequisites
|
|
|
|
if [ "$CLEAN_ONLY" = true ]; then
|
|
clean_build
|
|
print_success "🧹 Build artifacts cleaned successfully"
|
|
exit 0
|
|
fi
|
|
|
|
install_dependencies
|
|
clean_build
|
|
prepare_build
|
|
build_application
|
|
verify_build
|
|
show_results
|
|
}
|
|
|
|
# Run main function with all arguments
|
|
main "$@"
|