|
| 1 | +#!/usr/bin/env bash |
| 2 | +overwrite_template_dir=0 |
| 3 | + |
| 4 | +while getopts t:o flag |
| 5 | +do |
| 6 | + case "${flag}" in |
| 7 | + t) template=${OPTARG};; |
| 8 | + o) overwrite_template_dir=1;; |
| 9 | + esac |
| 10 | +done |
| 11 | + |
| 12 | +if [ -z "${template}" ]; then |
| 13 | + echo "Available templates: flask" |
| 14 | + read -p "Enter template name: " template |
| 15 | +fi |
| 16 | + |
| 17 | +repo_urlname=$(basename -s .git `git config --get remote.origin.url`) |
| 18 | +repo_name=$(basename -s .git `git config --get remote.origin.url` | tr '-' '_' | tr '[:upper:]' '[:lower:]') |
| 19 | +repo_owner=$(git config --get remote.origin.url | awk -F ':' '{print $2}' | awk -F '/' '{print $1}') |
| 20 | +echo "Repo name: ${repo_name}" |
| 21 | +echo "Repo owner: ${repo_owner}" |
| 22 | +echo "Repo urlname: ${repo_urlname}" |
| 23 | + |
| 24 | +if [ -f ".github/workflows/rename_project.yml" ]; then |
| 25 | + .github/rename_project.sh -a "${repo_owner}" -n "${repo_name}" -u "${repo_urlname}" -d "Awesome ${repo_name} created by ${repo_owner}" |
| 26 | +fi |
| 27 | + |
| 28 | +function download_template { |
| 29 | + rm -rf "${template_dir}" |
| 30 | + mkdir -p .github/templates |
| 31 | + git clone "${template_url}" "${template_dir}" |
| 32 | +} |
| 33 | + |
| 34 | +echo "Using template:${template}" |
| 35 | +template_url="https://github.com/rochacbruno/${template}-project-template" |
| 36 | +template_dir=".github/templates/${template}" |
| 37 | +if [ -d "${template_dir}" ]; then |
| 38 | + # Template directory already exists |
| 39 | + if [ "${overwrite_template_dir}" -eq 1 ]; then |
| 40 | + # user passed -o flag, delete and re-download |
| 41 | + echo "Overwriting ${template_dir}" |
| 42 | + download_template |
| 43 | + else |
| 44 | + # Ask user if they want to overwrite |
| 45 | + echo "Directory ${template_dir} already exists." |
| 46 | + read -p "Do you want to overwrite it? [y/N] " -n 1 -r |
| 47 | + echo |
| 48 | + if [[ $REPLY =~ ^[Yy]$ ]]; then |
| 49 | + echo "Overwriting ${template_dir}" |
| 50 | + download_template |
| 51 | + else |
| 52 | + # User decided not to overwrite |
| 53 | + echo "Using existing ${template_dir}" |
| 54 | + fi |
| 55 | + fi |
| 56 | +else |
| 57 | + # Template directory does not exist, download it |
| 58 | + echo "Downloading ${template_url}" |
| 59 | + download_template |
| 60 | +fi |
| 61 | + |
| 62 | +echo "Applying ${template} template to this project"} |
| 63 | +./.github/templates/${template}/apply.sh -a "${repo_owner}" -n "${repo_name}" -u "${repo_urlname}" -d "Awesome ${repo_name} created by ${repo_owner}" |
| 64 | + |
| 65 | +# echo "Removing temporary template files" |
| 66 | +# rm -rf .github/templates/${template} |
| 67 | + |
| 68 | +echo "Done! review, commit and push the changes" |
0 commit comments