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() {
|
||||
sh local-remote.sh --dry-run | grep -E "(\.less|\.js|\.vue|\.css)"
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Changes detected in build files - running build..."
|
||||
npm run build && sh local-remote.sh
|
||||
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 "No build files changed - uploading directly..."
|
||||
echo "Build failed, skipping upload"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "No build required - uploading directly..."
|
||||
sh local-remote.sh
|
||||
fi
|
||||
}
|
||||
@@ -18,4 +51,4 @@ fi
|
||||
|
||||
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