add watch-core-build script that watches locally build and uploads
This commit is contained in:
@@ -121,7 +121,6 @@ echo "{
|
||||
echo -e "${GREEN}.vscode/sftp.json created successfully${NC}"
|
||||
|
||||
# Add upload core build script
|
||||
|
||||
# Add variables to upload core script
|
||||
echo "
|
||||
#!/bin/bash
|
||||
@@ -137,4 +136,22 @@ SERVER_PATH=\"${SERVER_PROJECT_PATH}/public\" # Public folders location on serve
|
||||
# Append the rest of the upload core build script
|
||||
cat "${SCRIPT_DIR}/upload-core-build.sh" >> upload-core-build.sh
|
||||
|
||||
echo -e "${GREEN}upload-core-build.sh created successfully${NC}"
|
||||
echo -e "${GREEN}upload-core-build.sh created successfully${NC}"
|
||||
|
||||
# Add watch core build script
|
||||
# Add variables to upload core script
|
||||
echo "
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Configuration
|
||||
SERVER_USER=\"${USERNAME}\"
|
||||
SERVER_HOST=\"${HOST}\"
|
||||
SERVER_PASSWORD=\"${SSH_PASSWORD}\"
|
||||
SERVER_PATH=\"${SERVER_PROJECT_PATH}/public\" # Public folders location on server
|
||||
" > watch-core-build.sh
|
||||
|
||||
# Append the rest of the watch core build script
|
||||
cat "${SCRIPT_DIR}/watch-core-build.sh" >> watch-core-build.sh
|
||||
|
||||
echo -e "${GREEN}watch-core-build.sh created successfully${NC}"
|
||||
86
watch-core-build.sh
Normal file
86
watch-core-build.sh
Normal file
@@ -0,0 +1,86 @@
|
||||
|
||||
# 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_PATH/"
|
||||
|
||||
# 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
|
||||
Reference in New Issue
Block a user