You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bump-js-versions.sh 1.2KB

12345678910111213141516171819202122232425262728293031323334
  1. #!/bin/sh
  2. if ! which git > /dev/null 2>&1 ;then
  3. echo "Cannot find git executable, not bumping js versions."
  4. exit
  5. fi
  6. if ! git status > /dev/null 2>&1 ;then
  7. echo "Not a git repository, not bumping js versions."
  8. exit
  9. fi
  10. # This script finds all js files included from index.html which have been
  11. # modified and bumps their version (the value of the "v" parameter used
  12. # in index.html)
  13. # contents of index.html at HEAD (excluding not-committed changes)
  14. index=`git show HEAD:index.html`
  15. # js files included from index.html. The sort needed for comm
  16. jsfiles=.bump-js-versions-jsfiles.tmp
  17. echo "$index" | grep '<script src=".*"' -o | sed -e 's/<script src="//' | sed -e 's/\?.*//' | tr -d \" | sort > $jsfiles
  18. # modified files since the last commit
  19. gitmodified=.bump-js-versions-gitmodified.tmp
  20. git ls-files -m | sort > $gitmodified
  21. for file in `comm -12 $jsfiles $gitmodified` ;do
  22. old_version=`echo "$index" | grep "<script src=\"${file}?v=[0-9]*" -o | sed -e 's/.*v=//'| tr -d \"`
  23. new_version=$((1+$old_version))
  24. echo Bumping version of $file from $old_version to $new_version
  25. sed -i.tmp -e "s%script src=\"${file}\?v=.*\"%script src=\"$file?v=$new_version\"%" index.html
  26. done
  27. rm -f $jsfiles $gitmodified index.html.tmp