-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathdeploy.sh
executable file
·72 lines (60 loc) · 1.78 KB
/
deploy.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
#!/usr/bin/env bash
#Create by Jason <[email protected]>
#This is meant for production
# > ./deploy.sh skipInstall skipBuild skipServer
##Using node >= 8
#nvm use 8
#source $HOME/.nvm/nvm.sh; nvm use 8
echo $(which node)
echo $(which pm2)
basepath=$(cd `dirname $0`; pwd)
cd ${basepath}
#Simple script to run app quickly
NodeVersion=$(node -v)
if [[ $? != 0 ]]; then
#nodejs not installed yet
echo ERROR: nodejs is not installed currently, pls install nodejs to continue
exit
else
echo node/${NodeVersion}, npm/$(npm -v)
# echo yarn/$(yarn -v)
fi
##Remove the freaking package-lock.json
#rm -f package-lock.json
##Installing npm modules
if [[ $1 != "1" ]]; then
##=====Uncomment script below if you are in China=====
#TaobaoRegistry="http://registry.npm.taobao.org/"
#NpmRegistry=$(npm config get registry)
#if [ "$TaobaoRegistry" != "$NpmRegistry" ]; then
# echo changing npm registry to taobao registry: "$TaobaoRegistry"
# npm config set registry "$TaobaoRegistry"
#fi
##Change SASS binary site to taobao
#export SASS_BINARY_SITE=https://npm.taobao.org/mirrors/node-sass/
echo installing npm modules...
##Don't install based on the package-lock.json by default, instead, only refer to package.json
##Change at your own risk
npm install --no-shrinkwrap
# yarn install --production=false
fi
if [[ $2 != "1" ]]; then
##webpack is bundling modules
echo webpack is bundling modules...
npm run build
npm run ssr
echo =====Build Finished=====
#yarn run build
fi
##Start server with pm2
if [[ $3 != "1" ]]; then
export NODE_ENV=production
PM2Version=$(pm2 -v)
if [[ $? != 0 ]]; then
echo ERROR: pls install pm2 to continue...
exit
fi
echo NODE_ENV: ${NODE_ENV}
echo "Using pm2: [$(which pm2)]"
pm2 reload pm2.config.js --update-env --env production
fi