198 lines
4.7 KiB
Bash
Executable File
198 lines
4.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# ServerManager Pro - Production Build for Linux & Windows
|
|
# Version: 2.0.0
|
|
|
|
set -e
|
|
|
|
# Colors
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
RED='\033[0;31m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m'
|
|
|
|
APP_NAME="ServerManager Pro"
|
|
VERSION=$(node -p "require('./package.json').version")
|
|
|
|
echo -e "${BLUE}=== $APP_NAME - Production Build ===${NC}"
|
|
echo -e "${GREEN}Version: $VERSION${NC}"
|
|
echo "======================================"
|
|
|
|
print_status() { echo -e "${BLUE}[$(date +%H:%M:%S)]${NC} $1"; }
|
|
print_success() { echo -e "${GREEN}✅ $1${NC}"; }
|
|
print_warning() { echo -e "${YELLOW}⚠️ $1${NC}"; }
|
|
print_error() { echo -e "${RED}❌ $1${NC}"; }
|
|
|
|
# Check environment
|
|
check_environment() {
|
|
print_status "Checking environment..."
|
|
|
|
if [ ! -f "package.json" ]; then
|
|
print_error "package.json not found. Run from project root."
|
|
exit 1
|
|
fi
|
|
|
|
if ! command -v node >/dev/null; then
|
|
print_error "Node.js not installed"
|
|
exit 1
|
|
fi
|
|
|
|
print_success "Environment check passed"
|
|
}
|
|
|
|
# Clean builds
|
|
clean_builds() {
|
|
print_status "Cleaning previous builds..."
|
|
rm -rf build dist
|
|
print_success "Clean completed"
|
|
}
|
|
|
|
# Install dependencies
|
|
install_deps() {
|
|
print_status "Installing dependencies..."
|
|
|
|
if [ ! -d "node_modules" ]; then
|
|
npm install
|
|
else
|
|
npm install
|
|
fi
|
|
|
|
print_success "Dependencies installed"
|
|
}
|
|
|
|
# Build React app
|
|
build_react() {
|
|
print_status "Building React application..."
|
|
npm run build
|
|
|
|
if [ ! -d "build" ]; then
|
|
print_error "React build failed"
|
|
exit 1
|
|
fi
|
|
|
|
print_success "React app built"
|
|
}
|
|
|
|
# Create icon if missing
|
|
create_icon() {
|
|
if [ ! -f "public/icon.png" ]; then
|
|
print_status "Creating application icon..."
|
|
|
|
if command -v convert >/dev/null; then
|
|
convert -size 512x512 gradient:blue-darkblue -pointsize 100 -fill white -gravity center -annotate +0+0 "SM" public/icon.png
|
|
print_success "Icon created"
|
|
else
|
|
print_warning "ImageMagick not available - using default icon"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
# Build Linux package
|
|
build_linux() {
|
|
print_status "Building Linux package (.deb)..."
|
|
|
|
npx electron-builder --linux deb
|
|
|
|
if ls dist/*.deb >/dev/null 2>&1; then
|
|
DEB_FILE=$(ls dist/*.deb | head -1)
|
|
print_success "Linux package: $(basename $DEB_FILE) ($(du -h $DEB_FILE | cut -f1))"
|
|
return 0
|
|
else
|
|
print_error "Linux package build failed"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Build Windows package
|
|
build_windows() {
|
|
print_status "Building Windows package (.exe)..."
|
|
|
|
npx electron-builder --win
|
|
|
|
if ls dist/*.exe >/dev/null 2>&1; then
|
|
EXE_FILE=$(ls dist/*.exe | head -1)
|
|
print_success "Windows package: $(basename $EXE_FILE) ($(du -h $EXE_FILE | cut -f1))"
|
|
return 0
|
|
else
|
|
print_error "Windows package build failed"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Generate report
|
|
generate_report() {
|
|
echo ""
|
|
echo -e "${GREEN}=== BUILD COMPLETE ===${NC}"
|
|
echo "Version: $VERSION"
|
|
echo "Build date: $(date)"
|
|
echo ""
|
|
|
|
echo -e "${BLUE}Generated Packages:${NC}"
|
|
|
|
# Linux packages
|
|
if ls dist/*.deb >/dev/null 2>&1; then
|
|
echo -e " 🐧 Linux (.deb):"
|
|
ls dist/*.deb | while read file; do
|
|
echo " 📦 $(basename $file) ($(du -h "$file" | cut -f1))"
|
|
done
|
|
else
|
|
echo -e " 🐧 Linux: ❌ Not built"
|
|
fi
|
|
|
|
# Windows packages
|
|
if ls dist/*.exe >/dev/null 2>&1; then
|
|
echo -e " 🪟 Windows (.exe):"
|
|
ls dist/*.exe | while read file; do
|
|
echo " 📦 $(basename $file) ($(du -h "$file" | cut -f1))"
|
|
done
|
|
else
|
|
echo -e " 🪟 Windows: ❌ Not built"
|
|
fi
|
|
|
|
echo ""
|
|
echo -e "${GREEN}Installation Instructions:${NC}"
|
|
echo " Linux: sudo dpkg -i dist/*.deb"
|
|
echo " Windows: Run the .exe file as Administrator"
|
|
echo ""
|
|
echo -e "${YELLOW}Next Steps:${NC}"
|
|
echo " • Test the application on both platforms"
|
|
echo " • Use IT"
|
|
}
|
|
|
|
# Main build process
|
|
main() {
|
|
local platform=${1:-all}
|
|
|
|
case $platform in
|
|
"linux")
|
|
check_environment
|
|
clean_builds
|
|
install_deps
|
|
create_icon
|
|
build_react
|
|
build_linux
|
|
;;
|
|
"windows")
|
|
check_environment
|
|
clean_builds
|
|
install_deps
|
|
create_icon
|
|
build_react
|
|
build_windows
|
|
;;
|
|
"all"|*)
|
|
check_environment
|
|
clean_builds
|
|
install_deps
|
|
create_icon
|
|
build_react
|
|
build_linux
|
|
build_windows
|
|
;;
|
|
esac
|
|
|
|
generate_report
|
|
}
|
|
|
|
main "$@" |