-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
122 lines (113 loc) · 3.24 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
#!/bin/bash
writeHeader() {
echo '<!DOCTYPE html>'
echo '<html lang="en">'
echo '<head>'
echo '<title>Gammes by GridSound</title>'
echo '<meta charset="utf-8"/>'
echo '<meta name="viewport" content="width=device-width"/>'
echo '<meta name="description" content="Musical scales cheatsheet"/>'
echo '<meta name="google" content="notranslate"/>'
echo '<meta property="og:type" content="website"/>'
echo '<meta property="og:title" content="Gammes by GridSound"/>'
echo '<meta property="og:url" content="https://gammes.gridsound.com"/>'
echo '<meta property="og:image" content="https://gammes.gridsound.com/cover.png"/>'
echo '<meta property="og:image:width" content="1090"/>'
echo '<meta property="og:image:height" content="898"/>'
echo '<meta property="og:description" content="Musical scales cheatsheet"/>'
echo '<link rel="manifest" href="manifest.json"/>'
echo '<link rel="shortcut icon" href="assets/favicon.png"/>'
}
writeBody() {
echo '</head>'
echo '<body>'
echo '<noscript>GridSound needs JavaScript to run</noscript>'
}
writeEnd() {
echo '</body>'
echo '</html>'
}
writeCSS() {
printf '<link rel="stylesheet" href="%s"/>\n' "${CSSfiles[@]}"
}
writeJS() {
printf '<script src="%s"></script>\n' "${JSfiles[@]}"
}
writeCSScompress() {
echo -n '' > allCSS.css
cat "${CSSfiles[@]}" >> allCSS.css
echo '<style>'
csso allCSS.css
echo '</style>'
rm allCSS.css
}
writeJScompress() {
echo '"use strict";' > allJS.js
cat "${JSfilesProd[@]}" >> allJS.js
cat "${JSfiles[@]}" >> allJS.js
echo '<script>'
terser allJS.js --compress --mangle --toplevel --mangle-props "regex='^[$]'"
echo '</script>'
rm allJS.js
}
declare -a CSSfiles=(
"assets/fonts/fonts.css"
"style.css"
)
declare -a JSfilesProd=(
"initServiceWorker.js"
)
declare -a JSfiles=(
"gs-utils/gs-utils-dom.js"
"main.html.js"
"run.js"
)
buildDev() {
filename='index.html'
echo "Build $filename"
writeHeader > $filename
writeCSS >> $filename
writeBody >> $filename
echo '<script>function lg( a ) { return console.log.apply( console, arguments ), a; }</script>' >> $filename
writeJS >> $filename
writeEnd >> $filename
}
buildProd() {
filename='index-prod.html'
echo "Build $filename"
writeHeader > $filename
writeCSScompress >> $filename
writeBody >> $filename
echo '<script>function lg( a ) { return a; }</script>' >> $filename
writeJScompress >> $filename
writeEnd >> $filename
}
lint() {
stylelint "${CSSfiles[@]}"
echo '"use strict";' > __lintMain.js
cat "${JSfilesProd[@]}" | grep -v '"use strict";' >> __lintMain.js
cat "${JSfiles[@]}" | grep -v '"use strict";' >> __lintMain.js
eslint __lintMain.js && rm __lintMain.js
}
updateDep() {
git submodule init
git submodule update --remote
}
if [ $# = 0 ]; then
echo ' --------------------------------'
echo ' .:: GridSound build shell-script ::.'
echo ' ------------------------------------'
echo ''
echo './build.sh dev ---> create "index.html" for development'
echo './build.sh prod --> create "index-prod.html" for production'
echo './build.sh lint --> launch the JS/CSS linters (ESLint and Stylelint)'
echo './build.sh dep ---> update all the submodules'
elif [ $1 = "dep" ]; then
updateDep
elif [ $1 = "dev" ]; then
buildDev
elif [ $1 = "prod" ]; then
buildProd
elif [ $1 = "lint" ]; then
lint
fi