-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.replace
More file actions
executable file
·207 lines (174 loc) · 5.12 KB
/
Copy pathdeploy.replace
File metadata and controls
executable file
·207 lines (174 loc) · 5.12 KB
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
#!/bin/bash
###############################################################################
##
## intialization: requires earlier configured dependencies:
##
## - https://github.com/jeff1evesque/jefflevesque.com#dependency
##
###############################################################################
source ~/.bash_profile
nvm use 14
###############################################################################
##
## local variables
##
###############################################################################
CWD="$PWD"
REGION=$(aws configure get region)
IDENTITY_POOL_ID="${REGION}:REPLACE-IDENTITY-POOL-ID"
USER_POOL_ID="${REGION}_REPLACE-USER-POOL-ID"
USER_POOL_CLIENT_ID='REPLACE-USER-POOL-WEB-CLIENT-ID'
DEPLOY_JS='false'
DEPLOY_CSS='false'
DEPLOY_IMG='false'
START_LOCAL_SERVER='false'
CERT_NAME='localhost'
ENVIRONMENT='dev'
###############################################################################
##
## cli arguments
##
###############################################################################
for i in "$@"; do
case $i in
--region=*)
REGION="${i#*=}"
;;
--env=*|--environment=*)
ENVIRONMENT="${i#*=}"
;;
--all)
DEPLOY_JS='true'
DEPLOY_CSS='true'
START_LOCAL_SERVER='true'
;;
--js)
DEPLOY_JS='true'
;;
--css)
DEPLOY_CSS='true'
;;
--img)
DEPLOY_IMG='true'
;;
--build-local-certs)
BUILD_LOCAL_CERTS='true'
;;
--start|--start-local-server)
START_LOCAL_SERVER='true'
;;
*)
echo "ERROR: ${i} is not a valid option"
;;
esac
done
###############################################################################
##
## utility function(s)
##
###############################################################################
configure_amplify () {
cd "$CWD/jsx"
echo 'Updating is_local.js with desired values'
cp -nf is_local.js.replace is_local.js
if [ "$(uname)" == "Darwin" ]; then
sed -i'' -e 's/REPLACE-IS-LOCAL/true/g' is_local.js
else
sed -i 's/REPLACE-IS-LOCAL/true/g' is_local.js
fi
echo 'Updating aws-exports.js with desired values'
cp -nf aws-exports.js.replace aws-exports.js
if [ "$(uname)" == "Darwin" ]; then
sed -i'' -e "s/REPLACE-IDENTITY-POOL-ID/${IDENTITY_POOL_ID}/g" aws-exports.js
sed -i'' -e "s/REPLACE-REGION/${REGION}/g" aws-exports.js
sed -i'' -e "s/REPLACE-IDENTITY-REGION/${REGION}/g" aws-exports.js
sed -i'' -e "s/REPLACE-USER-POOL-ID/${USER_POOL_ID}/g" aws-exports.js
sed -i'' -e "s/REPLACE-USER-POOL-WEB-CLIENT-ID/${USER_POOL_CLIENT_ID}/g" aws-exports.js
else
sed -i "s/REPLACE-IDENTITY-POOL-ID/${IDENTITY_POOL_ID}/g" aws-exports.js
sed -i "s/REPLACE-REGION/CognitoRegion/g" aws-exports.js
sed -i "s/REPLACE-IDENTITY-REGION/${REGION}/g" aws-exports.js
sed -i "s/REPLACE-USER-POOL-ID/${USER_POOL_ID}/g" aws-exports.js
sed -i "s/REPLACE-USER-POOL-WEB-CLIENT-ID/${USER_POOL_CLIENT_ID}/g" aws-exports.js
fi
}
compile_js () {
echo 'Notice: compiling javascript'
mkdir -p "${CWD}/static/js/"
cd "${CWD}/jsx"
npm run "build:${ENVIRONMENT}"
mv dist/content.js "${CWD}/static/js/content.js"
}
compile_css () {
echo 'Notice: compiling css'
mkdir -p "${CWD}/static/css/"
cd "${CWD}/scss"
npm run build:css
mv style.css "${CWD}/static/css/style.css"
}
compile_img () {
echo 'Notice: copying image(s)'
mkdir -p "${CWD}/static/img/"
cp -R "${CWD}/img/" "${CWD}/static/img/"
}
build_local_certs () {
echo 'Notice: building openssl local certificate and key'
mkdir -p "${CWD}/certs"
openssl \
req -x509 \
-newkey rsa:2048 \
-nodes \
-sha256 \
-subj '/CN=localhost' \
-keyout "${CWD}/certs/${CERT_NAME}.key" \
-out "${CWD}/certs/${CERT_NAME}.crt"
}
start_local_server () {
echo 'Notice: starting sirv --single'
cd "$CWD"
if npm list -g --depth 0 | grep 'sirv-cli' > /dev/null 2>&1;
then
if [ -f "${CWD}/certs/${CERT_NAME}.key" ] && [ -f "${CWD}/certs/${CERT_NAME}.crt" ]; then
sirv \
--single \
--http2 \
--key "${CWD}/certs/${CERT_NAME}.key" \
--cert "${CWD}/certs/${CERT_NAME}.crt"
else
sirv --single
fi
else
npm install -g sirv-cli
fi
}
###############################################################################
##
## compile
##
###############################################################################
if [ "$DEPLOY_JS" = 'true' ];
then
configure_amplify
compile_js
fi
if [ "$DEPLOY_CSS" = 'true' ];
then
compile_css
fi
if [ "$DEPLOY_IMG" = 'true' ];
then
compile_img
fi
if [ "$BUILD_LOCAL_CERTS" = 'true' ];
then
build_local_certs
fi
###############################################################################
##
## start server
##
###############################################################################
if [ "$START_LOCAL_SERVER" = 'true' ];
then
start_local_server
fi