-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
353 lines (282 loc) · 9.1 KB
/
build.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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#!/bin/bash
R='\033[0;31m'
G='\033[0;32m'
B='\033[0;96m'
# ------------------------------------------ #
# Vars
# ------------------------------------------ #
ROOT=$(echo $(pwd) | sed 's|/c/|C:/|')
NAME='release' # slug
THEME='default' # slug
TEST=TRUE
VENDOR=TRUE
COMPOSER=TRUE
GENERATE=TRUE
APP="${ROOT}/.build/${NAME}"
ASSET="${APP}/public/assets"
# ------------------------------------------ #
# Checking toolkits
# ------------------------------------------ #
echo -e "${B}Checking toolkits..."
if ! terser --version terser &> /dev/null
then
echo -e "${B}Installing global terser package..."
npm install terser -g
fi
if ! uglifyjs -v uglifyjs &> /dev/null
then
echo -e "${B}Installing global uglify-js package..."
npm install uglify-js -g
fi
if ! uglifycss --version uglifycss &> /dev/null
then
echo -e "${B}Installing global uglify-css package..."
npm install uglifycss -g
fi
if ! combine-files combine-files &> /dev/null
then
echo -e "${B}Installing global combine-files package..."
npm install combine-files -g
fi
if ! json --version json &> /dev/null
then
echo -e "${B}Installing global Json parser..."
npm install -g json
fi
sleep 2
clear
# ------------------------------------------ #
# Copying release files
# ------------------------------------------ #
echo -e "${G}Copying release files..."
if [ -d "${APP}" ]; then
rm -rf "${APP}"
fi
rm -f "${APP}-*.zip"
mkdir "${APP}"
cp "${ROOT}/.htaccess" "${APP}/.htaccess"
cp "${ROOT}/index.php" "${APP}/index.php"
cp -r "${ROOT}/public" "${APP}/public"
if [ "$COMPOSER" = "TRUE" ]; then
cp "${ROOT}/composer.json" "${APP}/composer.json"
fi
if [ "$GENERATE" = "TRUE" ]; then
cp "${ROOT}/generate.php" "${APP}/generate.php"
cp "${ROOT}/generate.sh" "${APP}/generate.sh"
fi
if [ "$TEST" = "TRUE" ]; then
cp "${ROOT}/init.sh" "${APP}/init.sh"
cp "${ROOT}/test.sh" "${APP}/test.sh"
cp "${ROOT}/test.php" "${APP}/test.php"
fi
if [ "$VENDOR" = "TRUE" ];
then
cp -r "${ROOT}/App" "${APP}/App"
else
mkdir "${APP}/App"
cp -r "${ROOT}/App/Controllers" "${APP}/App/Controllers"
cp -r "${ROOT}/App/Helpers" "${APP}/App/Helpers"
cp -r "${ROOT}/App/Models" "${APP}/App/Models"
cp -r "${ROOT}/App/Modules" "${APP}/App/Modules"
cp -r "${ROOT}/App/Storage" "${APP}/App/Storage"
cp -r "${ROOT}/App/Views" "${APP}/App/Views"
cp "${ROOT}/App/App.php" "${APP}/App/App.php"
cp "${ROOT}/App/.htaccess" "${APP}/App/.htaccess"
fi
sleep 2
clear
# ------------------------------------------ #
# Testing release
# ------------------------------------------ #
if [ "$TEST" = "TRUE" ]; then
bash "${APP}/init.sh"
bash "${APP}/test.sh"
sleep 2
fi
# ------------------------------------------ #
# Composer update (production)
# ------------------------------------------ #
if [ "$COMPOSER" = "TRUE" ]; then
echo -e "${G}Composer update (production)..."
cd "${APP}"
composer clearcache
composer validate
composer update --no-dev -o
sleep 2
clear
fi
# ------------------------------------------ #
# Generate production files
# ------------------------------------------ #
if [ "$GENERATE" = "TRUE" ]; then
echo -e "${G}Generate production files..."
bash "${APP}/generate.sh"
sleep 2
clear
fi
# ------------------------------------------ #
# Copy shared vendors (icons)
# ------------------------------------------ #
# echo -e "${G}Copy shared vendors (icons)..."
# TMP="${ASSET}/vendor"
# DIST="${ASSET}/front/theme/${THEME}/css"
# cp "${TMP}/example/example.css" "${DIST}/example.css"
# sleep 2
# clear
# ------------------------------------------ #
# Combine CSS files
# ------------------------------------------ #
echo -e "${G}Combine CSS files..."
# cd "${TMP}"
# combine-files . style.min.css
# find . -type f -not -name "style.min.css" -delete
TMP="${ASSET}/front/theme/${THEME}/css/"
# cp "${ASSET}/example/example.min.css" "${TMP}example.min.css"
FILES=(
"style.css"
"custom.css"
"icons.min.css"
# "example.min.css"
)
FILES=$(printf "%s," "${FILES[@]/#/$TMP}")
FILES=${FILES%,}
combine-files "${FILES}" "${TMP}/style.min.css"
sleep 2
clear
# ------------------------------------------ #
# Combine JS files
# ------------------------------------------ #
echo -e "${G}Combine JS files..."
TMP="${ASSET}/vendor/"
FILES=(
"bootstrap/bootstrap.bundle.min.js"
"jquery/jquery.min.js"
"vanille/VanillePlugin.min.js"
# "example/example.min.js"
)
FILES=$(printf "%s," "${FILES[@]/#/$TMP}")
FILES=${FILES%,}
combine-files "${FILES}" "${TMP}/all.min.js"
sleep 2
clear
# ------------------------------------------ #
# Minify CSS files
# ------------------------------------------ #
echo -e "${G}Minify CSS files..."
TMP="${ASSET}/front/theme/${THEME}/css"
uglifycss "${TMP}/style.min.css" --output "${TMP}/style.min.css"
TMP="${ASSET}/admin/css"
uglifycss "${TMP}/style.css" --output "${TMP}/style.min.css"
sleep 2
clear
# ------------------------------------------ #
# Minify JS files
# ------------------------------------------ #
echo -e "${G}Minify JS files..."
TMP="${ASSET}/front/theme/${THEME}/js"
uglifyjs "${TMP}/main.js" -c -m --output "${TMP}/main.min.js"
TMP="${ASSET}/admin/js"
uglifyjs "${TMP}/main.js" -c -m --output "${TMP}/main.min.js"
uglifyjs "${TMP}/login.js" -c -m --output "${TMP}/login.min.js"
# TMP="${ASSET}/vendor"
# uglifyjs "${TMP}/all.min.js" -c -m --output "${TMP}/all.min.js"
sleep 2
clear
# ------------------------------------------ #
# Compile language files
# ------------------------------------------ #
TMP="${APP}/App/Storage/translation"
echo -e "${G}Compile language files [EN]..."
msgfmt -o "${TMP}/en.mo" "${TMP}/en.po"
sleep 2
clear
# ------------------------------------------ #
# Remove cache, logs, backups
# ------------------------------------------ #
echo -e "${R}Remove cache, logs, backups..."
TMP="${APP}/App/Storage"
rm -rf "${TMP}/cache/view"
rm -rf "${TMP}/cache/temp"
rm -rf "${TMP}/logs/core/*"
rm -rf "${TMP}/logs/database/*"
rm -rf "${TMP}/upload/backups/*.zip"
rm -rf "${TMP}/upload/backups/*.backup"
sleep 2
clear
# ------------------------------------------ #
# Removing development files
# ------------------------------------------ #
echo -e "${R}Removing development files..."
find "${APP}" -type f -name "*.bak.*" -exec rm -f {} \;
find "${APP}" -type f -name "*.bak" -exec rm -f {} \;
find "${APP}" -type f -name "*.sh" -exec rm -f {} \;
find "${APP}" -type f -name "*.md" -exec rm -f {} \;
find "${APP}" -type f -name "phpunit.*" -exec rm -f {} \;
find "${APP}" -type f -name ".gitignore" -exec rm -f {} \;
find "${APP}" -type f -name ".editorconfig" -exec rm -f {} \;
find "${APP}" -type f -name ".gitattributes" -exec rm -f {} \;
find "${APP}" -type f -name ".codeclimate.yml" -exec rm -f {} \;
find "${APP}" -type f -name ".travis.yml" -exec rm -f {} \;
find "${APP}" -type f -name "composer.json" -exec rm -f {} \;
find "${APP}" -type f -name "composer.lock" -exec rm -f {} \;
find "${APP}" -type f -name "CHANGELOG" -exec rm -f {} \;
find "${APP}" -type f -name "README" -exec rm -f {} \;
find "${APP}" -type f -name "README.rst" -exec rm -f {} \;
find "${APP}" -type f -name "LICENSE.txt" -exec rm -f {} \;
find "${APP}" -type f -name "LICENSE" -exec rm -f {} \;
find "${APP}" -type f -name "LICENCE" -exec rm -f {} \;
find "${APP}" -type f -name "installed.json" -exec rm -f {} \;
find "${APP}" -type f -name "_config.yml" -exec rm -f {} \;
find "${APP}" -type f -name ".php_cs.dist" -exec rm -f {} \;
find "${APP}" -type f -name ".php-cs-fixer.dist.php" -exec rm -f {} \;
rm -f "${APP}/test.php"
rm -f "${APP}/generate.php"
rm -f "${APP}/App/Storage/config/db.ini" # Legacy
rm -f "${ASSET}/front/theme/${THEME}/css/style.css"
rm -f "${ASSET}/front/theme/${THEME}/css/custom.css"
rm -f "${ASSET}/front/theme/${THEME}/css/icons.min.css"
rm -f "${ASSET}/front/theme/${THEME}/js/main.js"
rm -f "${ASSET}/admin/css/style.css"
rm -f "${ASSET}/admin/js/main.js"
rm -f "${ASSET}/admin/js/login.js"
rm -rf "${ASSET}/vendor/jquery"
rm -rf "${ASSET}/vendor/bootstrap"
rm -rf "${ASSET}/vendor/vanille"
# rm -rf "${ASSET}/example/example"
sleep 2
clear
# ------------------------------------------ #
# Update global config
# ------------------------------------------ #
echo -e "${G}Update global config..."
TMP="${APP}/App/Storage/config"
DEBUGON='"debug": true'
DEBUGOFF='"debug": false'
cp "${TMP}/global.json" "${TMP}/global.tmp"
sed "s/${DEBUGON}/${DEBUGOFF}/g" "${TMP}/global.tmp" > "${TMP}/global.json"
rm "${TMP}/global.tmp"
sleep 2
clear
# ------------------------------------------ #
# Parsing version
# ------------------------------------------ #
echo -e "${G}Parsing version from global.json..."
TMP="${APP}/App/Storage/config/global.json"
VERSION=`cat ${TMP}`
VERSION=`echo ${VERSION} | json version`
sleep 2
clear
# ------------------------------------------ #
# Generating release archive
# ------------------------------------------ #
echo -e "${G}Generating release archive [${VERSION}]..."
cd "${ROOT}/.build"
zip "${NAME}-${VERSION}.zip" -r "${NAME}"
rm -rf "${NAME}"
sleep 2
clear
# ------------------------------------------ #
# Done
# ------------------------------------------ #
echo -e "${B}Done! press [Enter]"
read PAUSE