@asyncapi/generator 1.10.9 → 1.10.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/api.md +1 -1
- package/docs/template-development.md +17 -11
- package/lib/generator.js +1 -1
- package/package.json +1 -1
package/docs/api.md
CHANGED
|
@@ -47,7 +47,7 @@ Instantiates a new Generator object.
|
|
|
47
47
|
- templateName `String` - Name of the template to generate.
|
|
48
48
|
- targetDir `String` - Path to the directory where the files will be generated.
|
|
49
49
|
- options `Object`
|
|
50
|
-
- [.templateParams] `
|
|
50
|
+
- [.templateParams] `Object.<string, string>` - Optional parameters to pass to the template. Each template define their own params.
|
|
51
51
|
- [.entrypoint] `String` - Name of the file to use as the entry point for the rendering process. Use in case you want to use only a specific template file. Note: this potentially avoids rendering every file in the template.
|
|
52
52
|
- [.noOverwriteGlobs] `Array.<String>` - List of globs to skip when regenerating the template.
|
|
53
53
|
- [.disabledHooks] `Object.<String, (Boolean|String|Array.<String>)>` - Object with hooks to disable. The key is a hook type. If key has "true" value, then the generator skips all hooks from the given type. If the value associated with a key is a string with the name of a single hook, then the generator skips only this single hook name. If the value associated with a key is an array of strings, then the generator skips only hooks from the array.
|
|
@@ -11,20 +11,24 @@ Let's break down the minimum template requirements: the `template` directory and
|
|
|
11
11
|
|
|
12
12
|
### `template` directory
|
|
13
13
|
|
|
14
|
-
The `template` directory
|
|
14
|
+
The `template` directory holds all the files that will be used for generating the output. The generator will process all the files stored in this directory.
|
|
15
15
|
|
|
16
|
+
The following code is an example of an `index.js` file inside the `template` folder.
|
|
16
17
|
```js
|
|
17
18
|
import { File, Text } from "@asyncapi/generator-react-sdk";
|
|
18
19
|
|
|
19
|
-
export default function({ asyncapi, params, originalAsyncAPI }) {
|
|
20
|
-
return (
|
|
20
|
+
export default function ({ asyncapi, params, originalAsyncAPI }) {
|
|
21
|
+
return (
|
|
21
22
|
<File name="asyncapi.md">
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
<Text>My application's markdown file.</Text>
|
|
24
|
+
<Text>App name: **{asyncapi.info().title()}**</Text>
|
|
24
25
|
</File>
|
|
25
|
-
);
|
|
26
|
+
);
|
|
26
27
|
}
|
|
27
28
|
```
|
|
29
|
+
|
|
30
|
+
The above example will produce an `asyncapi.md` file where usage of the AsyncAPI document information (i.e. the `title`) is demonstrated.
|
|
31
|
+
|
|
28
32
|
### `package.json` file
|
|
29
33
|
|
|
30
34
|
Before the generation process begins, the generator installs the template into its dependencies. A `package.json` file is necessary to identify the template name.
|
|
@@ -43,8 +47,6 @@ The following block shows an example `package.json` file that points to the [Rea
|
|
|
43
47
|
}
|
|
44
48
|
```
|
|
45
49
|
|
|
46
|
-
The above example of a `template/index.js` file shows the generation process result. The user also receives an `asyncapi.md` file with hardcoded and dynamic (application title from the AsyncAPI document) information.
|
|
47
|
-
|
|
48
50
|
Every template must depend on the [`@asyncapi/generator-react-sdk` package](https://github.com/asyncapi/generator-react-sdk), which contains a template file's basic components.
|
|
49
51
|
|
|
50
52
|
## Additional configuration options
|
|
@@ -73,14 +75,16 @@ The following examples show some advanced configurations that we can use in our
|
|
|
73
75
|
"name": "myTemplate",
|
|
74
76
|
"generator": {
|
|
75
77
|
"renderer": "react",
|
|
76
|
-
"supportedProtocols":
|
|
78
|
+
"supportedProtocols": [
|
|
79
|
+
"mqtt"
|
|
80
|
+
]
|
|
77
81
|
},
|
|
78
82
|
"dependencies": {
|
|
79
83
|
"@asyncapi/generator-react-sdk": "^0.2.25"
|
|
80
84
|
}
|
|
81
85
|
}
|
|
82
86
|
```
|
|
83
|
-
The above `package.json` file has a newly added configuration called `supportedProtocols` which is set to `mqtt`. This configuration displays all the protocols that this template supports. You can have multiple supported protocols in our template.
|
|
87
|
+
The above `package.json` file has a newly added configuration called `supportedProtocols` which is set to a list containing only `mqtt`. This configuration displays all the protocols that this template supports. You can have multiple supported protocols in our template.
|
|
84
88
|
|
|
85
89
|
For example, if you want to generate an output using the above template, you need to have an AsyncAPI document with servers that use `mqtt` to generate your desired output. If your AsyncAPI document has server connections with `kafka`, the generation process will be terminated since the only supported protocol mentioned is `mqtt`.
|
|
86
90
|
|
|
@@ -93,7 +97,9 @@ Additionally, we can also have a configuration called `parameters`, which is an
|
|
|
93
97
|
"name": "myTemplate",
|
|
94
98
|
"generator": {
|
|
95
99
|
"renderer": "react",
|
|
96
|
-
"supportedProtocols":
|
|
100
|
+
"supportedProtocols": [
|
|
101
|
+
"mqtt"
|
|
102
|
+
],
|
|
97
103
|
"parameters": {
|
|
98
104
|
"version": {
|
|
99
105
|
"description": "Overrides application version under `info.version` in the AsyncAPI document.",
|
package/lib/generator.js
CHANGED
|
@@ -77,7 +77,7 @@ class Generator {
|
|
|
77
77
|
* @param {String} templateName Name of the template to generate.
|
|
78
78
|
* @param {String} targetDir Path to the directory where the files will be generated.
|
|
79
79
|
* @param {Object} options
|
|
80
|
-
* @param {
|
|
80
|
+
* @param {Object<string, string>} [options.templateParams] Optional parameters to pass to the template. Each template define their own params.
|
|
81
81
|
* @param {String} [options.entrypoint] Name of the file to use as the entry point for the rendering process. Use in case you want to use only a specific template file. Note: this potentially avoids rendering every file in the template.
|
|
82
82
|
* @param {String[]} [options.noOverwriteGlobs] List of globs to skip when regenerating the template.
|
|
83
83
|
* @param {Object<String, Boolean | String | String[]>} [options.disabledHooks] Object with hooks to disable. The key is a hook type. If key has "true" value, then the generator skips all hooks from the given type. If the value associated with a key is a string with the name of a single hook, then the generator skips only this single hook name. If the value associated with a key is an array of strings, then the generator skips only hooks from the array.
|