-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild
executable file
·73 lines (59 loc) · 2.07 KB
/
build
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
#!/bin/bash
# Creates a versions folder with latest version and specific version folders.
# Relative paths are replaced by absolute paths.
# In addition, CSS/JS/MJS files are minimized and the paths adjusted accordingly.
# author: André Kless <[email protected]> (https://github.com/akless)
# version: 1.0.0
# create versions folder if not exists
mkdir -p versions
# create empty subfolder for latest version
rm -rf versions/latest
mkdir versions/latest
# copy relevant folders/files to this subfolder
shopt -s extglob
cp -R !(docs|node_modules|tests|versions|build|favicon.ico|*.html|LICENSE|README.md|package.json|package-lock.json) versions/latest
shopt -u extglob
# replace locale paths that start with '././' with absolute paths
domain=$(awk '/@domain/{print $3}' ccm*.js)
str=s\/\\.\\/\\.\\//${domain//\//\\\/}versions\\/latest\\//g
find ./versions/latest -type f -print0 | xargs -0 perl -pi -e $str
# help function for update paths where minified type of files are used
hlp() {
file=${1:1}.${2}
file=${file////\\/}
min=${1:1}.min.${2}
min=${min////\\/}
str=s/${file}/${min}/g
find ./versions/latest -type f -print0 | xargs -0 perl -pi -e $str
}
# minify css files
for i in $(find ./versions/latest -name \*.css)
do
i="${i%.*}"
csso -i ${i}.css -o ${i}.min.css
# update paths where minified CSS files are used
hlp $i css
done
# minify js files
for i in $(find ./versions/latest -name \*.js)
do
i="${i%.*}"
terser ${i}.js -o ${i}.min.js --comments false --source-map "url='${i}.min.js.map'"
# update paths where minified JS files are used
hlp $i js
done
# minify mjs files
for i in $(find ./versions/latest -name \*.mjs)
do
i="${i%.*}"
terser ${i}.mjs -o ${i}.min.mjs --comments false --source-map "url='${i}.min.mjs.map'"
# update paths where minified JS files are used
hlp $i mjs
done
# create empty subfolder for specific version
version=$(awk '/@version/{print $3}' ccm*.js)
version=v${version%.*.*}
rm -rf "versions/${version}"
mkdir "versions/${version}"
# copy folders/files from latest version to specific version
cp -R versions/latest/* "versions/${version}"