Skip to content

Commit 6a360d9

Browse files
committed
feat(plugin): add buildStart hook
1 parent 506445e commit 6a360d9

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

.changeset/clean-mugs-fold.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@umijs/tnf': patch
3+
---
4+
5+
feat(plugin): add buildStart hook

docs/plugin.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
# Plugin
22

3+
## Properties
4+
5+
### name
6+
7+
- Type: `string`
8+
9+
Plugin name.
10+
11+
### enforce
12+
13+
- Type: `'pre' | 'post'`
14+
15+
Plugin execution order.
16+
317
## General Hooks
418

519
### buildStart
620

7-
> Not implemented
8-
921
- Type: `(ctx: { command: string }) => void | Promise<void>`
1022

1123
Called when build start.

examples/normal/.tnfrc.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ export default defineConfig({
99
},
1010
plugins: [
1111
{
12+
buildStart: ({ command }) => {
13+
console.log('buildStart', command);
14+
},
1215
buildEnd: ({ command, err }) => {
1316
console.log('buildEnd', command, err);
1417
},

src/cli.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { debug, error, info, warn } from './fishkit/logger';
77
import * as logger from './fishkit/logger';
88
import { checkVersion, setNoDeprecation, setNodeTitle } from './fishkit/node';
99
import { mock } from './funplugins/mock/mock';
10-
import { PluginManager } from './plugin/plugin_manager';
10+
import { PluginHookType, PluginManager } from './plugin/plugin_manager';
1111
import { type Context, Mode } from './types';
1212

1313
async function buildContext(cwd: string): Promise<Context> {
@@ -46,6 +46,16 @@ async function run(cwd: string) {
4646
const context = await buildContext(cwd);
4747
const cmd = context.argv._[0];
4848
assert(cmd, 'Command is required');
49+
50+
if (cmd === 'build' || cmd === 'dev') {
51+
await context.pluginManager.apply({
52+
hook: 'buildStart',
53+
args: [{ command: cmd }],
54+
type: PluginHookType.Parallel,
55+
pluginContext: context.pluginContext,
56+
});
57+
}
58+
4959
switch (cmd) {
5060
case 'build':
5161
const { build } = await import('./build.js');

0 commit comments

Comments
 (0)