forked from hajkmap/Hajk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·127 lines (109 loc) · 3.19 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
#!/bin/bash
# README
#
# The following script will NOT copy/overwrite those files/directories:
# App_Data/
# logs/ (but backend will create it where needed)
# static/
# .env
#
# YOU NEED TO ENSURE THAT THEY EXIST MANUALLY!
#
# This script assumes that $GIT_DIR is a valid Hajk git repo.
# It will get the latest backend, client and admin and installed
# to $DEST_DIR. Backend will go directly to $DEST_DIR, while
# client and admin will be exposed via the static functionality
# built into backend. You will find the static build of them in
# $DEST_DIR/static/{admin|client}.
# You will be able to run the whole package (backend, as well as
# it serving the static client and admin apps) via one command:
# node index.js
show_usage() {
echo "Usage: $0 git_dir dest_dir" 1>&2
exit 1
}
# Main program starts here
if [ $# -ne 2 ]; then
show_usage
else # There are two arguments
if [ -d $1 ]; then
# First argument is a valid directory, use it
GIT_DIR=$1
else
echo 'Invalid git directory'
show_usage
fi
if [ -d $2 ]; then
# Second argument is a valid directory too
DEST_DIR=$2
else
echo 'Invalid destination directory'
show_usage
fi
fi
# Resolve relative paths
GIT_DIR=$(cd $GIT_DIR && pwd)
DEST_DIR=$(cd $DEST_DIR && pwd)
echo "Building from git directory: ${GIT_DIR}"
echo "Deploying build to destination: ${DEST_DIR}"
# Got to our repo dir and grab the latest from Git
echo "Downloading the latest code..."
cd $GIT_DIR
git fetch
git pull
# BACKEND
echo "Installing backend dependencies..."
cd $GIT_DIR/new-backend
# Before we can compile, we need to install NPM deps.
# Make sure to get the latest by first removing the dir entirely.
rm -rf node_modules/
npm ci
# Build. Will create the dist directory.
echo "Building backend..."
npm run compile
echo "Copying backend to destination..."
# Copy the results
cp -r dist/* $DEST_DIR
cp package*.json $DEST_DIR
# Install deps in the final destination
cd $DEST_DIR
rm -rf node_modules
npm ci
# Next step is to build client and admin and put them to $DEST_DIR/static
# so that backend can serve them. Make sure that you've enabled that
# functionality in your .env too!
# Ensure that the static dir exists, if not, create it
mkdir -p $DEST_DIR/static
# CLIENT
echo "Preparing to install client dependencies..."
cd $GIT_DIR/new-client
rm -rf node_modules/
echo "Installing client dependencies..."
npm ci
echo "Building client..."
npm run build
rm -rf $DEST_DIR/static/client/static
echo "Copying client to destination..."
cd build
cp -r static $DEST_DIR/static/client
cp asset-manifest.json $DEST_DIR/static/client
cp index.* $DEST_DIR/static/client
cp manifest.json $DEST_DIR/static/client
# ADMIN
echo "Preparing to install admin dependencies..."
cd $GIT_DIR/new-admin
rm -rf node_modules/
echo "Installing admin dependencies..."
npm ci
echo "Building admin..."
npm run build
echo "Copying admin to destination..."
rm -rf $DEST_DIR/static/admin/static
rm -rf $DEST_DIR/static/admin/precache-manifest*
cd build
cp -r static $DEST_DIR/static/admin
cp asset-manifest.json $DEST_DIR/static/admin
cp index.* $DEST_DIR/static/admin
cp manifest.json $DEST_DIR/static/admin
cp precache*.js $DEST_DIR/static/admin
echo "All done, the latest Hajk is now installed in ${DEST_DIR}"