Skip to content

Commit

Permalink
添加是否删除本地打包文件配置项
Browse files Browse the repository at this point in the history
  • Loading branch information
fuchengwei committed Dec 30, 2020
1 parent d29853b commit 0c10ec5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 19 deletions.
22 changes: 7 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ npm install deploy-cli-service --save-dev
查看版本,表示安装成功

```javascript
deploy-cli-service -v
deploy - cli - service - v
```

注:本地安装的需要在调用前加 `npx`
Expand All @@ -42,8 +42,6 @@ npx deploy-cli-service -v

![](https://ae01.alicdn.com/kf/U943f01b07cdd492499f3186582d813c8n.jpg)



### 2 使用(以下代码都以全局安装为例)

#### 2.1 查看帮助
Expand All @@ -54,8 +52,6 @@ deploy-cli-service -h

![](https://ae01.alicdn.com/kf/Ud0667faaa3ef44939c8c016eb8a1cc026.jpg)



#### 2.2 初始化配置文件(在项目目录下)

```shell
Expand All @@ -66,8 +62,6 @@ deploy-cli-service init # 或者使用简写 deploy-cli-service i

![](https://ae01.alicdn.com/kf/Uf9bb311b13764e4aa25c51d57b52bdc2Z.jpg)



#### 2.3 手动创建或修改配置文件

在项目根目录下手动创建 `deploy.config.js` 文件,复制以下代码按情况修改即可。
Expand All @@ -88,7 +82,8 @@ module.exports = {
password: '123456', // 服务器登录密码
distPath: 'dist', // 本地打包生成目录
webDir: '/usr/local/nginx/html', // 服务器部署路径(不可为空或'/')
isRemoveRemoteFile: true // 是否删除远程文件(默认true)
isRemoveRemoteFile: true, // 是否删除远程文件(默认true)
isRemoveLocalFile: true // 是否删除本地文件(默认true)
},
test: {
// 环境对象
Expand All @@ -100,7 +95,8 @@ module.exports = {
password: '123456', // 服务器登录密码
distPath: 'dist', // 本地打包生成目录
webDir: '/usr/local/nginx/html', // 服务器部署路径(不可为空或'/')
isRemoveRemoteFile: true // 是否删除远程文件(默认true)
isRemoveRemoteFile: true, // 是否删除远程文件(默认true)
isRemoveLocalFile: true // 是否删除本地文件(默认true)
},
prod: {
// 环境对象
Expand All @@ -112,7 +108,8 @@ module.exports = {
password: '123456', // 服务器登录密码
distPath: 'dist', // 本地打包生成目录
webDir: '/usr/local/nginx/html', // 服务器部署路径(不可为空或'/')
isRemoveRemoteFile: true // 是否删除远程文件(默认true)
isRemoveRemoteFile: true, // 是否删除远程文件(默认true)
isRemoveLocalFile: true // 是否删除本地文件(默认true)
}
}
```
Expand All @@ -129,8 +126,6 @@ deploy-cli-service deploy --mode dev # 或者使用 deploy-cli-service d --mode

![](https://ae01.alicdn.com/kf/U6c196c63cab242cd894371c6d0725d87Q.jpg)



#### 2.5 集群部署 (在项目目录下)

注意:集群配置需要在 `deploy-cli-service` 中 配置 `cluster` 字段 (如:`cluster: ['dev', 'test', 'prod']`
Expand All @@ -143,8 +138,6 @@ deploy-cli-service deploy # 或者使用 deploy-cli-service d

![](https://ae01.alicdn.com/kf/Ue11c75ee338844ac9f3668686879f988E.jpg)



#### 2.6 更新优化

如果不想把服务器密码保存在配置文件中,也可以在配置文件中删除 `password` 字段。在部署的时候会弹出输入密码界面。
Expand Down Expand Up @@ -174,4 +167,3 @@ npm run deploy:dev
```

最后如果大家觉得还不错挺好用的话,麻烦给个 Star 😜😜😜。

4 changes: 2 additions & 2 deletions lib/commands/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ const disconnectSSH = () => {

// 创建任务列表
const createTaskList = (config) => {
const { script, isRemoveRemoteFile = true } = config
const { script, isRemoveRemoteFile = true, isRemoveLocalFile = true } = config

taskList = []
script && taskList.push(execBuild)
Expand All @@ -241,7 +241,7 @@ const createTaskList = (config) => {
taskList.push(uploadLocalFile)
isRemoveRemoteFile && taskList.push(removeRemoteFile)
taskList.push(unzipRemoteFile)
taskList.push(removeLocalFile)
isRemoveLocalFile && taskList.push(removeLocalFile)
taskList.push(disconnectSSH)
}

Expand Down
3 changes: 2 additions & 1 deletion lib/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ const createJsonObj = (userInputInfo) => {
password: userInputInfo[`${env}Password`],
distPath: userInputInfo[`${env}DistPath`],
webDir: userInputInfo[`${env}WebDir`],
isRemoveRemoteFile: userInputInfo[`${env}IsRemoveRemoteFile`]
isRemoveRemoteFile: userInputInfo[`${env}IsRemoveRemoteFile`],
isRemoveLocalFile: userInputInfo[`${env}IsRemoveLocalFile`]
}
}

Expand Down
21 changes: 21 additions & 0 deletions lib/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ const devConfig = [
message: '是否删除远程文件',
default: true,
when: (answers) => answers.deployEnvList.includes('dev')
},
{
type: 'confirm',
name: 'devIsRemoveLocalFile',
message: '是否删除本地打包文件',
default: true,
when: (answers) => answers.deployEnvList.includes('dev')
}
]

Expand Down Expand Up @@ -125,6 +132,13 @@ const testConfig = [
message: '是否删除远程文件',
default: true,
when: (answers) => answers.deployEnvList.includes('test')
},
{
type: 'confirm',
name: 'testIsRemoveLocalFile',
message: '是否删除本地打包文件',
default: true,
when: (answers) => answers.deployEnvList.includes('test')
}
]

Expand Down Expand Up @@ -188,6 +202,13 @@ const prodConfig = [
message: '是否删除远程文件',
default: true,
when: (answers) => answers.deployEnvList.includes('prod')
},
{
type: 'confirm',
name: 'prodIsRemoveLocalFile',
message: '是否删除本地打包文件',
default: true,
when: (answers) => answers.deployEnvList.includes('prod')
}
]

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "deploy-cli-service",
"version": "1.2.3",
"version": "1.2.4",
"description": "前端一键自动化部署脚手架服务",
"main": "lib/service.js",
"homepage": "https://github.com/fuchengwei/deploy-cli-service",
Expand Down

0 comments on commit 0c10ec5

Please sign in to comment.