添加动态发布配置
This commit is contained in:
parent
a1574cad53
commit
6cad8a2eeb
13
CHANGELOG.md
13
CHANGELOG.md
|
@ -1,5 +1,18 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2.0.3
|
||||||
|
|
||||||
|
- 修改测试与正式两个配置方式为动态配置
|
||||||
|
|
||||||
|
## 2.0.2
|
||||||
|
|
||||||
|
- 修复找不到动画类的bug
|
||||||
|
- 修改项目地址,调整部分文件位置
|
||||||
|
|
||||||
|
## 2.0.1
|
||||||
|
|
||||||
|
- 修复示例文档的bug
|
||||||
|
- 添加加密页面
|
||||||
## 2.0.0
|
## 2.0.0
|
||||||
|
|
||||||
- 添加ftp/sftp上传功能
|
- 添加ftp/sftp上传功能
|
||||||
|
|
30
README.md
30
README.md
|
@ -7,17 +7,18 @@
|
||||||
npm install @dllcn/auto-deploy -D
|
npm install @dllcn/auto-deploy -D
|
||||||
```
|
```
|
||||||
|
|
||||||
2. 添加执行命令
|
2. 在`package.json`的`scripts`添加执行命令
|
||||||
```
|
```
|
||||||
"deploy": "node ./node_modules/@dllcnx/auto-deploy"
|
"deploy": "node ./node_modules/@dllcnx/auto-deploy"
|
||||||
```
|
```
|
||||||
|
|
||||||
3. 在项目根目录创建`deploy.config.js`文件:
|
3. 在项目根目录创建`deploy.config.js`文件,可配置多个发布服务,例如以下配置了三个:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// 配置示例,具体配置看配置
|
// 配置示例,具体配置看配置
|
||||||
module.exports = Object.freeze({
|
module.exports = Object.freeze({
|
||||||
development: {//ftp配置
|
ftp: {//ftp配置
|
||||||
|
NAME: "ftp发布",
|
||||||
SERVER_HOST: 'xxx', // 服务器地址
|
SERVER_HOST: 'xxx', // 服务器地址
|
||||||
USER: 'root', // 用户名
|
USER: 'root', // 用户名
|
||||||
PASSWORD: 'xxx', //密码,需加密,加密页面参考下面链接
|
PASSWORD: 'xxx', //密码,需加密,加密页面参考下面链接
|
||||||
|
@ -30,7 +31,22 @@ npm install @dllcn/auto-deploy -D
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
production: {//ssh
|
sftp: {//ftp配置
|
||||||
|
NAME: "sftp发布",
|
||||||
|
SERVER_HOST: 'xxx', // 服务器地址
|
||||||
|
USER: 'root', // 用户名
|
||||||
|
PASSWORD: 'xxx', //密码,需加密,加密页面参考下面链接
|
||||||
|
REMOTE_ROOT: '/web/test/', // 需要上传的服务器目录地址 如 /usr/local/nginx/html
|
||||||
|
LOCAL_PATH: "dist", // 需要上传文件夹路径,默认dist
|
||||||
|
PORT: 5521,
|
||||||
|
TYPE: "ftp", // ftp,sftp,ssh 模认ssh
|
||||||
|
FTP_CONFIG:{
|
||||||
|
DELETE_REMOTE: true,
|
||||||
|
...
|
||||||
|
}
|
||||||
|
},
|
||||||
|
ssh: {//ssh
|
||||||
|
NAME: "sftp发布",
|
||||||
SERVER_HOST: 'xxx',
|
SERVER_HOST: 'xxx',
|
||||||
USER: 'root',
|
USER: 'root',
|
||||||
//方式一 用秘钥登录服务器(推荐), private 本机私钥文件地址(需要在服务器用户目录 一般是 /root/.ssh/authorized_keys 配置公钥 并该文件权限为 600, (.ssh文件夹一般默认隐藏)
|
//方式一 用秘钥登录服务器(推荐), private 本机私钥文件地址(需要在服务器用户目录 一般是 /root/.ssh/authorized_keys 配置公钥 并该文件权限为 600, (.ssh文件夹一般默认隐藏)
|
||||||
|
@ -49,9 +65,15 @@ npm install @dllcn/auto-deploy -D
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
4. 执行`npm run deploy`发布命令
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
### 配置
|
### 配置
|
||||||
|
|
||||||
#### 基础配置
|
#### 基础配置
|
||||||
|
- **name**: 配置名称,默认采用key值
|
||||||
- **SERVER_HOST**: 服务器地址
|
- **SERVER_HOST**: 服务器地址
|
||||||
- **USER**: 服务器用户名
|
- **USER**: 服务器用户名
|
||||||
- **PASSWORD**: 密码
|
- **PASSWORD**: 密码
|
||||||
|
|
23
index.js
23
index.js
|
@ -1,13 +1,24 @@
|
||||||
const pathHierarchy = '../../../' //脚本到项目的层级 项目/node_modules/deploy-node/index.js
|
// const pathHierarchy = '../../../' //脚本到项目的层级 项目/node_modules/deploy-node/index.js
|
||||||
// const pathHierarchy = './test/' //测试目录
|
const pathHierarchy = './test/' //测试目录
|
||||||
|
|
||||||
const inquirer = require('inquirer') //命令行交互
|
const inquirer = require('inquirer') //命令行交互
|
||||||
const runUploadTask = require('./ssh/upload')
|
const runUploadTask = require('./ssh/upload')
|
||||||
const runFtpTask = require('./ftp/index')
|
const runFtpTask = require('./ftp/index')
|
||||||
|
|
||||||
let DCONFIG;
|
let DCONFIG;
|
||||||
|
let choices = [];
|
||||||
try {
|
try {
|
||||||
DCONFIG = require(`${pathHierarchy}deploy.config.js`) // 项目配置
|
DCONFIG = require(`${pathHierarchy}deploy.config.js`) // 项目配置
|
||||||
|
// console.log(DCONFIG)
|
||||||
|
for (const key in DCONFIG) {
|
||||||
|
if (Object.hasOwnProperty.call(DCONFIG, key)) {
|
||||||
|
const element = DCONFIG[key].NAME || key;
|
||||||
|
choices.push({
|
||||||
|
name: element,
|
||||||
|
value: key
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
errorLog('请在项目根目录添加 deploy.config.js 配置文件, 参考说明文档中的配置')
|
errorLog('请在项目根目录添加 deploy.config.js 配置文件, 参考说明文档中的配置')
|
||||||
process.exit() //退出流程
|
process.exit() //退出流程
|
||||||
|
@ -50,13 +61,7 @@ inquirer
|
||||||
type: 'list',
|
type: 'list',
|
||||||
message: '选择您的部署环境',
|
message: '选择您的部署环境',
|
||||||
name: 'env',
|
name: 'env',
|
||||||
choices: [{
|
choices: choices,
|
||||||
name: '测试环境',
|
|
||||||
value: 'development'
|
|
||||||
}, {
|
|
||||||
name: '正式环境',
|
|
||||||
value: 'production'
|
|
||||||
}],
|
|
||||||
when: function (answers) { // 当watch为true的时候才会提问当前问题
|
when: function (answers) { // 当watch为true的时候才会提问当前问题
|
||||||
return answers.confirm
|
return answers.confirm
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
"description": "自动部署脚本",
|
"description": "自动部署脚本",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"publish": "npm publish"
|
"publish": "npm publish",
|
||||||
|
"test": "node index.js"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
Loading…
Reference in New Issue