1+ #! /bin/bash
2+
3+ # package.sh - Build and package FileFlow for all supported platforms
4+ # Usage: ./package.sh [version]
5+
6+ set -e # Exit on any error
7+
8+ VERSION=${1:- " unknown" }
9+
10+ # Define variables
11+ PROJECT_NAME=" FileFlow"
12+ BUILD_DIR=" build"
13+ DIST_DIR=" web/dist"
14+
15+ # Function to check if Node.js is installed
16+ check_node () {
17+ if command -v node > /dev/null 2>&1 ; then
18+ NODE_VERSION=$( node --version)
19+ echo " Node.js is already installed: $NODE_VERSION "
20+ return 0
21+ else
22+ echo " Node.js is not installed"
23+ return 1
24+ fi
25+ }
26+
27+ # Function to install Node.js 24
28+ install_node () {
29+ echo " Installing Node.js 24..."
30+
31+ # Detect OS
32+ if [[ " $OSTYPE " == " linux-gnu" * ]]; then
33+ # Install using NodeSource repository for Ubuntu/Debian
34+ curl -fsSL https://deb.nodesource.com/setup_24.x | sudo -E bash -
35+ sudo apt-get install -y nodejs
36+ elif [[ " $OSTYPE " == " darwin" * ]]; then
37+ # On macOS, use Homebrew
38+ if ! command -v brew > /dev/null 2>&1 ; then
39+ echo " Homebrew is not installed. Please install Homebrew first: https://brew.sh/"
40+ exit 1
41+ fi
42+ brew install node@24
43+ else
44+ echo " Unsupported OS. Please install Node.js 24 manually."
45+ exit 1
46+ fi
47+
48+ # Verify installation
49+ if command -v node > /dev/null 2>&1 ; then
50+ NODE_VERSION=$( node --version)
51+ echo " Node.js successfully installed: $NODE_VERSION "
52+ else
53+ echo " Failed to install Node.js"
54+ exit 1
55+ fi
56+ }
57+
58+ # Function to check if pnpm is installed
59+ check_pnpm () {
60+ if command -v pnpm > /dev/null 2>&1 ; then
61+ PNPM_VERSION=$( pnpm --version)
62+ echo " pnpm is already installed: $PNPM_VERSION "
63+ return 0
64+ else
65+ echo " pnpm is not installed"
66+ return 1
67+ fi
68+ }
69+
70+ # Function to install pnpm
71+ install_pnpm () {
72+ echo " Installing pnpm..."
73+ npm install -g pnpm
74+
75+ if command -v pnpm > /dev/null 2>&1 ; then
76+ PNPM_VERSION=$( pnpm --version)
77+ echo " pnpm successfully installed: $PNPM_VERSION "
78+ else
79+ echo " Failed to install pnpm"
80+ exit 1
81+ fi
82+ }
83+
84+ # Function to check if Rust is installed
85+ check_rust () {
86+ if command -v rustc > /dev/null 2>&1 ; then
87+ RUST_VERSION=$( rustc --version)
88+ echo " Rust is already installed: $RUST_VERSION "
89+ return 0
90+ else
91+ echo " Rust is not installed"
92+ return 1
93+ fi
94+ }
95+
96+ # Function to install Rust
97+ install_rust () {
98+ echo " Installing Rust..."
99+ curl --proto ' =https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
100+
101+ # Source cargo environment
102+ source " $HOME /.cargo/env"
103+
104+ if command -v rustc > /dev/null 2>&1 ; then
105+ RUST_VERSION=$( rustc --version)
106+ echo " Rust successfully installed: $RUST_VERSION "
107+ else
108+ echo " Failed to install Rust"
109+ exit 1
110+ fi
111+ }
112+
113+ # Function to check if mingw-w64 is installed (needed for Windows cross-compilation)
114+ check_mingw_w64 () {
115+ if command -v x86_64-w64-mingw32-gcc > /dev/null 2>&1 ; then
116+ echo " mingw-w64 is already installed"
117+ return 0
118+ else
119+ echo " mingw-w64 is not installed"
120+ return 1
121+ fi
122+ }
123+
124+ # Function to install mingw-w64
125+ install_mingw_w64 () {
126+ echo " Installing mingw-w64..."
127+
128+ # Detect OS
129+ if [[ " $OSTYPE " == " linux-gnu" * ]]; then
130+ # Install mingw-w64 for Ubuntu/Debian
131+ sudo apt-get update
132+ sudo apt-get install -y mingw-w64
133+ elif [[ " $OSTYPE " == " darwin" * ]]; then
134+ # On macOS, use Homebrew
135+ if ! command -v brew > /dev/null 2>&1 ; then
136+ echo " Homebrew is not installed. Please install Homebrew first: https://brew.sh/"
137+ exit 1
138+ fi
139+ brew install mingw-w64
140+ else
141+ echo " Unsupported OS. Please install mingw-w64 manually."
142+ exit 1
143+ fi
144+
145+ # Verify installation
146+ if command -v x86_64-w64-mingw32-gcc > /dev/null 2>&1 ; then
147+ echo " mingw-w64 successfully installed"
148+ else
149+ echo " Failed to install mingw-w64"
150+ exit 1
151+ fi
152+ }
153+
154+ # Check and install Node.js if needed
155+ echo " Checking Node.js installation..."
156+ if ! check_node; then
157+ install_node
158+ fi
159+
160+ # Check and install pnpm if needed
161+ echo " Checking pnpm installation..."
162+ if ! check_pnpm; then
163+ install_pnpm
164+ fi
165+
166+ # Check and install Rust if needed
167+ echo " Checking Rust installation..."
168+ if ! check_rust; then
169+ install_rust
170+ # Source cargo environment for current session
171+ source " $HOME /.cargo/env"
172+ fi
173+
174+ # Check and install mingw-w64 if needed (for Windows cross-compilation)
175+ echo " Checking mingw-w64 installation (needed for Windows cross-compilation)..."
176+ if ! check_mingw_w64; then
177+ install_mingw_w64
178+ fi
179+
180+ # Create build directory
181+ echo " Creating build directory..."
182+ mkdir -p " ${BUILD_DIR} "
183+
184+ # Build frontend first
185+ echo " Building frontend..."
186+ cd web
187+ pnpm install
188+ pnpm build-only
189+ cd ..
190+
191+ # Function to package for a specific platform
192+ package_for_platform () {
193+ local target=$1
194+ local platform_name=$2
195+ local output_name=" ${PROJECT_NAME} -${platform_name} "
196+
197+ echo " Packaging for ${platform_name} (${target} )..."
198+
199+ # Use cross for cross-compilation
200+ cd server
201+ rustup target add " ${target} " 2> /dev/null || true
202+ cargo build --release --target " ${target} "
203+ cd ..
204+
205+ # Copy binary directly to build directory with platform-specific name
206+ if [[ " ${platform_name} " == * " windows" * ]]; then
207+ cp " server/target/${target} /release/FileFlow.exe" " ${BUILD_DIR} /${output_name} .exe" 2> /dev/null || \
208+ cp " server/target/${target} /release/file_flow.exe" " ${BUILD_DIR} /${output_name} .exe" 2> /dev/null || \
209+ cp " server/target/${target} /release/FileFlow" " ${BUILD_DIR} /${output_name} .exe"
210+ else
211+ cp " server/target/${target} /release/FileFlow" " ${BUILD_DIR} /${output_name} " 2> /dev/null || \
212+ cp " server/target/${target} /release/file_flow" " ${BUILD_DIR} /${output_name} "
213+ fi
214+
215+ echo " Created ${BUILD_DIR} /${output_name} "
216+ }
217+
218+ # Package for all platforms
219+ echo " Starting packaging process for version: ${VERSION} "
220+
221+ # Linux packaging
222+ package_for_platform " x86_64-unknown-linux-musl" " linux-x86_64"
223+
224+ # Windows packaging
225+ package_for_platform " x86_64-pc-windows-gnu" " windows-x86_64"
226+
227+ echo " All packages created successfully in ${BUILD_DIR} /"
0 commit comments