2 set -o nounset # Treat unset variables as an error and immediately exit
3 set -o errexit # If a command fails exit the whole script
5 if [ "${DEBUG:-false}" = "true" ]; then
6 set -x # Run the entire script in debug mode
10 echo "usage: $(basename "$0") <new-formula-name>" 1>&2
12 echo "Convert template-formula to <new-formula-name>-formula." 1>&2
13 echo "<new-formula-name> should be a string of lowercase characters and numbers only." 1>&2
14 echo "<new-formula-name> should not be any of 'bin' 'docs' 'test'." 1>&2
23 if echo "$NEW_NAME" | grep -E --quiet --invert-match '^[a-z0-9]+$'; then
27 if echo bin docs test | grep --quiet --word-regexp "$NEW_NAME"; then
34 # Empty history and make commit message `semantic-release`-compliant
35 # Works for forks of `template-formula` as well as GitHub "Use this template"
36 # See https://stackoverflow.com/a/15572071/5009408
38 "$(echo 'feat: initial commit' \
39 | git commit-tree 'HEAD^{tree}')"
40 git rm --quiet bin/convert-formula.sh AUTHORS.md CHANGELOG.md \
41 docs/_static/css/custom.css docs/AUTHORS.rst docs/CHANGELOG.rst \
42 docs/conf.py docs/CONTRIBUTING_DOCS.rst docs/index.rst
43 git mv TEMPLATE "${NEW_NAME}"
44 grep --recursive --files-with-matches --exclude-dir=.git TEMPLATE . \
45 | xargs -L 1 ex -u NONE -sc '%s/TEMPLATE/'"${NEW_NAME}"'/g|x'
46 # Searching across multiple lines.
47 # See https://vim.fandom.com/wiki/Search_across_multiple_lines
48 ex -u NONE -sc '%s/^.. <REMOVEME\_.\{-}.. REMOVEME>/None/g|x' docs/README.rst
49 ex -u NONE -sc '%s/^\s*# <REMOVEME\_.\{-}# REMOVEME>\n//g|x' .travis.yml
50 ex -u NONE -sc '%s/^\s*# <REMOVEME\_.\{-}# REMOVEME>\n//g|x' .rubocop.yml
51 ex -u NONE -sc '%s/^\(version:\).*/\1 1.0.0/g|x' FORMULA
52 # shellcheck disable=SC2016 # Expressions don't expand in single quotes
53 git commit --quiet --all \
54 --message 'feat: convert `template-formula` to `'"${NEW_NAME}"'-formula`' \
55 --message 'BREAKING CHANGE: changed all state names and ids'