部署流程:(执行 zr-deploy
后)
- 选择部署环境
配置文件 zr-deploy-config.json
- 打包:执行配置文件的
打包命令 buildCommand
打包项目 - 压缩:打包完成后将文件压缩
local.distDir -> local.distZip
- 连接服务器:
node-ssh
连接服务器 - 上传代码:上传文件到项目目录(
server.distDir
) server.bakeup
true false- 解压缩项目文件
- 部署成功
:point_right:
已发布 npm
,:point_right: zr-deploy
源码 github
,:point_right: zr-deploy
md-note
在这里:point_right: md-note
工具使用
下载
注意 加 -g
/ global
下载到全局,不然会提示找不到命令!
这样也不用每个项目加这个依赖,只要进到项目目录下,添加配置文件后,执行 zr-deploy
就能部署了
npm i -g zr-deploy
复制代码
或
yarn global add zr-deploy
复制代码
然后在 项目根目录 新建配置文件 zr-deploy-config.json
,
记住 加到 .gitignore
,不要把它上传到 github
上面了
执行
进入项目目录
zr-deploy
复制代码
配置文件
local
buildCommand distDir distZipserver
name host username password distDir distZipName bakeup
zr-deploy-config.json
格式如下
[
{
"local": {
"buildCommand": "yarn build",
"distDir": "./docs",
"distZip": "./dist.zip"
},
"server": {
"name": "服务器1",
"host": "1.1.1.1",
"username": "username",
"password": "password",
"distDir": "/var/www/xxx/xxx",
"distZipName": "dist",
"bakeup": false
}
},
{
"local": {
"buildCommand": "yarn build",
"distDir": "./docs",
"distZip": "./dist.zip"
},
"server": {
"name": "服务器2",
"host": "2.2.2.2",
"username": "username",
"password": "password",
"distDir": "/var/www/xxx/xxx",
"distZipName": "dist",
"bakeup": false
}
}
]
复制代码
工具说明
目录结构
.
├── CHANGE_LOG.md
├── Description.md
├── README.md
├── README_zh.md
├── __test__
│ ├── buildDist.t.js
│ ├── compressDist.t.js
│ ├── getConfig.t.js
│ ├── index.test.js
│ └── zr-deploy-config.json
├── bin
│ └── zr-deploy.js
├── package-lock.json
├── package.json
└── src
├── buildDist.js
├── compressDist.js
├── deploy.js
├── getConfig.js
├── index.js