From 6cad8a2eeb72297f24e27f29228491ef8576109a Mon Sep 17 00:00:00 2001 From: jukaifeng Date: Tue, 17 Jan 2023 23:15:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=A8=E6=80=81=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 13 +++++++++++++ README.md | 30 ++++++++++++++++++++++++++---- index.js | 23 ++++++++++++++--------- package.json | 3 ++- 4 files changed, 55 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d3740e..e742e48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Changelog +## 2.0.3 + + - 修改测试与正式两个配置方式为动态配置 + +## 2.0.2 + + - 修复找不到动画类的bug + - 修改项目地址,调整部分文件位置 + +## 2.0.1 + + - 修复示例文档的bug + - 添加加密页面 ## 2.0.0 - 添加ftp/sftp上传功能 diff --git a/README.md b/README.md index 4d00c8d..2d7fa30 100644 --- a/README.md +++ b/README.md @@ -7,17 +7,18 @@ npm install @dllcn/auto-deploy -D ``` -2. 添加执行命令 +2. 在`package.json`的`scripts`添加执行命令 ``` "deploy": "node ./node_modules/@dllcnx/auto-deploy" ``` -3. 在项目根目录创建`deploy.config.js`文件: +3. 在项目根目录创建`deploy.config.js`文件,可配置多个发布服务,例如以下配置了三个: ```javascript // 配置示例,具体配置看配置 module.exports = Object.freeze({ - development: {//ftp配置 + ftp: {//ftp配置 + NAME: "ftp发布", SERVER_HOST: 'xxx', // 服务器地址 USER: 'root', // 用户名 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', USER: 'root', //方式一 用秘钥登录服务器(推荐), private 本机私钥文件地址(需要在服务器用户目录 一般是 /root/.ssh/authorized_keys 配置公钥 并该文件权限为 600, (.ssh文件夹一般默认隐藏) @@ -49,9 +65,15 @@ npm install @dllcn/auto-deploy -D ``` + +4. 执行`npm run deploy`发布命令 + +![image-20230117231310216](https://dllcnx.com:10011/2023/01/202301172313308.png) + ### 配置 #### 基础配置 +- **name**: 配置名称,默认采用key值 - **SERVER_HOST**: 服务器地址 - **USER**: 服务器用户名 - **PASSWORD**: 密码 diff --git a/index.js b/index.js index 996e9fa..9ed7680 100644 --- a/index.js +++ b/index.js @@ -1,13 +1,24 @@ -const pathHierarchy = '../../../' //脚本到项目的层级 项目/node_modules/deploy-node/index.js -// const pathHierarchy = './test/' //测试目录 +// const pathHierarchy = '../../../' //脚本到项目的层级 项目/node_modules/deploy-node/index.js +const pathHierarchy = './test/' //测试目录 const inquirer = require('inquirer') //命令行交互 const runUploadTask = require('./ssh/upload') const runFtpTask = require('./ftp/index') let DCONFIG; +let choices = []; try { 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) { errorLog('请在项目根目录添加 deploy.config.js 配置文件, 参考说明文档中的配置') process.exit() //退出流程 @@ -50,13 +61,7 @@ inquirer type: 'list', message: '选择您的部署环境', name: 'env', - choices: [{ - name: '测试环境', - value: 'development' - }, { - name: '正式环境', - value: 'production' - }], + choices: choices, when: function (answers) { // 当watch为true的时候才会提问当前问题 return answers.confirm } diff --git a/package.json b/package.json index c37c48c..f1dedb0 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "自动部署脚本", "main": "index.js", "scripts": { - "publish": "npm publish" + "publish": "npm publish", + "test": "node index.js" }, "repository": { "type": "git",