forked from tericcabrel/node-restapi-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·48 lines (40 loc) · 1.21 KB
/
deploy.sh
File metadata and controls
executable file
·48 lines (40 loc) · 1.21 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
#!/usr/bin/env bash
APP_NAME='node-rest-starter'
if [[ $1 == 'run' ]]; then
# Install node packages
yarn
# If the directory build exists, rename the folder to build-old
if [[ -d './build' ]]; then
mv ./build ./build-old
fi
# Compile files from Typescript to ES5
tsc
# Copy the folders who was not moved during the Typescript compilation
cp -r ./app/views ./build
cp -r ./app/locale ./build
cp -r ./app/core/mailer/templates ./build/core/mailer
FILE=./build-old/.env.prod
# If the configuration file exists in build-old copy into build
# Otherwise, create it's from the .env template file (.env.example)
if [[ -f "$FILE" ]]; then
cp ${FILE} ./build/
rm -rf ./build-old
else
cp .env.example ./build/.env.prod
nano ./build/.env.prod
fi
if [[ $2 == 'docker' ]]; then
docker-compose -f docker-compose.prod.yml up --build
else
# Launch the application with pm2
NODE_ENV=production pm2 start ./build/index.js --name ${APP_NAME}
fi
elif [[ $1 == 'restart' ]]; then
pm2 restart ${APP_NAME}
elif [[ $1 == 'stop' ]]; then
pm2 stop ${APP_NAME}
elif [[ $1 == 'reset' ]]; then
pm2 stop ${APP_NAME} && pm2 delete ${APP_NAME}
else
echo "Unknown command"
fi