UNPKG

muspe-cli

Version:

MusPE Advanced Framework v2.1.3 - Mobile User-friendly Simple Progressive Engine with Enhanced CLI Tools, Specialized E-Commerce Templates, Material Design 3, Progressive Enhancement, Mobile Optimizations, Performance Analysis, and Enterprise-Grade Develo

623 lines (511 loc) 17.2 kB
# MusPE Deployment Scripts # Collection of deployment and build automation scripts # Build script for multiple platforms build-all.sh: | #!/bin/bash echo "🚀 MusPE Multi-Platform Build Script" echo "====================================" # Set error handling set -e # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' BLUE='\033[0;34m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Functions log_info() { echo -e "${BLUE}[INFO]${NC} $1" } log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1" } log_error() { echo -e "${RED}[ERROR]${NC} $1" } log_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } # Check if we're in a MusPE project if [ ! -f "package.json" ] || ! grep -q "muspe-cli" package.json; then log_error "Not in a MusPE project directory" exit 1 fi # Parse command line arguments BUILD_SERVER=false BUILD_ANDROID=false BUILD_IOS=false BUILD_DOCKER=false BUILD_PWA=false RELEASE_MODE=false while [[ $# -gt 0 ]]; do case $1 in --server) BUILD_SERVER=true shift ;; --android) BUILD_ANDROID=true shift ;; --ios) BUILD_IOS=true shift ;; --docker) BUILD_DOCKER=true shift ;; --pwa) BUILD_PWA=true shift ;; --all) BUILD_SERVER=true BUILD_ANDROID=true BUILD_IOS=true BUILD_DOCKER=true BUILD_PWA=true shift ;; --release) RELEASE_MODE=true shift ;; *) echo "Unknown option $1" exit 1 ;; esac done # If no specific build target is specified, build all if [ "$BUILD_SERVER" = false ] && [ "$BUILD_ANDROID" = false ] && [ "$BUILD_IOS" = false ] && [ "$BUILD_DOCKER" = false ] && [ "$BUILD_PWA" = false ]; then BUILD_SERVER=true BUILD_ANDROID=true BUILD_IOS=true BUILD_DOCKER=true BUILD_PWA=true fi # Prepare release flag RELEASE_FLAG="" if [ "$RELEASE_MODE" = true ]; then RELEASE_FLAG="--release" log_info "Building in RELEASE mode" else log_info "Building in DEBUG mode" fi # Install dependencies log_info "Installing dependencies..." npm install # Build server if [ "$BUILD_SERVER" = true ]; then log_info "Building server deployment..." if npx muspe deploy server $RELEASE_FLAG --ssr; then log_success "Server build completed" else log_error "Server build failed" exit 1 fi fi # Build PWA if [ "$BUILD_PWA" = true ]; then log_info "Building PWA..." if npx muspe deploy pwa $RELEASE_FLAG; then log_success "PWA build completed" else log_error "PWA build failed" exit 1 fi fi # Build Docker if [ "$BUILD_DOCKER" = true ]; then log_info "Building Docker container..." if npx muspe deploy docker $RELEASE_FLAG; then log_success "Docker build completed" else log_error "Docker build failed" exit 1 fi fi # Build Android if [ "$BUILD_ANDROID" = true ]; then log_info "Building Android app..." # Check Android environment if ! command -v java &> /dev/null; then log_error "Java is not installed. Please install Java JDK 11 or higher." exit 1 fi if ! command -v cordova &> /dev/null; then log_warning "Cordova not found, installing globally..." npm install -g cordova fi ANDROID_FLAGS="$RELEASE_FLAG" if [ "$RELEASE_MODE" = true ]; then ANDROID_FLAGS="$ANDROID_FLAGS --bundle" fi if npx muspe deploy android $ANDROID_FLAGS; then log_success "Android build completed" else log_error "Android build failed" exit 1 fi fi # Build iOS (only on macOS) if [ "$BUILD_IOS" = true ]; then if [[ "$OSTYPE" == "darwin"* ]]; then log_info "Building iOS app..." # Check Xcode if ! command -v xcodebuild &> /dev/null; then log_error "Xcode is not installed. Please install Xcode from the App Store." exit 1 fi if ! command -v cordova &> /dev/null; then log_warning "Cordova not found, installing globally..." npm install -g cordova fi IOS_FLAGS="$RELEASE_FLAG" if [ "$RELEASE_MODE" = true ]; then IOS_FLAGS="$IOS_FLAGS --archive" fi if npx muspe deploy ios $IOS_FLAGS; then log_success "iOS build completed" else log_error "iOS build failed" exit 1 fi else log_warning "iOS builds are only supported on macOS, skipping..." fi fi log_success "All builds completed successfully!" # Display build summary echo "" echo "📦 Build Summary:" echo "==================" if [ "$BUILD_SERVER" = true ]; then echo "✅ Server: deploy/server/" fi if [ "$BUILD_PWA" = true ]; then echo "✅ PWA: dist/" fi if [ "$BUILD_DOCKER" = true ]; then echo "✅ Docker: Dockerfile, docker-compose.yml" fi if [ "$BUILD_ANDROID" = true ]; then echo "✅ Android: platforms/android/app/build/outputs/" fi if [ "$BUILD_IOS" = true ] && [[ "$OSTYPE" == "darwin"* ]]; then echo "✅ iOS: platforms/ios/build/" fi echo "" echo "🎉 Ready for deployment!" # Server deployment script deploy-server.sh: | #!/bin/bash echo "🌐 MusPE Server Deployment Script" echo "=================================" # Configuration SERVER_HOST="${DEPLOY_SERVER_HOST:-your-server.com}" SERVER_USER="${DEPLOY_SERVER_USER:-deploy}" SERVER_PATH="${DEPLOY_SERVER_PATH:-/var/www/muspe-app}" # Colors GREEN='\033[0;32m' BLUE='\033[0;34m' RED='\033[0;31m' NC='\033[0m' log_info() { echo -e "${BLUE}[INFO]${NC} $1" } log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1" } log_error() { echo -e "${RED}[ERROR]${NC} $1" } # Check if deployment artifacts exist if [ ! -d "deploy/server" ]; then log_error "Server deployment artifacts not found. Run 'muspe deploy server' first." exit 1 fi # Upload files log_info "Uploading files to $SERVER_HOST..." rsync -avz --delete deploy/server/ $SERVER_USER@$SERVER_HOST:$SERVER_PATH/ # Upload static files if [ -d "dist" ]; then rsync -avz --delete dist/ $SERVER_USER@$SERVER_HOST:$SERVER_PATH/dist/ fi # Run deployment commands on server log_info "Running deployment commands on server..." ssh $SERVER_USER@$SERVER_HOST << 'ENDSSH' cd /var/www/muspe-app # Install dependencies npm install --production # Restart services pm2 reload ecosystem.config.js || pm2 start ecosystem.config.js # Reload nginx sudo nginx -t && sudo nginx -s reload echo "✅ Server deployment completed" ENDSSH log_success "Deployment completed successfully!" # Android signing and upload script android-release.sh: | #!/bin/bash echo "🤖 MusPE Android Release Script" echo "===============================" # Configuration KEYSTORE_PATH="${ANDROID_KEYSTORE_PATH:-android-release-key.keystore}" KEY_ALIAS="${ANDROID_KEY_ALIAS:-muspe-app}" # Colors GREEN='\033[0;32m' BLUE='\033[0;34m' RED='\033[0;31m' YELLOW='\033[1;33m' NC='\033[0m' log_info() { echo -e "${BLUE}[INFO]${NC} $1" } log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1" } log_error() { echo -e "${RED}[ERROR]${NC} $1" } log_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } # Check if keystore exists if [ ! -f "$KEYSTORE_PATH" ]; then log_warning "Keystore not found. Generating new keystore..." # Prompt for keystore information echo "Please provide keystore information:" read -p "Organization Name: " ORG_NAME read -p "Organizational Unit: " ORG_UNIT read -p "City/Locality: " CITY read -p "State/Province: " STATE read -p "Country Code (2 letters): " COUNTRY read -s -p "Keystore Password: " KEYSTORE_PASS echo read -s -p "Key Password: " KEY_PASS echo # Generate keystore keytool -genkey -v \ -keystore "$KEYSTORE_PATH" \ -alias "$KEY_ALIAS" \ -keyalg RSA \ -keysize 2048 \ -validity 10000 \ -dname "CN=$ORG_NAME, OU=$ORG_UNIT, O=$ORG_NAME, L=$CITY, S=$STATE, C=$COUNTRY" \ -storepass "$KEYSTORE_PASS" \ -keypass "$KEY_PASS" log_success "Keystore generated: $KEYSTORE_PATH" fi # Build release APK/AAB log_info "Building Android release..." npx muspe deploy android --release --bundle # Sign the APK/AAB (if not already signed) APK_PATH="platforms/android/app/build/outputs/apk/release" AAB_PATH="platforms/android/app/build/outputs/bundle/release" if [ -d "$APK_PATH" ]; then log_info "APK files found in $APK_PATH" ls -la "$APK_PATH"/*.apk fi if [ -d "$AAB_PATH" ]; then log_info "AAB files found in $AAB_PATH" ls -la "$AAB_PATH"/*.aab fi # Optional: Upload to Google Play Console if command -v fastlane &> /dev/null; then log_info "Fastlane detected. You can upload to Google Play using:" echo " fastlane supply --aab $AAB_PATH/*.aab" else log_info "Manual upload required:" echo " 1. Go to https://play.google.com/console/developers" echo " 2. Upload the AAB file from: $AAB_PATH" fi log_success "Android release process completed!" # iOS release and upload script ios-release.sh: | #!/bin/bash echo "🍎 MusPE iOS Release Script" echo "==========================" # Check if running on macOS if [[ "$OSTYPE" != "darwin"* ]]; then echo "❌ iOS builds are only supported on macOS" exit 1 fi # Colors GREEN='\033[0;32m' BLUE='\033[0;34m' RED='\033[0;31m' NC='\033[0m' log_info() { echo -e "${BLUE}[INFO]${NC} $1" } log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1" } log_error() { echo -e "${RED}[ERROR]${NC} $1" } # Check Xcode installation if ! command -v xcodebuild &> /dev/null; then log_error "Xcode is not installed. Please install Xcode from the App Store." exit 1 fi # Build iOS release log_info "Building iOS release..." npx muspe deploy ios --release --archive # Find the archive ARCHIVE_PATH="platforms/ios/build" if [ -d "$ARCHIVE_PATH" ]; then ARCHIVES=$(find "$ARCHIVE_PATH" -name "*.xcarchive" -type d) if [ -n "$ARCHIVES" ]; then log_success "Archive(s) created:" echo "$ARCHIVES" # Export IPA for ARCHIVE in $ARCHIVES; do log_info "Exporting IPA from $ARCHIVE..." IPA_DIR="$ARCHIVE_PATH/ipa" mkdir -p "$IPA_DIR" # Create export options plist cat > "$ARCHIVE_PATH/ExportOptions.plist" << EOF <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>method</key> <string>app-store</string> <key>uploadBitcode</key> <false/> <key>uploadSymbols</key> <true/> <key>compileBitcode</key> <false/> </dict> </plist> EOF # Export IPA xcodebuild -exportArchive \ -archivePath "$ARCHIVE" \ -exportPath "$IPA_DIR" \ -exportOptionsPlist "$ARCHIVE_PATH/ExportOptions.plist" if [ $? -eq 0 ]; then log_success "IPA exported to $IPA_DIR" # Find IPA file IPA_FILE=$(find "$IPA_DIR" -name "*.ipa") if [ -n "$IPA_FILE" ]; then log_info "IPA file: $IPA_FILE" # Upload to App Store Connect (if credentials are available) if [ -n "$APP_STORE_CONNECT_API_KEY_ID" ] && [ -n "$APP_STORE_CONNECT_API_PRIVATE_KEY" ]; then log_info "Uploading to App Store Connect..." xcrun altool --upload-app \ --type ios \ --file "$IPA_FILE" \ --apiKey "$APP_STORE_CONNECT_API_KEY_ID" \ --apiIssuer "$APP_STORE_CONNECT_ISSUER_ID" if [ $? -eq 0 ]; then log_success "Upload to App Store Connect completed!" else log_error "Upload to App Store Connect failed" fi else log_info "Manual upload required:" echo " 1. Open Xcode" echo " 2. Go to Window > Organizer" echo " 3. Select your archive and click 'Distribute App'" echo " 4. Choose 'App Store Connect' and follow the wizard" echo "" echo " Or use Transporter app:" echo " 1. Open Transporter app" echo " 2. Drag and drop: $IPA_FILE" fi fi else log_error "IPA export failed" fi done else log_error "No archives found" exit 1 fi else log_error "Archive directory not found" exit 1 fi log_success "iOS release process completed!" # Docker deployment script docker-deploy.sh: | #!/bin/bash echo "🐳 MusPE Docker Deployment Script" echo "=================================" # Configuration DOCKER_REGISTRY="${DOCKER_REGISTRY:-docker.io}" DOCKER_USERNAME="${DOCKER_USERNAME:-your-username}" IMAGE_NAME="${DOCKER_IMAGE_NAME:-muspe-app}" # Colors GREEN='\033[0;32m' BLUE='\033[0;34m' RED='\033[0;31m' NC='\033[0m' log_info() { echo -e "${BLUE}[INFO]${NC} $1" } log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1" } log_error() { echo -e "${RED}[ERROR]${NC} $1" } # Check Docker installation if ! command -v docker &> /dev/null; then log_error "Docker is not installed. Please install Docker Desktop." exit 1 fi # Build Docker image log_info "Building Docker image..." npx muspe deploy docker --release # Get version from package.json VERSION=$(node -p "require('./package.json').version") # Build and tag image docker build -t "$IMAGE_NAME:latest" . docker tag "$IMAGE_NAME:latest" "$IMAGE_NAME:$VERSION" if [ -n "$DOCKER_USERNAME" ] && [ "$DOCKER_USERNAME" != "your-username" ]; then docker tag "$IMAGE_NAME:latest" "$DOCKER_REGISTRY/$DOCKER_USERNAME/$IMAGE_NAME:latest" docker tag "$IMAGE_NAME:latest" "$DOCKER_REGISTRY/$DOCKER_USERNAME/$IMAGE_NAME:$VERSION" fi log_success "Docker image built successfully" # Push to registry (if credentials are available) if [ -n "$DOCKER_PASSWORD" ] && [ -n "$DOCKER_USERNAME" ] && [ "$DOCKER_USERNAME" != "your-username" ]; then log_info "Logging in to Docker registry..." echo "$DOCKER_PASSWORD" | docker login "$DOCKER_REGISTRY" -u "$DOCKER_USERNAME" --password-stdin log_info "Pushing images to registry..." docker push "$DOCKER_REGISTRY/$DOCKER_USERNAME/$IMAGE_NAME:latest" docker push "$DOCKER_REGISTRY/$DOCKER_USERNAME/$IMAGE_NAME:$VERSION" log_success "Images pushed to registry" else log_info "Manual push required:" echo " docker login $DOCKER_REGISTRY" echo " docker push $DOCKER_REGISTRY/$DOCKER_USERNAME/$IMAGE_NAME:latest" echo " docker push $DOCKER_REGISTRY/$DOCKER_USERNAME/$IMAGE_NAME:$VERSION" fi # Test container log_info "Testing container..." CONTAINER_ID=$(docker run -d -p 3000:3000 "$IMAGE_NAME:latest") # Wait for container to start sleep 5 # Health check if curl -f http://localhost:3000/health > /dev/null 2>&1; then log_success "Container health check passed" else log_error "Container health check failed" fi # Stop test container docker stop "$CONTAINER_ID" docker rm "$CONTAINER_ID" log_success "Docker deployment completed!" echo "" echo "🚀 Ready to deploy:" echo " docker run -d -p 80:80 -p 443:443 $IMAGE_NAME:latest" echo "" echo "📋 Or use docker-compose:" echo " docker-compose up -d"