simplify building locally

This commit is contained in:
Leons Aleksandrovs
2025-11-19 09:53:54 +02:00
parent cb9c3113fe
commit 60ea75372b
4 changed files with 10 additions and 122 deletions

2
scripts/build-watch.sh Normal file
View File

@@ -0,0 +1,2 @@
watchexec --debounce 2s -w . "npm run build && sh local-remote.sh"

View File

@@ -1,28 +0,0 @@
# Local paths
LOCAL_PUBLIC="./public"
LOCAL_MANIFEST="./mix-manifest.json"
# Clear screen
clear
# Build assets
echo "Building assets..."
bun run dev
echo "Starting deployment..."
# Sync public folder (js, css, images, etc.)
echo "Syncing public folder..."
sshpass -p "$SERVER_PASSWORD" rsync -avz --progress \
--exclude 'storage' \
--exclude '.htaccess' \
"$LOCAL_PUBLIC/" "$SERVER_USER@$SERVER_HOST:$SERVER_PATHpublic/"
# Upload mix-manifest.json specifically (if not already synced)
echo "Uploading mix-manifest.json..."
sshpass -p "$SERVER_PASSWORD" scp "$LOCAL_MANIFEST" \
"$SERVER_USER@$SERVER_HOST:$SERVER_PATH/mix-manifest.json"
echo "Deployment complete!"

View File

@@ -1,86 +0,0 @@
# Watch and upload script for core assets
# Install: brew install fswatch
# This script monitors the public folder for changes, rebuilds assets, and uploads them to the server
set -e
# Local paths
LOCAL_PUBLIC="./public"
LOCAL_MANIFEST="./mix-manifest.json"
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Trap to kill background processes on script exit
trap cleanup EXIT INT TERM
cleanup() {
echo "${YELLOW}Cleaning up...${NC}"
if [ ! -z "$BUN_PID" ]; then
echo "Killing bun watch process..."
kill $BUN_PID 2>/dev/null || true
wait $BUN_PID 2>/dev/null || true
fi
if [ ! -z "$RSYNC_PID" ]; then
kill $RSYNC_PID 2>/dev/null || true
fi
echo "${GREEN}Cleanup complete${NC}"
}
# Function to upload changes
upload_changes() {
echo "${BLUE}=== Starting upload cycle ===${NC}"
# Sync public folder (js, css, images, etc.)
echo "Syncing public folder..."
sshpass -p "$SERVER_PASSWORD" rsync -avz --progress \
--exclude 'storage' \
--exclude '.htaccess' \
"$LOCAL_PUBLIC/" "$SERVER_USER@$SERVER_HOST:$SERVER_PATHpublic/"
# Upload mix-manifest.json specifically
echo "Uploading mix-manifest.json..."
sshpass -p "$SERVER_PASSWORD" scp "$LOCAL_MANIFEST" \
"$SERVER_USER@$SERVER_HOST:$SERVER_PATH/mix-manifest.json"
echo "${GREEN}Upload complete!${NC}"
}
# Clear screen
clear
# Start bun run watch in background
echo "${BLUE}Starting bun watch...${NC}"
bun run watch &
BUN_PID=$!
echo "${GREEN}Bun watch started (PID: $BUN_PID)${NC}"
echo ""
# Wait a moment for the initial build
sleep 2
# Initial upload
echo "${BLUE}Performing initial upload...${NC}"
upload_changes
echo ""
# Watch for changes in public folder
echo "${BLUE}Watching for changes in $LOCAL_PUBLIC...${NC}"
echo "Press Ctrl+C to stop watching and exit"
echo ""
fswatch -o "$LOCAL_PUBLIC" | while read num; do
# Kill previous pending upload
if [ ! -z "$UPLOAD_PID" ]; then
kill $UPLOAD_PID 2>/dev/null || true
wait $UPLOAD_PID 2>/dev/null || true
fi
# Schedule upload after 0.5 seconds of no changes
(sleep 0.5 && upload_changes) &
UPLOAD_PID=$!
done

View File

@@ -121,19 +121,19 @@ echo "{
echo -e "${GREEN}.vscode/sftp.json created successfully${NC}"
# Go through scripts, add variables and add them to project folder
scripts=("upload-core-build.sh" "watch-core-build.sh" "local-remote.sh" "remote-local.sh" "sftp-watch.sh")
scripts=("build-watch.sh" "local-remote.sh" "remote-local.sh" "sftp-watch.sh")
for script in "${scripts[@]}"; do
# Add variables to script
echo "
#!/bin/bash
set -e
#!/bin/bash
set -e
# Configuration
SERVER_USER=\"${USERNAME}\"
SERVER_HOST=\"${HOST}\"
SERVER_PASSWORD=\"${SSH_PASSWORD}\"
SERVER_PATH=\"${SERVER_PROJECT_PATH}/\"
# Configuration
SERVER_USER=\"${USERNAME}\"
SERVER_HOST=\"${HOST}\"
SERVER_PASSWORD=\"${SSH_PASSWORD}\"
SERVER_PATH=\"${SERVER_PROJECT_PATH}/\"
" > "${script}"
# Append the rest of the upload core build script