Skip to content

Commit b0f6529

Browse files
committed
refactor: update template repository setup scripts
- Update SETUP_TEMPLATE.sh with improved script functionality - Refactor FUNCTION_HELPERS.sh for better code organization - Enhance test scripts for better reliability and coverage - Update test runners and argument parsing logic - Improve project scaffolding test cases These changes maintain backward compatibility while improving the overall code quality and test coverage of the template repository.
1 parent d4febbf commit b0f6529

6 files changed

Lines changed: 704 additions & 704 deletions

File tree

SETUP_TEMPLATE.sh

100644100755
Lines changed: 159 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -1,159 +1,159 @@
1-
#!/bin/bash
2-
3-
#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#
4-
# SCRIPT: SETUP_TEMPLATE.sh
5-
# USAGE: bash SETUP_TEMPLATE.sh | ./SETUP_TEMPLATE.sh
6-
# PURPOSE: Shell script that setups the @TuxTechLab/TuxTechLab-Template-Repo GitHub project template.
7-
# It detects the user's GitHub username, email and project name,
8-
# and then prompts for the type of project that it is. All the data can be manually specified using
9-
# the script optional arguments. For more information, please execute the script with the '--help' flag.
10-
# After it will customize all the files with the user's data and remove some files and folders,
11-
# even this own script.
12-
# TITLE: SETUP_TEMPLATE
13-
# AUTHOR: @TuxTechLab
14-
# VERSION: See in CHANGELOG.md or in variable 'SCRIPT_VERSION'.
15-
# NOTES: This script will auto remove itself, and if you want to rerun it, the user must download
16-
# it again or do a 'git stash' and revert the changes.
17-
# BASH_VERSION: 5.1.4(1)-release (x86_64-pc-linux-gnu)
18-
# LICENSE: see in LICENSE (project root) or https://github.com/TuxTechLab/TuxTechLab-Template-Repo/blob/master/LICENSE
19-
# GITHUB: https://github.com/TuxTechLab/
20-
# REPOSITORY: https://github.com/TuxTechLab/TuxTechLab-Template-Repo
21-
# ISSUES: https://github.com/TuxTechLab/TuxTechLab-Template-Repo/issues
22-
# MAIL: root.tuxtechlab@gmail.com
23-
#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#
24-
25-
RED='\033[1;31m' # color red
26-
NAME_AND_PROJECT_UNPARSED=$(git ls-remote --get-url) # READ GITHUB USERNAME AND GITHUB PROJECT NAME
27-
NEW_USERNAME=$(echo "$NAME_AND_PROJECT_UNPARSED" | cut -d':' -f 2 | cut -d'/' -f 1)
28-
PROJECT_NAME=$(echo "$NAME_AND_PROJECT_UNPARSED" | cut -d'/' -f 2 | cut -d'.' -f 1)
29-
NEW_EMAIL=$(git config user.email)
30-
TEMP_TEST_OUTPUT=".ignore.test_output.txt"
31-
PROJECT_TYPE="repository" # default value if not specified
32-
will_omit_verification=false
33-
will_omit_commit=false
34-
will_omit_test=false
35-
SCRIPT_VERSION="1.11.8"
36-
37-
FILE_FUNCTION_HELPERS=bin/FUNCTION_HELPERS.sh
38-
39-
if [ ! -f "$FILE_FUNCTION_HELPERS" ]; then # check if the function helpers file is not found
40-
echo -e "${RED}X Can not find ${FILE_FUNCTION_HELPERS}"
41-
exit 1 # it will exit if the function helpers file is not found
42-
else
43-
# shellcheck source=bin/FUNCTION_HELPERS.sh disable=SC1091
44-
source $FILE_FUNCTION_HELPERS || exit 1 # obtain some global functions and variables, if the file isn't found exit
45-
fi
46-
47-
# PARSE THE ARGUMENTS
48-
for i in "$@"; do
49-
case $i in
50-
-u=* | --user=* | --username=* | --name=*)
51-
NEW_USERNAME="${i#*=}"
52-
shift # past argument=value
53-
;;
54-
-p=* | --project=* | --project-name=* | --project_name=* | --projectName=*)
55-
PROJECT_NAME="${i#*=}"
56-
shift # past argument=value
57-
;;
58-
-e=* | --email=* | --mail=*)
59-
NEW_EMAIL="${i#*=}"
60-
shift # past argument=value
61-
;;
62-
-t=* | --type=* | --project_type=* | --projectType=*)
63-
PROJECT_TYPE="${i#*=}"
64-
shift # past argument=value
65-
;;
66-
-h | --help | --info | --information)
67-
displayHelpTexts
68-
exit 0
69-
shift # past argument=value
70-
;;
71-
-v | --version)
72-
echo -e "${GREEN}$SCRIPT_VERSION${NC}"
73-
exit 0
74-
shift # past argument=value
75-
;;
76-
-o | --omit | --omit-commit-and-confirmation)
77-
echo -e "${BBLUE}X Deprecated:${NC} The arguments '--omit-commit-and-confirmation', '-o' and '--omit' are ${RED}deprecated${NC}. Use '--omit-verification' and/or ' --omit-commit' instead."
78-
will_omit_verification=true
79-
will_omit_commit=true
80-
choice="y"
81-
shift # past argument with no value
82-
;;
83-
--omit-verification)
84-
will_omit_verification=true
85-
choice="y"
86-
shift # past argument with no value
87-
;;
88-
--omit-commit)
89-
will_omit_commit=true
90-
shift # past argument with no value
91-
;;
92-
--omit-test-check | --omit-tests-check | --omit-tests)
93-
will_omit_test=true
94-
shift # past argument with no value
95-
;;
96-
*) # unknown option
97-
echo -e "${RED}X Unknown option:${NC} '${i}', type the flag '${BBLUE}--help${NC}' to view all the options and flags."
98-
;;
99-
esac
100-
done
101-
102-
echo -e "Thanks for using ${GREEN}@TuxTechLab/TuxTechLab-Template-Repo${NC}"
103-
echo -e "Read all the documentation carefully before you continue executing this script: ${UPURPLE}https://github.com/TuxTechLab/TuxTechLab-Template-Repo${NC}\n"
104-
105-
bash tests/TESTS_RUNNER.sh >/dev/null 2>&1 # PERFORM the TESTS
106-
107-
if [ "$?" -eq 1 ] && [ $will_omit_test = false ]; then # if when running the tests any error was found
108-
rm "$TEMP_TEST_OUTPUT" 2>/dev/null || :
109-
displayTestErrorTexts
110-
exit 1
111-
fi
112-
113-
rm "$TEMP_TEST_OUTPUT" 2>/dev/null || :
114-
115-
if [ "$PROJECT_TYPE" = "repository" ]; then # if the project's type has not been manually specified
116-
read -p "Enter $(echo -e "$BBLUE""what your project is""$NC") (program/extension/API/web/CLI tool/backend/frontend/scrapper/automation tool/etc): " PROJECT_TYPE
117-
fi
118-
119-
if [ $will_omit_verification = false ]; then # if the ignore flag has not been manually specified
120-
read -p "Is this data correct: username \"$(echo -e "$GREEN""$NEW_USERNAME""$NC")\", email: \"$(echo -e "$GREEN""$NEW_EMAIL""$NC")\", project name: \"$(echo -e "$GREEN""$PROJECT_NAME""$NC")\", of type: \"$(echo -e "$GREEN""$PROJECT_TYPE""$NC")\" (y/n)? " choice
121-
fi
122-
123-
# confirm that the data is correct
124-
case "$choice" in
125-
y | Y)
126-
center "Setting everything up for you ;)"
127-
128-
# replace the username and email
129-
find .github/ -type f -name "*" -print0 | xargs -0 sed -i "s/TuxTechLab/${NEW_USERNAME}/g"
130-
find .github/ -type f -name "*" -print0 | xargs -0 sed -i "s/root.tuxtechlab@gmail.com/${NEW_EMAIL}/g"
131-
find .github/ -type f -name "*" -print0 | xargs -0 sed -i "s/project-template/${PROJECT_NAME}/g"
132-
find .gitignore -type f -name "*" -print0 | xargs -0 sed -i "s/TuxTechLab\/project-template/${NEW_USERNAME}\/${PROJECT_NAME}/g"
133-
134-
rm LICENSE 2>/dev/null || : # remove the license
135-
rm -r bin/ 2>/dev/null || : # remove the bin folder
136-
rm -r tests/ 2>/dev/null || : # remove the tests folder
137-
rm -r .github/workflows/ 2>/dev/null || : # remove the workflow folder
138-
writeREADME # write the new README.md
139-
writeCHANGELOG # write the basic structure of the CHANGELOG.md
140-
echo -e "# add your own funding links" >.github/FUNDING.yml # remove author's custom funding links
141-
142-
if [ $will_omit_commit = false ]; then # if the ignore option for tests has been specified
143-
git add CHANGELOG.md README.md .gitignore .github SETUP_TEMPLATE.sh LICENSE bin tests # commit the new files
144-
git -c color.status=always status | less -REX # show git status with colours
145-
echo -e "Committing the changes for you :)\n"
146-
git commit -m "📝 Set up '@TuxTechLab/TuxTechLab-Template-Repo' template: Personalized files by executing the SETUP_TEMPLATE.sh script.🚀"
147-
echo -e "\nRemember to review every file and customize it as you like.\nYou are ready to start your brand new awesome project🚀🚀." else
148-
fi
149-
150-
# self remove this script
151-
rm -- "$0" 2>/dev/null || :
152-
;;
153-
n | N)
154-
echo -e "\nIf your username, project name or email were NOT right, you can manually change them. Read how to do it with the script's help: ${UPURPLE}bash SETUP_TEMPLATE.sh --help${NC}\n"
155-
;;
156-
*) echo -e "${RED}X Invalid option${NC}" ;;
157-
esac
158-
159-
exit 0
1+
#!/bin/bash
2+
3+
#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#
4+
# SCRIPT: SETUP_TEMPLATE.sh
5+
# USAGE: bash SETUP_TEMPLATE.sh | ./SETUP_TEMPLATE.sh
6+
# PURPOSE: Shell script that setups the @TuxTechLab/TuxTechLab-Template-Repo GitHub project template.
7+
# It detects the user's GitHub username, email and project name,
8+
# and then prompts for the type of project that it is. All the data can be manually specified using
9+
# the script optional arguments. For more information, please execute the script with the '--help' flag.
10+
# After it will customize all the files with the user's data and remove some files and folders,
11+
# even this own script.
12+
# TITLE: SETUP_TEMPLATE
13+
# AUTHOR: @TuxTechLab
14+
# VERSION: See in CHANGELOG.md or in variable 'SCRIPT_VERSION'.
15+
# NOTES: This script will auto remove itself, and if you want to rerun it, the user must download
16+
# it again or do a 'git stash' and revert the changes.
17+
# BASH_VERSION: 5.1.4(1)-release (x86_64-pc-linux-gnu)
18+
# LICENSE: see in LICENSE (project root) or https://github.com/TuxTechLab/TuxTechLab-Template-Repo/blob/master/LICENSE
19+
# GITHUB: https://github.com/TuxTechLab/
20+
# REPOSITORY: https://github.com/TuxTechLab/TuxTechLab-Template-Repo
21+
# ISSUES: https://github.com/TuxTechLab/TuxTechLab-Template-Repo/issues
22+
# MAIL: root.tuxtechlab@gmail.com
23+
#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#
24+
25+
RED='\033[1;31m' # color red
26+
NAME_AND_PROJECT_UNPARSED=$(git ls-remote --get-url) # READ GITHUB USERNAME AND GITHUB PROJECT NAME
27+
NEW_USERNAME=$(echo "$NAME_AND_PROJECT_UNPARSED" | cut -d':' -f 2 | cut -d'/' -f 1)
28+
PROJECT_NAME=$(echo "$NAME_AND_PROJECT_UNPARSED" | cut -d'/' -f 2 | cut -d'.' -f 1)
29+
NEW_EMAIL=$(git config user.email)
30+
TEMP_TEST_OUTPUT=".ignore.test_output.txt"
31+
PROJECT_TYPE="repository" # default value if not specified
32+
will_omit_verification=false
33+
will_omit_commit=false
34+
will_omit_test=false
35+
SCRIPT_VERSION="1.11.8"
36+
37+
FILE_FUNCTION_HELPERS=bin/FUNCTION_HELPERS.sh
38+
39+
if [ ! -f "$FILE_FUNCTION_HELPERS" ]; then # check if the function helpers file is not found
40+
echo -e "${RED}X Can not find ${FILE_FUNCTION_HELPERS}"
41+
exit 1 # it will exit if the function helpers file is not found
42+
else
43+
# shellcheck source=bin/FUNCTION_HELPERS.sh disable=SC1091
44+
source $FILE_FUNCTION_HELPERS || exit 1 # obtain some global functions and variables, if the file isn't found exit
45+
fi
46+
47+
# PARSE THE ARGUMENTS
48+
for i in "$@"; do
49+
case $i in
50+
-u=* | --user=* | --username=* | --name=*)
51+
NEW_USERNAME="${i#*=}"
52+
shift # past argument=value
53+
;;
54+
-p=* | --project=* | --project-name=* | --project_name=* | --projectName=*)
55+
PROJECT_NAME="${i#*=}"
56+
shift # past argument=value
57+
;;
58+
-e=* | --email=* | --mail=*)
59+
NEW_EMAIL="${i#*=}"
60+
shift # past argument=value
61+
;;
62+
-t=* | --type=* | --project_type=* | --projectType=*)
63+
PROJECT_TYPE="${i#*=}"
64+
shift # past argument=value
65+
;;
66+
-h | --help | --info | --information)
67+
displayHelpTexts
68+
exit 0
69+
shift # past argument=value
70+
;;
71+
-v | --version)
72+
echo -e "${GREEN}$SCRIPT_VERSION${NC}"
73+
exit 0
74+
shift # past argument=value
75+
;;
76+
-o | --omit | --omit-commit-and-confirmation)
77+
echo -e "${BBLUE}X Deprecated:${NC} The arguments '--omit-commit-and-confirmation', '-o' and '--omit' are ${RED}deprecated${NC}. Use '--omit-verification' and/or ' --omit-commit' instead."
78+
will_omit_verification=true
79+
will_omit_commit=true
80+
choice="y"
81+
shift # past argument with no value
82+
;;
83+
--omit-verification)
84+
will_omit_verification=true
85+
choice="y"
86+
shift # past argument with no value
87+
;;
88+
--omit-commit)
89+
will_omit_commit=true
90+
shift # past argument with no value
91+
;;
92+
--omit-test-check | --omit-tests-check | --omit-tests)
93+
will_omit_test=true
94+
shift # past argument with no value
95+
;;
96+
*) # unknown option
97+
echo -e "${RED}X Unknown option:${NC} '${i}', type the flag '${BBLUE}--help${NC}' to view all the options and flags."
98+
;;
99+
esac
100+
done
101+
102+
echo -e "Thanks for using ${GREEN}@TuxTechLab/TuxTechLab-Template-Repo${NC}"
103+
echo -e "Read all the documentation carefully before you continue executing this script: ${UPURPLE}https://github.com/TuxTechLab/TuxTechLab-Template-Repo${NC}\n"
104+
105+
bash tests/TESTS_RUNNER.sh >/dev/null 2>&1 # PERFORM the TESTS
106+
107+
if [ "$?" -eq 1 ] && [ $will_omit_test = false ]; then # if when running the tests any error was found
108+
rm "$TEMP_TEST_OUTPUT" 2>/dev/null || :
109+
displayTestErrorTexts
110+
exit 1
111+
fi
112+
113+
rm "$TEMP_TEST_OUTPUT" 2>/dev/null || :
114+
115+
if [ "$PROJECT_TYPE" = "repository" ]; then # if the project's type has not been manually specified
116+
read -p "Enter $(echo -e "$BBLUE""what your project is""$NC") (program/extension/API/web/CLI tool/backend/frontend/scrapper/automation tool/etc): " PROJECT_TYPE
117+
fi
118+
119+
if [ $will_omit_verification = false ]; then # if the ignore flag has not been manually specified
120+
read -p "Is this data correct: username \"$(echo -e "$GREEN""$NEW_USERNAME""$NC")\", email: \"$(echo -e "$GREEN""$NEW_EMAIL""$NC")\", project name: \"$(echo -e "$GREEN""$PROJECT_NAME""$NC")\", of type: \"$(echo -e "$GREEN""$PROJECT_TYPE""$NC")\" (y/n)? " choice
121+
fi
122+
123+
# confirm that the data is correct
124+
case "$choice" in
125+
y | Y)
126+
center "Setting everything up for you ;)"
127+
128+
# replace the username and email
129+
find .github/ -type f -name "*" -print0 | xargs -0 sed -i "s/TuxTechLab/${NEW_USERNAME}/g"
130+
find .github/ -type f -name "*" -print0 | xargs -0 sed -i "s/root.tuxtechlab@gmail.com/${NEW_EMAIL}/g"
131+
find .github/ -type f -name "*" -print0 | xargs -0 sed -i "s/project-template/${PROJECT_NAME}/g"
132+
find .gitignore -type f -name "*" -print0 | xargs -0 sed -i "s/TuxTechLab\/project-template/${NEW_USERNAME}\/${PROJECT_NAME}/g"
133+
134+
rm LICENSE 2>/dev/null || : # remove the license
135+
rm -r bin/ 2>/dev/null || : # remove the bin folder
136+
rm -r tests/ 2>/dev/null || : # remove the tests folder
137+
rm -r .github/workflows/ 2>/dev/null || : # remove the workflow folder
138+
writeREADME # write the new README.md
139+
writeCHANGELOG # write the basic structure of the CHANGELOG.md
140+
echo -e "# add your own funding links" >.github/FUNDING.yml # remove author's custom funding links
141+
142+
if [ $will_omit_commit = false ]; then # if the ignore option for tests has been specified
143+
git add CHANGELOG.md README.md .gitignore .github SETUP_TEMPLATE.sh LICENSE bin tests # commit the new files
144+
git -c color.status=always status | less -REX # show git status with colours
145+
echo -e "Committing the changes for you :)\n"
146+
git commit -m "📝 Set up '@TuxTechLab/TuxTechLab-Template-Repo' template: Personalized files by executing the SETUP_TEMPLATE.sh script.🚀"
147+
echo -e "\nRemember to review every file and customize it as you like.\nYou are ready to start your brand new awesome project🚀🚀." else
148+
fi
149+
150+
# self remove this script
151+
rm -- "$0" 2>/dev/null || :
152+
;;
153+
n | N)
154+
echo -e "\nIf your username, project name or email were NOT right, you can manually change them. Read how to do it with the script's help: ${UPURPLE}bash SETUP_TEMPLATE.sh --help${NC}\n"
155+
;;
156+
*) echo -e "${RED}X Invalid option${NC}" ;;
157+
esac
158+
159+
exit 0

0 commit comments

Comments
 (0)