-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmantra.sh
executable file
·103 lines (84 loc) · 4.04 KB
/
mantra.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
#DEFAULT VALUES
projectsDirectory=~/IdeaProjects
author="Adam Michalak"
author_mail="[email protected]"
repoUrl="github.com\/michalakadam"
groupDomain="dev.michalak.adam"
groupProjectDirectory="dev/michalak/adam"
#ask for project name
correctInputFlag=0
while [[ "$correctInputFlag" -eq 0 ]]; do
read -p "Name of the project: " projectName
if [[ -z "$projectName" ]]; then
echo "No arguments, try again."
else
correctInputFlag=$(( correctInputFlag+1 ))
fi
done
projectNameLowerCase=$(echo "$projectName" | tr '[:upper:]' '[:lower:]')
#create project folder if it does not already exist
if [[ -d "$projectsDirectory"/"$projectName" ]]; then
echo "Project with such a name already exist. Terminating..."
exit 1
else
mkdir -p "$projectsDirectory"/"$projectName"
fi
printf "Project directory successfully created.\n\n"
read -p "Feed me short project description: " description
#create tree-like maven structure
mkdir -p "$projectsDirectory"/"$projectName"/src/{main,test}/java/"$groupProjectDirectory"/"${projectNameLowerCase}"
mkdir -p "$projectsDirectory"/"$projectName"/src/main/resources
printf "Standard maven folder structure of the project generated.\n"
#add minimal pom.xml
sed -e "s/GROUP_ID/$groupDomain/g" -e "s/PROJECT_NAME/$projectName/g" -e "s/PROJECT_DESCRIPTION/$description/g" -e "s/GROUP_URL/$repoUrl/g" -e "s/MAIN_CLASS_PATH/$groupDomain\.$projectName/g" ./templates/pom > "$projectsDirectory"/"$projectName"/pom.xml
printf "Adding pom... DONE.\n"
#add template main class of the program
sed -e "s/PACKAGE_NAME/$groupDomain/g" -e "s/PROJECT_NAME/$projectName/g" -e "s/AUTHOR_NAME/$author/g" ./templates/mainclass > "$projectsDirectory"/"$projectName"/src/main/java/"$groupProjectDirectory"/$projectName.java
printf "Adding main class of the program in $projectName/src/main/java/$groupProjectDirectory/$projectName.java... DONE.\n"
#Add readme.md file template
sed -e "s/PROJECT_NAME/$projectName/g" -e "s/DESCRIPTION/$description/g" -e "s/REPO_URL/$repoUrl/g" -e "s/MAIL/$author_mail/g" ./templates/readme > "$projectsDirectory"/"$projectName"/README.md
printf "Adding README... DONE.\n"
#Add estimates.md for future goal specification
now=$(date +"%d-%m-%Y")
sed -e "s/PROJECT_NAME/$projectName/g" -e "s/DESCRIPTION/$description/g" -e "s/DATE_TODAY/$now/g" ./templates/estimates > "$projectsDirectory"/"$projectName"/estimates.md
printf "Adding estimates... DONE.\n"
#Navigate to project directory
cd "$projectsDirectory"/"$projectName"/
#create gitignore
curl https://www.gitignore.io/api/java,intellij > .gitignore
echo "*.iml" >> .gitignore
echo "target/" >> .gitignore
echo ".idea/" >> .gitignore
printf "Creating gitignore file... DONE.\n"
#create mailmap
echo "$author <$author_mail>" > .mailmap
printf "Creating mailmap file... DONE.\n"
#Initialize empty git repository in the project's folder
git init
#add git precommit hook in git repository
rm .git/hooks/pre-commit.sample
curl https://raw.githubusercontent.com/michalakadam/GitHook/master/precommit.sh > .git/hooks/pre-commit
chmod u+x .git/hooks/pre-commit
printf "Adding precommit hook to repository... DONE.\n"
#Enable user to add remote repository
read -p "Do you want to track remote repository?[Y/n] " repoAnswer
if [ "$repoAnswer" = "Y" ] || [ "$repoAnswer" = "y" ] || [ "$repoAnswer" = "" ]; then
read -p "Feed me with link to the repository: (press q to quit) " repoLink
#enable user to quit here
if [ "$repoLink" = "q" ]; then
echo "Quitting connection to remote repository"
else
git remote add origin $repoLink
fi
fi
#Initial commit
git add .
git commit -m "initial commit with project template generated"
git checkout -b development
##Open project in Intellij IDEA - works on Linux only. Uncomment and change idea.sh location in order to use it.
#read -p "Do you want to open this project in Intellij?[Y/n] " ideAnswer
# if [ "$ideAnswer" = "Y" ] || [ "$ideAnswer" = "y" ] || [ "$ideAnswer" = "" ]; then
# //snap/intellij-idea-community/95/bin/idea.sh pom.xml &
#fi
printf "\nNEW PROJECT INITIALIZED SUCCESSFULLY"