-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·192 lines (169 loc) · 5.01 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
#!/bin/bash
set -e
command -v bundle >/dev/null 2>&1 || {
echo >&2 "Impossible de trouver la commande \"bundle\"."
echo >&2 "Installer bundler avec \"gem install bundler\"."
exit 1
}
command -v npm >/dev/null 2>&1 || {
echo >&2 "Impossible de trouver la commande \"npm\"."
echo >&2 "Installer nodejs pour continuer "
echo >&2 "\thttps://docs.microsoft.com/fr-fr/windows/dev-environment/javascript/nodejs-on-wsl"
exit 1
}
command -v vips >/dev/null 2>&1 || {
echo >&2 "Impossible de trouver la commande \"vips\""
if [[ "$OSTYPE" == "darwin"* ]] ;then
echo >&2 "Installer libvips avec \"brew install vips\""
else #everythin else is linux
echo >&2 "Installer libvips avec \"sudo apt install libvips-tools\""
fi
exit 1
}
usageStr(){
if ! test -z "$1" ;then
echo -e "invalid Option : $1"
fi
echo -e "Usage : build.sh [options]"
echo -e "Valid options :"
echo -e "\t-t --test : Enable checks with html-proofer"
echo -e "\t-i --integration \"target\" : run integration tests on target"
echo -e "\t\tuse target \"local\" to test on ./_site/ files"
echo -e "\t\t(imply --no-build if target != local)"
echo -e "\t-e --extended : extended integration tests"
echo -e "\t-f --force : Force assets rebuild"
echo -e "\t-w --watch : Use jekyll serve mode"
echo -e "\t-c --compress-static : compress static assets"
echo -e "\t-p --pack : pack distributed files for npm module @holusion/theme"
echo "long option only : "
echo -e "\t--no-build : disable site build"
}
make_build=true
make_force=false
make_check=false
make_watch=false
make_compress=false
make_pack=false
integration_target=""
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--)
shift
break
;;
-t|--test)
make_check=true
;;
-i|--integration)
shift
integration_target="$1"
if test -z "$integration_target" || test "$integration_target" == -* ;then
echo "integration testing required with no target argument"
usageStr
exit
fi
#Integration runs on target and does not trigger a build
if test "x$integration_target" != "xlocal" ;then
make_build=false
fi
;;
-e|--extended)
export RUN_EXTENDED_TESTS=1
;;
-f|--force)
make_force=true
;;
-w|--watch)
make_watch=true
;;
-c|--compress-static)
make_compress=true
;;
--no-build)
make_build=false
;;
-p|--pack)
make_pack=true
;;
*)
echo "unknown opt"
usageStr $1
exit
;;
esac
shift # past argument or value
done
DIR="$( cd "$( dirname "$0" )" && pwd )"
OLD_PWD=$(pwd)
cd "$DIR"
#Get convert helpers
source ./scripts/optimizers.sh
#Set up RVM
if test -s "$HOME/.rvm/scripts/rvm" ; then
# First try to load from a user install
source "$HOME/.rvm/scripts/rvm"
rvm use "$(cat $DIR/.ruby-version)@$(cat $DIR/.ruby-gemset)"
elif test -s "/usr/local/rvm/scripts/rvm" ; then
# Then try to load from a root install
source "/usr/local/rvm/scripts/rvm"
rvm use "$(cat $DIR/.ruby-version)@$(cat $DIR/.ruby-gemset)"
else
echo "WARNING: An RVM installation was not found."
echo "Using system Ruby : $(ruby -e 'print ENV["RUBY_VERSION"]')"
fi
#[ -d "$DIR/build" ] || mkdir -p "$DIR/build"
#check gem dependencies and install if necessary
bundle check >/dev/null || bundle install
if $make_compress ;then
install_optimizers "$DIR/build"
#echo "Compress static assets"
time compress_folder "$DIR/static"
fi
if ${make_build} ;then
s_conf="_config.yml"
# deploy if _deploy.yml exists. it should not in dev environments.
# It's a shorthand to pass in build-time variables like site.url
if test -f _deploy.yml ;then
s_conf="$s_conf,_deploy.yml"
fi
if $make_watch ;then
exec_cmd="serve"
else
exec_cmd="build"
fi
# final command
bundle exec jekyll $exec_cmd --force-polling --config $s_conf $@
fi
#
# TEST target
# + static analysis of site's files.
#
if ${make_check} ;then
bundle exec htmlproofer _site \
--checks "Links,Images" \
--only-4xx \
--enforce-https false \
--allow-missing-href true \
--ignore-missing-alt true \
--disable-external true \
--ignore-files "/node_modules/,/static\/fonts\/.*.html/,/google[0-9a-f]*\.html/,/^_site\/index.html$/,/\/0_snipcart-templates.html$/" \
--ignore-urls "/^\/?$/" \
--log-level :debug \
$@
fi
# Integration End-To-End tests
# if $integration_target=local, will start a local web server to test from `_site`
if ! test -z "$integration_target" ;then
echo "RUN integration tests on $integration_target"
TARGET="$integration_target" npm test -- $@
fi
if ${make_pack} ;then
mkdir -p dist/;
sed 's|/static/fonts/|fonts/|g' _site/css/theme.css > dist/theme.css
sed 's|/static/fonts/|fonts/|g' _site/css/theme.css.map > dist/theme.css.map
cp -r static/fonts/ dist/fonts
cp node_modules/bootstrap/dist/js/bootstrap.bundle.min.js* dist/
sed 's|../node_modules/|~|' _css/_variables.scss > dist/_variables.scss
fi