only build when needed improvement
This commit is contained in:
@@ -1,12 +1,45 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
upload() {
|
upload() {
|
||||||
sh local-remote.sh --dry-run | grep -E "(\.less|\.js|\.vue|\.css)"
|
if needs_build; then
|
||||||
|
echo "Running build..."
|
||||||
if [ $? -eq 0 ]; then
|
if npm run build; then
|
||||||
echo "Changes detected in build files - running build..."
|
# Update cache file timestamp
|
||||||
npm run build && sh local-remote.sh
|
touch "$CACHE_FILE"
|
||||||
|
sh local-remote.sh
|
||||||
|
else
|
||||||
|
echo "Build failed, skipping upload"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "No build files changed - uploading directly..."
|
echo "No build required - uploading directly..."
|
||||||
sh local-remote.sh
|
sh local-remote.sh
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -18,4 +51,4 @@ fi
|
|||||||
|
|
||||||
sh "remote-local.sh"
|
sh "remote-local.sh"
|
||||||
|
|
||||||
watchexec --debounce 2s -w . 'sh watch-build.sh --upload'
|
watchexec --debounce 1s -w . 'sh watch-build.sh --upload'
|
||||||
|
|||||||
Reference in New Issue
Block a user