-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathship-merge.sh
executable file
·137 lines (114 loc) · 2.78 KB
/
ship-merge.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env bash
set -e
shopt -s dotglob
template_repo="https://github.com/paralect/ship-merge"
deploy_dir="deploy-setup"
deploy_repo="https://github.com/paralect/ship-deploy"
api_dotnet=".NET API Starter"
api_dotnet_dir="api"
api_dotnet_repo="https://github.com/paralect/dotnet-api-starter"
api_koa="Koa API Starter"
api_koa_dir="api"
api_koa_repo="https://github.com/paralect/koa-api-starter"
web_next="Next Web Starter"
web_next_dir="web"
web_next_repo="https://github.com/paralect/next-starter"
function read_project_name() {
printf "\n? Enter project name: "
read project_name
if [[ -z "$project_name" ]]; then
printf "! Project name cannot be empty\n"
read_project_name
fi
}
function read_api_framework() {
printf "\n? Select API framework (Koa or .NET): "
read api
if [[ "$api" = Koa ]]; then
services+=("$api_koa")
elif [[ "$api" = .NET ]]; then
services+=("$api_dotnet")
else
printf "! Try again\n"
read_api_framework
fi
}
function read_platform() {
printf "\n? Select platform (Digital Ocean or AWS): "
read api
if [[ "$api" = 'Digital Ocean' ]]; then
platform="$api"
platform_dir=digital-ocean
elif [[ "$api" = AWS ]]; then
platform="$api"
platform_dir=aws
else
printf "! Try again\n"
read_platform
fi
}
read_project_name
platform=""
services=("$web_next")
read_api_framework
read_platform
filesToRemove=(
"docker-compose.yml"
".husky"
)
function installService() {
service="$1"
repo="$2"
dir="$3"
printf "\n! Installing $service..."
mkdir "$dir"
cd "$dir"
git clone --quiet "$repo" .
rm -rf .git "${filesToRemove[@]}"
cd ../
}
printf "\n"
printf "! Setup Info\n"
printf " Project name\n"
printf " $project_name\n"
printf " Services\n"
printf " %s\n" "${services[@]}"
printf " Platform\n"
printf " $platform\n"
mkdir $project_name
cd $project_name
git clone --quiet "$template_repo" .
rm -rf .git ship-merge.sh
echo "# $project_name" > README.md
for i in docker-compose*; do
perl -i -pe"s/ship/$project_name/g" $i
done
for service in "${services[@]}"; do
case "$service" in
"$api_dotnet")
installService "$service" "$api_dotnet_repo" "$api_dotnet_dir"
;;
"$api_koa")
installService "$service" "$api_koa_repo" "$api_koa_dir"
;;
"$web_next")
installService "$service" "$web_next_repo" "$web_next_dir"
;;
esac
done
installService "$platform" "$deploy_repo" "$deploy_dir"
mv ./"$deploy_dir"/"$platform_dir" ./deploy
mv ./"$deploy_dir"/.gitignore ./deploy
mv ./"$deploy_dir"/README.md ./deploy
mv ./deploy/.github .
mv workflows/chromatic.yml .github/workflows
rm -rf "$deploy_dir"
rm -rf web/.github
rm -rf workflows
npm install
git init
git add .
git commit -m "initial commit"
git branch -M main
npx husky install
printf "\n! Installation completed\n"