Skip to content
This repository was archived by the owner on Feb 6, 2025. It is now read-only.

Commit 877151f

Browse files
committed
(docs): Making the before and after lifecycle functions page more clear.
1 parent c1347a6 commit 877151f

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

docs/plugins/before-after.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ slug: /plugins/plugin-events/plugin-events-before-after
99

1010
All events expose an identical interface with two functions that can be handled by the plugin and responsible for a different step in the lifecycle of the event. One for "before" the event is emitted and another for "after" the event is emitted.
1111

12+
## Event Structure and Parameters
13+
1214
```tsx
1315
export interface PluginEventType<T extends EventParams> {
1416
before?: PluginBeforeEvent<T>;
@@ -20,20 +22,24 @@ For each event, the type of `EventParams` is different, providing access to rele
2022

2123
```tsx
2224
export interface EventParams {}
25+
```
2326

27+
## Before and After Function Signatures
28+
29+
```tsx
2430
export type PluginBeforeEvent<T extends EventParams> = (
2531
dsgContext: DsgContext,
2632
eventParams: T
2733
) => Promisable<T>;
2834

29-
// Node.js [version](https://github.com/amplication/amplication/blob/master/libs/util/code-gen-types/src/plugins.types.ts#L21)
35+
// Node.js version
3036
export type PluginAfterEvent<T extends EventParams> = (
3137
dsgContext: DsgContext,
3238
eventParams: T,
3339
modules: ModuleMap
3440
) => Promisable<ModuleMap>;
3541

36-
// .NET [version](https://github.com/amplication/amplication/blob/master/libs/util/code-gen-types/src/dotnet-plugins.types.ts#L22)
42+
// .NET version
3743
export type PluginAfterEvent<T extends EventParams, F> = (
3844
dsgContext: DsgContext,
3945
eventParams: T,
@@ -45,13 +51,19 @@ In the `before` and `after` functions, we have an access to the context and the
4551
The [context](docs\plugins\context.md) is used to gather common parts between events.
4652
The event params manipulate the default behavior by passing different values.
4753

54+
## Accessing and Modifying Generated Files
55+
4856
In the `after` function, we also have access to the generated files. An example of using this parameter is when you want to restructure the generated files in a different folder structure.
4957

5058
:::info
5159
In the `after` function for .NET plugins, we use a [`FileMap`](https://github.com/amplication/amplication/blob/master/libs/util/code-gen-types/src/files/file-map.ts). For Node.js plugins' `after` function we use a [`ModuleMap`](https://github.com/amplication/amplication/blob/master/libs/util/code-gen-types/src/code-gen-types.ts#L149).
5260
:::
5361

54-
## Cautionary Guidelines
62+
## Function Examples
63+
64+
Most of the functions include examples. But, if you're looking for more comprehensive and real-world examples, you can explore the [code of the Amplication plugins](https://github.com/amplication/plugins/tree/master/plugins)directly. These plugins showcase various implementations and use cases for the before and after lifecycle functions.
65+
66+
## Best Practices and Cautions
5567

5668
1. In the `after` function, avoid unintentionally overriding the entire generated file. Opt for smaller changes instead.
5769
2. In the `before` function, take care when modifying templates to not unintentionally affect code generation.

0 commit comments

Comments
 (0)