-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathbuild_critical_css.sh
executable file
·37 lines (31 loc) · 1.05 KB
/
build_critical_css.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
#!/bin/bash
set -euo pipefail # Exit on errors and undefined variables.
# Get the directory of this script:
# https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# Import the domain and port
ENV_PATH="$DIR/../../.env"
if [[ ! -f $ENV_PATH ]]; then
echo "Failed to find the \".env\" file at: $ENV_PATH"
exit 1
fi
source "$ENV_PATH"
if [[ -z ${DOMAIN-} ]]; then
DOMAIN="localhost"
fi
if [[ -z ${PORT-} ]]; then
PORT="80"
fi
if [[ -n ${TLS_CERT_FILE-} ]]; then
echo "A production environment has been detected. You cannot build critical CSS in production. Instead, run this script on a local development server and push the changes to the git repository."
exit 1
fi
URL="http://$DOMAIN:$PORT"
# Test to see if the server is running
if ! curl --silent "$URL" > /dev/null; then
echo "You must ensure that the server is running before running this script."
exit 1
fi
# Rebuild the critical CSS
cd "$DIR"
npx grunt critical --url="$URL"