From 3fd1023784e75065ae77ac61f992751b9dea10ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E8=89=B2=E9=98=B3=E5=85=89?= <1122@hizhou.cn> Date: Wed, 17 Jul 2024 17:59:05 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E6=96=B0=E5=A2=9E=E5=9B=9E?= =?UTF-8?q?=E8=B0=83=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- readme.md | 21 +++++++++++++++++++++ src/index.js | 11 +++++++++++ 2 files changed, 32 insertions(+) diff --git a/readme.md b/readme.md index 1a84ccd..a859d0f 100644 --- a/readme.md +++ b/readme.md @@ -50,6 +50,18 @@ deploy({ // privateKey: '', }, }, + callback: { + deployBefore: (files, tasks) => { + // 部署前的回调 + // files,扫描到的文件列表 + // tasks,执行任务对象 + }, + deployAfter: (files, tasks) => { + // 部署后的回调 + // files,扫描到文件列表 + // tasks,执行任务对象 + }, + }, }); ``` @@ -83,3 +95,12 @@ deploy({ | **server** | `Object` | null | 服务器的配置,参考配置概览 | ----------- + +### `callback:` 回调函数 + +| 属性 | 值类型 | 默认值 | 说明 | +| ---- | ---- | ---- | ---- | +| **deployBefore** | `Function` | null | 部署前回调,支持异步,`files` 扫描到的文件列表,`tasks` 执行任务对象 | +| **deployAfter** | `Function` | null | 部署后回调,支持异步,`files` 扫描到的文件列表,`tasks` 执行任务对象 | + +----------- diff --git a/src/index.js b/src/index.js index 02e6f40..1269e68 100644 --- a/src/index.js +++ b/src/index.js @@ -15,7 +15,12 @@ const deploy = async ({ // 规则 rule, config, + callback, }) => { + const { + deployBefore, + deployAfter, + } = callback || {}; const startTime = Date.now(); console.log(chalk.white(` 正在扫描目录[${dir}] `)); const { @@ -71,6 +76,9 @@ const deploy = async ({ width: Math.min(total * 2, 30), }); + if (typeof deployBefore === 'function') { + await deployBefore(files, tasks, transferToTasks); + } try { // OSS上传 if (tasks.oss.length) { @@ -101,6 +109,9 @@ const deploy = async ({ console.log(chalk.bgRed(' 部署异常 ')); throw error; } + if (typeof deployAfter === 'function') { + await deployAfter(files, tasks); + } console.log(chalk.bgBlue(' 部署完成 ')); };