Last active
June 28, 2020 21:46
-
-
Save nexxai/1ae56ebe6328167344e0282dc6af2edf to your computer and use it in GitHub Desktop.
Laravel - only 'yarn run production' if JS/CSS assets were changed in the last git commit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Dump the list of filenames changed in the last git commit | |
| git diff --name-only HEAD HEAD~1 > /tmp/gitdiff.txt | |
| # Default to no changes | |
| yarn=false | |
| # Read the /tmp/gitdiff.txt file line by line.... | |
| while read line; do | |
| # The regex to search for CSS/JS/Vue/.lock/JSON files | |
| positiveMatch='^(resources\/|).*(css|js|vue|lock|json)$' | |
| # The regex to ignore the composer.json files and the entire /public folder | |
| negativeMatch='^(composer|public)' | |
| echo $line | |
| # Check to see if any those filetypes are listed | |
| if [[ $line =~ $positiveMatch && ! $line =~ $negativeMatch ]]; then | |
| # ...and if so, set the yarn flag to true | |
| yarn=true; | |
| fi | |
| done < /tmp/gitdiff.txt | |
| # If any changes were detected, run the necessary yarn commands | |
| if $yarn ; then | |
| yarn install --save | |
| yarn run production | |
| fi | |
| # Cleanup | |
| yarn=false | |
| rm /tmp/gitdiff.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment