forked from duenyang/webpack-multipage-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·66 lines (61 loc) · 1.83 KB
/
deploy.sh
File metadata and controls
executable file
·66 lines (61 loc) · 1.83 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/sh
handle=$1;
env=$2;
newDir=$3;
# 使用脚本时,把'your remote ip'替换为你的远程服务器地址即可
# 远程部署机 webhook
# 如果用远程机器部署的话就要用到以下方法
# preHandle(){
# git pull orgin master
# //设置淘宝源,不推荐
# (npm config set registry http://registry.npm.taobao.org/)
# npm install
# npm run build-prod
# }
# 对于在服务器上没有相关的项目目录的,可以尝试新建一个目录,当然你也可以自己去服务器新建一个
newRemoteDir(){
echo "[exec]正在服务器上新建项目目录 remote:your remote ip"
ssh root@your remote ip "mkdir /home/www/dist"
}
# 清空dist目录
emptyRemoteDist(){
if [ $env == "prod" ]
then
echo "[exec]正在清空服务器目录文件 remote:your remote ip(prod)"
ssh root@your remote ip "rm -f /home/www/dist/*"
else
echo "[exec]正在清空服务器目录文件 remote:your remote ip(dev)"
ssh root@your remote ip "rm -f /home/www/dist/*"
fi
}
# 发送文件到正式服
transferFileToProSever(){
echo "[exec]正在发送文件到正式服 remote:your remote ip(prod)"
scp -r ./dist/* root@your remote ip:/home/www/dist/
}
# 发送文件到测试服
transferFileToTestSever(){
echo "[exec]正在发送文件到测试服 remote:your remote ip(dev)"
scp -r ./dist/* root@your remote ip:/home/www/dist/
}
if [ $handle == "build" ]
then
if [ $newDir == "newDir" ]
then
newRemoteDir
fi
if [ $env == "prod" ]
then
env='prod'
echo "[exec]build ==> build production"
npm run build
emptyRemoteDist
transferFileToProSever
else
env='dev'
echo "[exec]build ==> build development"
npm run build
emptyRemoteDist
transferFileToTestSever
fi
fi