Use your AsyncAPI definition to generate literally anything. Markdown documentation, Node.js code, HTML documentation, anything!
npm install -g asyncapi-generator
Usage: ag [options] <asyncapi> <template>
Options:
-V, --version output the version number
-o, --output <outputDir> directory where to put the generated files (defaults to current directory)
-t, --templates <templatesDir> directory where templates are located (defaults to internal templates directory)
--params <templateParams> json object with additional params to pass to templates
-h, --help output usage information
The shortest possible syntax:
ag asyncapi.yaml markdown
Specify where to put the result:
ag -o ./docs asyncapi.yaml markdown
Passing parameters to templates:
ag -o ./docs --params '{ "title": "Hello from param" }' asyncapi.yaml markdown
In the template you can use it like this: {{ params.title }}
Generates a file of a given template, and returns the result as a string.
Name | Type | Required | Description |
---|---|---|---|
options | object |
Yes | An object containing all the options. |
options.templatesDir | string |
No | Directory where to find the templates. Defaults to internal templates directory. |
options.template | string |
Yes | Name of the template you want to use. |
options.file | string |
Yes | Path to the file you want to generate. |
options.config | object |
Yes | An object containing configuration options. |
options.config.asyncapi | string |object |
Yes | Path to the AsyncAPI file to use. |
const generator = require('asyncapi-generator');
generator.generateTemplateFile({
template: 'html',
file: 'index.html',
config: {
asyncapi: path.resolve(__dirname, 'asyncapi.yml'),
}
})
.then((result) => {
// `result` is a string containing the generated file.
console.log(result);
})
.catch(console.error);
Gets a file of a given template, and returns the its content as a string.
Name | Type | Required | Description |
---|---|---|---|
options | object |
Yes | An object containing all the options. |
options.templatesDir | string |
No | Directory where to find the templates. Defaults to internal templates directory. |
options.template | string |
Yes | Name of the template you want to use. |
options.file | string |
Yes | Path to the file you want to generate. |
const generator = require('asyncapi-generator');
generator.getTemplateFile({
template: 'html',
file: 'css/main.css',
})
.then((content) => {
console.log(result);
})
.catch(console.error);
- Node.js v7.6+
Contributions are more than welcome. If you want to make a contribution, please make sure you go through the following steps:
- Pick or create an issue. It's always a good idea to leave a message saying that you're going to work on it before you start any actual work.
- Fork the repository and work there.
- Open a Pull Request pointing to
master
branch. - A maintainer will review and, eventually, merge your Pull Request. Please, be patient as most of us are doing this in our spare time.
Fran Méndez (@fmvilas)