forked from aripalo/gatsby-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·69 lines (57 loc) · 1.26 KB
/
entrypoint.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
#!/bin/sh
set -e
set -o errexit
export GATSBY_DIR="/site"
export PATH="$PATH:/usr/local/bin/gatsby"
# Change ownership to directories and files
change_owner() {
USER_ID=$(stat -c '%u' $GATSBY_DIR )
GROUP_ID=$(stat -c '%g' $GATSBY_DIR)
echo "Change owner to $USER_ID:$GROUP_ID"
chown -R "$USER_ID":"$GROUP_ID" $GATSBY_DIR
}
# Initialize Gatsby or run NPM install if needed
check_project() {
if [ ! -f "$GATSBY_DIR/package.json" ]
then
echo "Initializing Gatsby..."
gatsby new $GATSBY_DIR
change_owner
else
if [ ! -e "$GATSBY_DIR/node_modules/" ]
then
echo "Node modules is empty. Running npm install..."
npm install
change_owner
fi
fi
}
# Decide what to do
if [ "$1" = "develop" ]
then
echo "Corriendo el proyecto"
rm -rf $GATSBY_DIR/public
gatsby $@ --host 0.0.0.0
elif [ "$1" = "build" ]
then
rm -rf $GATSBY_DIR/public
gatsby build
change_owner
elif [ "$1" = "stage" ]
then
rm -rf $GATSBY_DIR/public
gatsby build
change_owner
gatsby serve --port 8000
elif [ "$1" = "new" ]
then
[ -z "$2" ] echo "Initializing Gatsby from $2" || echo "Initializing default new project's Gatsby"
gatsby new $GATSBY_DIR $2
change_owner
else
if [ "$1" != "gatsby" ]
then
check_project
fi
exec $@
fi