Files
mtc-project-sync-script/scripts/build-watch.sh

55 lines
1.2 KiB
Bash
Raw Normal View History

2025-11-21 11:28:50 +02:00
#!/bin/bash
2025-11-19 09:53:54 +02:00
2025-11-21 11:28:50 +02:00
CACHE_FILE=".build-cache"
needs_build() {
# If cache file doesn't exist, require build
if [ ! -f "$CACHE_FILE" ]; then
echo "Build required: first run"
return 0
fi
# Get all changed files from git
changed_files=$(git status --porcelain | awk '{print $NF}')
if [ -z "$changed_files" ]; then
return 1
fi
# Check if any changed file is a build source file and newer than cache
while IFS= read -r file; do
if [[ "$file" =~ \.(js|vue|less|css)$ ]] && [ -f "$file" ] && [ "$file" -nt "$CACHE_FILE" ]; then
echo "Build required: $file changed"
return 0
fi
done <<< "$changed_files"
2025-11-21 10:49:49 +02:00
2025-11-21 11:28:50 +02:00
return 1
}
upload() {
if needs_build; then
echo "Running build..."
if npm run build; then
# Update cache file timestamp
touch "$CACHE_FILE"
sh local-remote.sh
else
echo "Build failed, skipping upload"
exit 1
fi
2025-11-21 10:49:49 +02:00
else
2025-11-21 11:28:50 +02:00
echo "No build required - uploading directly..."
2025-11-21 10:49:49 +02:00
sh local-remote.sh
fi
}
if [ "$1" = "--upload" ]; then
upload
exit 0
fi
sh "remote-local.sh"
2025-11-21 11:28:50 +02:00
watchexec --debounce 1s -w . 'sh watch-build.sh --upload'