Skip to content
This repository was archived by the owner on May 26, 2025. It is now read-only.

Commit b7f7c3b

Browse files
authored
template is external (#8)
1 parent 0fe228c commit b7f7c3b

32 files changed

Lines changed: 84 additions & 509 deletions

.github/init.sh

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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"

.github/rename_project.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ original_author="author_name"
2020
original_name="project_name"
2121
original_urlname="project_urlname"
2222
original_description="project_description"
23-
24-
2523
# for filename in $(find . -name "*.*")
2624
for filename in $(git ls-files)
2725
do
@@ -34,6 +32,7 @@ done
3432

3533
mv project_name $name
3634

37-
# This command runs only once!
38-
rm -rf .github/rename_project.sh
39-
rm -rf .github/workflows/rename_project.yml
35+
# This command runs only once on GHA!
36+
if [ -f .github/workflows/project_name.yml ]; then
37+
mv .github/workflows/rename_project.yml .github/workflows/rename_project.yml.disabled
38+
fi

.github/templates/flask/.env

Lines changed: 0 additions & 2 deletions
This file was deleted.

.github/templates/flask/README.md

Lines changed: 0 additions & 60 deletions
This file was deleted.

.github/templates/flask/apply.sh

Lines changed: 0 additions & 46 deletions
This file was deleted.

.github/templates/flask/module/VERSION

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/templates/flask/module/__init__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

.github/templates/flask/module/__main__.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

.github/templates/flask/module/base.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

.github/templates/flask/module/ext/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)