Skip to content

Commit

Permalink
docs: reorg documents
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni committed Jun 19, 2024
1 parent c92eac3 commit 433da9f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 40 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ ln -s <absolute-path>/bin/codegen /usr/local/bin/codegen
</tr>
</table>

You can find all the possible commands in [the usage documentation](./docs/usage.md).

## Initialize
Add The Codegen Project configuration file, either manually or through the CLI;
```sh
Expand All @@ -154,7 +156,7 @@ codegen init

<video src='https://github.com/the-codegen-project/cli/assets/13396189/6a351e0d-b5b2-4ca3-845a-556aeba490c9' width=1920></video>

Check out all the new generators here: https://github.com/the-codegen-project/cli/tree/main/docs/generators
Check out all the possible generators here: https://github.com/the-codegen-project/cli/tree/main/docs/generators

## Generate
With your configuration file in hand, time to generate the code and use it!
Expand Down
36 changes: 0 additions & 36 deletions docs/dependencies.md

This file was deleted.

42 changes: 39 additions & 3 deletions docs/generators/custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

This generator is simple, it's a callback that enable you to write any file or do any operation in the code generation process. This preset is available for all languages.

## Dependencies
## Imports

The dependencies you have access to is any native `node` dependency and all dependencies listed in [the codegen project](https://github.com/the-codegen-project/cli/blob/8b8fa6f0c5b0c0c63515a8ca439f72872815f491/package.json#L9). Here is an example:
The dependencies you have access to is any native `node` dependency and all dependencies listed in [The Codegen Project](https://github.com/the-codegen-project/cli/blob/8b8fa6f0c5b0c0c63515a8ca439f72872815f491/package.json#L9). Here is an example:

```ts
import { JavaFileGenerator } from "@asyncapi/modelina";
Expand All @@ -23,10 +23,46 @@ export default {
};
```

# Dependencies

In each generator (don't manually use it unless you use [`preset: custom`](./custom.md)), you can add `dependencies` property, which takes an array of `id`'s that the rendering engine ensures are rendered before the dependant one.

Each generator has a specific output (except [`custom`](./custom.md) which is dynamic and under your control), they are documented under each [./generators](./). These outputs can be accessed under `dependencyOutputs`.

There are two rules though;

1. You are not allowed to have circular dependencies, i.e. two generators both depending on each other.
2. You are not allowed to have self-dependant generators

## How does it work?

For example, take two generators, you can chain them together and use one's output in the other, as for example below, to have the console print out `Hello World!`.
```js
export default {
...
generators: [
{
preset: 'custom',
renderFunction: ({dependencyOutputs}) => {
console.log(dependencyOutputs['bar'])
},
dependencies: ['bar']
},
{
preset: 'custom',
id: 'bar',
renderFunction: () => {
return 'Hello World!'
}
}
]
};
```

## Arguments
In the `renderFunction` you have access to a bunch of arguments to help you create the callback;

- `generator` - is the generator configuration, where you have access to the `options` and all other information.
- `inputType` - is the root `inputType` for the input document
- `asyncapiDocument` - is the parsed AsyncAPI document input (according to the [AsyncAPI parser](https://github.com/asyncapi/parser-js/)), undefined if the `inputType` is not `asyncapi`
- `dependencyOutputs` - if you have defined any `dependencies`, this is where you can access the output. Checkout the [dependency documentation](../dependencies.md) for more information.
- `dependencyOutputs` - if you have defined any `dependencies`, this is where you can access the output. Checkout the [dependency documentation](#dependencies) for more information.

0 comments on commit 433da9f

Please sign in to comment.