simplify building locally
This commit is contained in:
2
scripts/build-watch.sh
Normal file
2
scripts/build-watch.sh
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
watchexec --debounce 2s -w . "npm run build && sh local-remote.sh"
|
||||||
@@ -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!"
|
|
||||||
@@ -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
|
|
||||||
@@ -121,7 +121,7 @@ echo "{
|
|||||||
echo -e "${GREEN}.vscode/sftp.json created successfully${NC}"
|
echo -e "${GREEN}.vscode/sftp.json created successfully${NC}"
|
||||||
|
|
||||||
# Go through scripts, add variables and add them to project folder
|
# 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
|
for script in "${scripts[@]}"; do
|
||||||
# Add variables to script
|
# Add variables to script
|
||||||
|
|||||||
Reference in New Issue
Block a user