-
Notifications
You must be signed in to change notification settings - Fork 7
/
skeletor.sh
executable file
·207 lines (158 loc) · 7.57 KB
/
skeletor.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/bin/bash
#
#
# ▄████████ ▄█ ▄█▄ ▄████████ ▄█ ▄████████ ███ ▄██████▄ ▄████████
# ███ ███ ███ ▄███▀ ███ ███ ███ ███ ███ ▀█████████▄ ███ ███ ███ ███
# ███ █▀ ███▐██▀ ███ █▀ ███ ███ █▀ ▀███▀▀██ ███ ███ ███ ███
# ███ ▄█████▀ ▄███▄▄▄ ███ ▄███▄▄▄ ███ ▀ ███ ███ ▄███▄▄▄▄██▀
# ▀███████████ ▀▀█████▄ ▀▀███▀▀▀ ███ ▀▀███▀▀▀ ███ ███ ███ ▀▀███▀▀▀▀▀
# ███ ███▐██▄ ███ █▄ ███ ███ █▄ ███ ███ ███ ▀███████████
# ▄█ ███ ███ ▀███▄ ███ ███ ███▌ ▄ ███ ███ ███ ███ ███ ███ ███
# ▄████████▀ ███ ▀█▀ ██████████ █████▄▄██ ██████████ ▄████▀ ▀██████▀ ███ ███
# ▀ ▀ ███ ███
#
# Usage:
#
# $ bash <(curl -fsSL https://skeletor.ckcollab.com)
#
#
# Environment variables:
# SKELETOR_BRANCH: the branch name to use when cloning from Skeletor git repo, default = master
#
# ----------------------------------------------------------------------------
# Script overview:
# make sure docker is running
#
# take input PROJECT_NAME if not provided to shell script already
#
# take input FRONTEND, default = 1
# FRONTEND_WEB_VUEJS=1
# FRONTEND_WEB_VUEJS_MOBILE_REACT_NATIVE=2
#
# git clone master into PROJECT_NAME
#
# if FRONTEND_WEB_VUEJS then remove mobile dir
#
# replace {{ project_name }} with PROJECT_NAME
#
# remove readme top section
#
# run make (django, vue, react native setup done here)
#
# ----------------------------------------------------------------------------
# default to cat
fancy_print_command=cat
# or if we have lolcat, use that!
if command -v lolcat &> /dev/null
then
fancy_print_command=lolcat
fi
black=`tput setaf 0`
red=`tput setaf 1`
green=`tput setaf 2`
magenta=`tput setaf 5`
cyan=`tput setaf 6`
white=`tput setaf 7`
bold=`tput bold`
dim=`tput dim`
reset_standout=`tput rmso`
white_bg=`tput setab 7`
underline=`tput smul`
reset=`tput sgr0`
cat << EOF
${red}
▄████████ ▄█ ▄█▄ ▄████████ ▄█ ▄████████ ███ ▄██████▄ ▄████████
███ ███ ███ ▄███▀ ███ ███ ███ ███ ███ ▀█████████▄ ███ ███ ███ ███
███ █▀ ███▐██▀ ███ █▀ ███ ███ █▀ ▀███▀▀██ ███ ███ ███ ███
███ ▄█████▀ ▄███▄▄▄ ███ ▄███▄▄▄ ███ ▀ ███ ███ ▄███▄▄▄▄██▀
▀███████████ ▀▀█████▄ ▀▀███▀▀▀ ███ ▀▀███▀▀▀ ███ ███ ███ ▀▀███▀▀▀▀▀
███ ███▐██▄ ███ █▄ ███ ███ █▄ ███ ███ ███ ▀███████████
▄█ ███ ███ ▀███▄ ███ ███ ███▌ ▄ ███ ███ ███ ███ ███ ███ ███
▄████████▀ ███ ▀█▀ ██████████ █████▄▄██ ██████████ ▄████▀ ▀██████▀ ███ ███
▀ ▀ ███ ███
EOF
$(echo $fancy_print_command) << EOF
--------------------------------------------------------------------------- ${white}${dim}made with ❤️ by ${reset_standout}${cyan}C${white}k${magenta}c ${reset}
EOF
# Setup cross platform helper functions
cross_platform_sed() {
# The first argument is the sed expression
local expr="$1"
shift # Remove the first argument from $@
# Detect the OS
local OS=$(uname)
if [ "$OS" = "Darwin" ]; then # macOS
sed -i '' "$expr" "$@"
elif [ "$OS" = "Linux" ]; then # Linux
sed -i "$expr" "$@"
else
echo "Unsupported OS: $OS"
exit 1
fi
}
# Make sure Docker is running first..
if ! docker info > /dev/null 2>&1; then
echo -e "\n${red}${bold}ERROR: This script uses docker, and docker isn't running - please start docker and try again!${reset}"
exit 4
fi
# Make sure pip is installed
if ! command -v pip &> /dev/null
then
echo -e "\n${red}${bold}ERROR: pip is not installed!${reset}"
exit 5
fi
# Get user input
read -p "Please provide a folder/project name: ${green}" PROJECT_NAME
echo "${reset}"
if [[ -z "$PROJECT_NAME" ]]; then
echo -e "\n${red}${bold}ERROR: PROJECT_NAME is required!${reset}"
exit 1
fi
# Choose a frontend
cat << EOF
${underline}Available frontends:${reset}
${green}${bold}1. Vue (web only) [recommended/default]${reset}
2. Vue (web) + React Native (mobile)
EOF
FRONTEND_WEB_VUEJS=1
FRONTEND_WEB_VUEJS_MOBILE_REACT_NATIVE=2
read -p "Please select your preferred frontend: ${green}" FRONTEND
echo "${reset}"
# Set default to 1 if no input given
FRONTEND=${FRONTEND:-1}
if [[ $FRONTEND -gt 2 ]]; then
echo -e "\n${red}${bold}ERROR: Invalid FRONTEND choice... must be 1 or 2!${reset}"
exit 2
fi
# Select skeletor branch, default is master
: "${SKELETOR_BRANCH:=master}"
# Clone repo into $PROJECT_NAME dir
echo -e "Git cloning from branch $SKELETOR_BRANCH into directory ${green}'$PROJECT_NAME'${reset} with frontend choice ${green}#$FRONTEND${reset}\n"
git clone -b $SKELETOR_BRANCH https://github.com/ckc-org/skeletor.git $PROJECT_NAME &> /dev/null
if [ $? -ne 0 ]; then
echo -e "\n${red}${bold}ERROR: Failed to clone git repo into directory ${underline}${PROJECT_NAME}${reset}"
exit 3
fi
# Go to project directory OR exit if fail
cd $PROJECT_NAME || exit 3
# Remove opening of README, before "---" line
cross_platform_sed '1,/^---$/d' README.md
# Replace "SKELETOR_NAME_PLACEHOLDER" with $PROJECT_NAME in all files
for file in $(grep -rl "SKELETOR_NAME_PLACEHOLDER" .); do
cross_platform_sed -e "s@SKELETOR_NAME_PLACEHOLDER@$PROJECT_NAME@g" "$file"
done
# Remove mobile dir if we don't need it
if [[ $FRONTEND == "$FRONTEND_WEB_VUEJS" ]]; then
rm -rf src/mobile
fi
# Remove Skeletor specific stuff
echo -e "Cleaning up stuff...\n"
rm -rf .git
rm -rf docs
rm skeletor.sh
rm LICENSE
rm .github/workflows/skeletor_test.yml
# Run Make
echo -e "Running Skeletor make...\n"
make
echo -e "\n${green}${bold}Done!${reset}"