-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.sh
256 lines (202 loc) · 8.06 KB
/
setup.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#!/bin/bash
# Theme setup.
# Defaults
default_name="Gotta Blast!"
default_id="gotta-blast"
default_author="Neutron Creative Inc"
default_author_url="https://neutroncreative.com"
default_url="genesis-starter.test"
default_namespace="NeutronCreative\GottaBlast"
default_company="${default_namespace%\\*}"
default_package="${default_namespace#*\\}"
default_version=`perl -ne 'print if /(?:\"version\": \")(.*?)(?:\")/' './package.json'`
# Files
bs='\'
setup_sh="./setup.sh"
functions_php="./functions.php"
front_page_php="./front-page.php"
config_php="./config/defaults.php"
package_json="./package.json"
composer_json="./composer.json"
example="./app/Example.php"
gulpfile="./Gulpfile.js"
readme="./README.md"
changelog="./CHANGELOG.md"
# Text styles
bold=$(tput bold)
white=$(tput setaf 7)
pink=$(tput setaf 198)
green=$(tput setaf 2)
blue=$(tput setaf 4)
txtreset=$(tput sgr0)
echo "${bold}${blue}
__ __
________ ____ / /_/ /_ ___ ____ ___ ___ _____
/ ___/ _ \/ __ \/ __/ __ \/ _ \/ __ '__ \/ _ \/ ___/
(__ ) ___/ /_/ / /_/ / / / __/ / / / / / ___(__ )
/____/\___/\____/\__/_/ /_/\___/_/ /_/ /_/\___/____/
${txtreset}"
# echo "${bold}
# Startup Pro
# ${txtreset}"
echo "1) Set name for your theme. (Default: $default_name)"
read name
# use default if empty
if test -n "$name"; then
echo ""
else
name=$default_name
fi
echo "2) Set unique id for your theme. Use only a-z and _. (Default: $default_id)"
read id
# use default if empty
if test -n "$id"; then
echo ""
else
id=$default_id
fi
echo "3) Set the author name for your theme. Use only a-z and _. (Default: $default_author)"
read author
# use default if empty
if test -n "$author"; then
echo ""
else
author=$default_author
fi
echo "4) Set the author URL for your theme. Use only a-z and _. (Default: $default_author_url)"
read author_url
# use default if empty
if test -n "$author_url"; then
echo ""
else
author_url=$default_author_url
fi
echo "5) Set the namespace for your theme. Use only a-z and _. (Default: $default_namespace)"
read -r namespace
# use default if empty
if test -n "$namespace"; then
echo ""
else
namespace=$default_namespace
fi
company="${namespace%\\*}"
package="${namespace#*\\}"
echo "6) Set local development url. Note: An SSL is required to use HTTPS (Default: $default_url)"
read url
# use default if empty
if test -n "$url"; then
echo ""
else
url=$default_url
fi
# "version": "1.2.3",
clean_version="${default_version//\"/}"
clean_version="${clean_version//version: /}"
clean_version="${clean_version//,/}"
clean_version="${clean_version// /}"
echo "7) Set version number for your theme. (Default: $clean_version)"
read version
# use default if empty
if test -n "$version"; then
echo ""
else
version=$clean_version
fi
echo "
Run setup:
=========="
# ----------------------------------------------------------------
# Search & Replace Name
# ----------------------------------------------------------------
perl -p -i -e "s|$default_name|$name|g" $functions_php
perl -p -i -e "s|$default_name|$name|g" $front_page_php
perl -p -i -e "s|$default_name|$name|g" $config_php
perl -p -i -e "s|$default_name|$name|g" $package_json
perl -p -i -e "s|$default_name|$name|g" $composer_json
perl -p -i -e "s|$default_name|$name|g" $gulpfile
perl -p -i -e "s|$default_name|$name|g" $readme
perl -p -i -e "s|$default_name|$name|g" $changelog
perl -p -i -e "s|$default_name|$name|g" $example
echo "1/8 --> Search & replace name ........ ${green}done${txtreset}"
# ----------------------------------------------------------------
# Search & Replace ID
# ----------------------------------------------------------------
perl -p -i -e "s|$default_id|$id|g" $functions_php
perl -p -i -e "s|$default_id|$id|g" $front_page_php
perl -p -i -e "s|$default_id|$id|g" $config_php
perl -p -i -e "s|$default_id|$id|g" $package_json
perl -p -i -e "s|$default_id|$id|g" $composer_json
perl -p -i -e "s|$default_id|$id|g" $gulpfile
perl -p -i -e "s|$default_id|$id|g" $readme
perl -p -i -e "s|$default_id|$id|g" $example
echo "2/8 --> Search & replace id .......... ${green}done${txtreset}"
# ----------------------------------------------------------------
# Change author
# ----------------------------------------------------------------
perl -p -i -e "s|$default_author|$author|g" $functions_php
perl -p -i -e "s|$default_author|$author|g" $front_page_php
perl -p -i -e "s|$default_author|$author|g" $config_php
perl -p -i -e "s|$default_author|$author|g" $package_json
perl -p -i -e "s|$default_author|$author|g" $composer_json
perl -p -i -e "s|$default_author|$author|g" $gulpfile
perl -p -i -e "s|$default_author|$author|g" $readme
perl -p -i -e "s|$default_author|$author|g" $example
echo "3/8 --> Change author name ........... ${green}done${txtreset}"
# ----------------------------------------------------------------
# Change author URL
# ----------------------------------------------------------------
perl -p -i -e "s|$default_author_url|$author_url|g" $functions_php
perl -p -i -e "s|$default_author_url|$author_url|g" $front_page_php
perl -p -i -e "s|$default_author_url|$author_url|g" $config_php
perl -p -i -e "s|$default_author_url|$author_url|g" $package_json
perl -p -i -e "s|$default_author_url|$author_url|g" $composer_json
perl -p -i -e "s|$default_author_url|$author_url|g" $gulpfile
perl -p -i -e "s|$default_author_url|$author_url|g" $readme
perl -p -i -e "s|$default_author_url|$author_url|g" $example
echo "4/8 --> Change author URL ............ ${green}done${txtreset}"
# ----------------------------------------------------------------
# Change namespace
# ----------------------------------------------------------------
perl -p -i -e "s|\Q$default_company$bs$default_package\E|$company$bs$bs$package|g" $functions_php
perl -p -i -e "s|\Q$default_company$bs$default_package\E|$company$bs$bs$package|g" $front_page_php
perl -p -i -e "s|\Q$default_company$bs$default_package\E|$company$bs$bs$package|g" $config_php
perl -p -i -e "s|\Q$default_company$bs$default_package\E|$company$bs$bs$package|g" $package_json
perl -p -i -e "s|\Q$default_company$bs$default_package\E|$company$bs$bs$package|g" $gulpfile
perl -p -i -e "s|\Q$default_company$bs$default_package\E|$company$bs$bs$package|g" $readme
perl -p -i -e "s|\Q$default_company$bs$default_package\E|$company$bs$bs$package|g" $composer_json
perl -p -i -e "s|\Q$default_company$bs$default_package\E|$company$bs$bs$package|g" $example
perl -p -i -e "s|$default_company|$company|g" $composer_json
perl -p -i -e "s|$default_package|$package|g" $composer_json
echo "5/8 --> Change namespace ............. ${green}done${txtreset}"
# ----------------------------------------------------------------
# Change dev URL
# ----------------------------------------------------------------
perl -p -i -e "s|$default_url|$url|g" $gulpfile
echo "6/8 --> Change dev URL ............... ${green}done${txtreset}"
# ----------------------------------------------------------------
# Update defaults
# ----------------------------------------------------------------
perl -p -i -e "s|$default_name|$name|g" $setup_sh
perl -p -i -e "s|$default_id|$id|g" $setup_sh
perl -p -i -e "s|$default_author|$author|g" $setup_sh
perl -p -i -e "s|$default_author_url|$author_url|g" $setup_sh
perl -p -i -e "s|$default_url|$url|g" $setup_sh
perl -p -i -e "s|\Q$default_company$bs$default_package\E|$company$bs$bs$package|g" $setup_sh
echo "7/8 --> Updating defaults ............ ${green}done${txtreset}"
# ----------------------------------------------------------------
# Reset version
# ----------------------------------------------------------------
formatted_version=" \"version\": \"${version}\","
perl -p -i -e "s|$default_version|$formatted_version|g" $package_json
perl -p -i -e "s|$default_version|$formatted_version|g" $example
echo "8/8 --> Updating version ............. ${green}done${txtreset}"
# ----------------------------------------------------------------
# Build theme
# ----------------------------------------------------------------
build="gulp build"
${build}
dump="composer dump-autoload"
${dump}
echo "${green}Setup complete, starting BrowserSync...${txtreset}"
serve="gulp serve"
${serve}