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.0KB

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