rename.sh 946 B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/env bash
  2. # https://gist.github.com/vncsna/64825d5609c146e80de8b1fd623011ca
  3. set -euo pipefail
  4. # Define the input vars
  5. GITHUB_REPOSITORY=${1?Error: Please pass username/repo, e.g. prb/hardhat-template}
  6. GITHUB_REPOSITORY_OWNER=${2?Error: Please pass username, e.g. prb}
  7. echo "GITHUB_REPOSITORY: $GITHUB_REPOSITORY"
  8. echo "GITHUB_REPOSITORY_OWNER: $GITHUB_REPOSITORY_OWNER"
  9. # jq is like sed for JSON data
  10. JQ_OUTPUT=`jq \
  11. --arg NAME "@$GITHUB_REPOSITORY" \
  12. --arg AUTHOR_NAME "$GITHUB_REPOSITORY_OWNER" \
  13. --arg URL "https://github.com/$GITHUB_REPOSITORY_OWNER" \
  14. '.name = $NAME | .description = "" | .author |= ( .name = $AUTHOR_NAME | .url = $URL )' \
  15. package.json
  16. `
  17. # Overwrite package.json
  18. echo "$JQ_OUTPUT" > package.json
  19. # Rename instances of "paulrberg/hardhat-template" to the new repo name in README.md for badges only
  20. sed -i -e "/Use this template/! s|paulrberg/hardhat-template|"${GITHUB_REPOSITORY}"|;" "README.md"