Skip to content

Commit

Permalink
✨ 新增回调函数
Browse files Browse the repository at this point in the history
  • Loading branch information
ossso committed Jul 17, 2024
1 parent 9af68ce commit 3fd1023
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
21 changes: 21 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ deploy({
// privateKey: '',
},
},
callback: {
deployBefore: (files, tasks) => {
// 部署前的回调
// files,扫描到的文件列表
// tasks,执行任务对象
},
deployAfter: (files, tasks) => {
// 部署后的回调
// files,扫描到文件列表
// tasks,执行任务对象
},
},
});
```

Expand Down Expand Up @@ -83,3 +95,12 @@ deploy({
| **server** | `Object` | null | 服务器的配置,参考配置概览 |

-----------

### `callback:` 回调函数

| 属性 | 值类型 | 默认值 | 说明 |
| ---- | ---- | ---- | ---- |
| **deployBefore** | `Function` | null | 部署前回调,支持异步,`files` 扫描到的文件列表,`tasks` 执行任务对象 |
| **deployAfter** | `Function` | null | 部署后回调,支持异步,`files` 扫描到的文件列表,`tasks` 执行任务对象 |

-----------
11 changes: 11 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ const deploy = async ({
// 规则
rule,
config,
callback,
}) => {
const {
deployBefore,
deployAfter,
} = callback || {};
const startTime = Date.now();
console.log(chalk.white(` 正在扫描目录[${dir}] `));
const {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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(' 部署完成 '));
};

Expand Down

0 comments on commit 3fd1023

Please sign in to comment.