Kind: global class
- Generator
- new Generator(templateName, targetDir, options)
- instance
- .templateName :
String
- .targetDir :
String
- .entrypoint :
String
- .noOverwriteGlobs :
Array.<String>
- .disabledHooks :
Object.<String, (Boolean|String|Array.<String>)>
- .output :
String
- .forceWrite :
Boolean
- .debug :
Boolean
- .install :
Boolean
- .templateConfig :
Object
- .hooks :
Object
- .mapBaseUrlToFolder :
Object
- .templateParams :
Object
- .originalAsyncAPI :
String
- .generate(asyncapiDocument) ⇒
Promise
- .configureTemplate()
- .generateFromString(asyncapiString, [parserOptions]) ⇒
Promise
- .generateFromURL(asyncapiURL) ⇒
Promise
- .generateFromFile(asyncapiFile) ⇒
Promise
- .installTemplate([force])
- .templateName :
- static
Instantiates a new Generator object.
Param | Type | Default | Description |
---|---|---|---|
templateName | String |
Name of the template to generate. | |
targetDir | String |
Path to the directory where the files will be generated. | |
options | Object |
||
[options.templateParams] | String |
Optional parameters to pass to the template. Each template define their own params. | |
[options.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. | |
[options.noOverwriteGlobs] | Array.<String> |
List of globs to skip when regenerating the template. | |
[options.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. | |
[options.output] | String |
'fs' |
Type of output. Can be either 'fs' (default) or 'string'. Only available when entrypoint is set. |
[options.forceWrite] | Boolean |
false |
Force writing of the generated files to given directory even if it is a git repo with unstaged files or not empty dir. Default is set to false. |
[options.install] | Boolean |
false |
Install the template and its dependencies, even when the template has already been installed. |
[options.debug] | Boolean |
false |
Enable more specific errors in the console. At the moment it only shows specific errors about filters. Keep in mind that as a result errors about template are less descriptive. |
[options.mapBaseUrlToFolder] | Object.<String, String> |
Optional parameter to map schema references from a base url to a local base folder e.g. url=https://schema.example.com/crm/ folder=./test/docs/ . |
Example
const path = require('path');
const generator = new Generator('@asyncapi/html-template', path.resolve(__dirname, 'example'));
Example (Passing custom params to the template)
const path = require('path');
const generator = new Generator('@asyncapi/html-template', path.resolve(__dirname, 'example'), {
templateParams: {
sidebarOrganization: 'byTags'
}
});
Name of the template to generate.
Kind: instance property of Generator
Path to the directory where the files will be generated.
Kind: instance property of Generator
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.
Kind: instance property of Generator
List of globs to skip when regenerating the template.
Kind: instance property of Generator
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.
Kind: instance property of Generator
Type of output. Can be either 'fs' (default) or 'string'. Only available when entrypoint is set.
Kind: instance property of Generator
Force writing of the generated files to given directory even if it is a git repo with unstaged files or not empty dir. Default is set to false.
Kind: instance property of Generator
Enable more specific errors in the console. At the moment it only shows specific errors about filters. Keep in mind that as a result errors about template are less descriptive.
Kind: instance property of Generator
Install the template and its dependencies, even when the template has already been installed.
Kind: instance property of Generator
The template configuration.
Kind: instance property of Generator
Hooks object with hooks functions grouped by the hook type.
Kind: instance property of Generator
Maps schema URL to folder.
Kind: instance property of Generator
The template parameters. The structure for this object is based on each individual template.
Kind: instance property of Generator
AsyncAPI string to use as a source.
Kind: instance property of Generator
Generates files from a given template and an AsyncAPIDocument object.
Kind: instance method of Generator
Param | Type | Description |
---|---|---|
asyncapiDocument | AsyncAPIDocument |
AsyncAPIDocument object to use as source. |
Example
generator
.generate(myAsyncAPIdocument)
.then(() => {
console.log('Done!');
})
.catch(console.error);
Example (Using async/await)
try {
await generator.generate(myAsyncAPIdocument);
console.log('Done!');
} catch (e) {
console.error(e);
}
Configure the templates based the desired renderer.
Kind: instance method of Generator
Generates files from a given template and AsyncAPI string.
Kind: instance method of Generator
Param | Type | Default | Description |
---|---|---|---|
asyncapiString | String |
AsyncAPI string to use as source. | |
[parserOptions] | Object |
{} |
AsyncAPI parser options. Check out @asyncapi/parser for more information. |
Example
const asyncapiString = `
asyncapi: '2.0.0'
info:
title: Example
version: 1.0.0
...
`;
generator
.generateFromString(asyncapiString)
.then(() => {
console.log('Done!');
})
.catch(console.error);
Example (Using async/await)
const asyncapiString = `
asyncapi: '2.0.0'
info:
title: Example
version: 1.0.0
...
`;
try {
await generator.generateFromString(asyncapiString);
console.log('Done!');
} catch (e) {
console.error(e);
}
Generates files from a given template and AsyncAPI file stored on external server.
Kind: instance method of Generator
Param | Type | Description |
---|---|---|
asyncapiURL | String |
Link to AsyncAPI file |
Example
generator
.generateFromURL('https://example.com/asyncapi.yaml')
.then(() => {
console.log('Done!');
})
.catch(console.error);
Example (Using async/await)
try {
await generator.generateFromURL('https://example.com/asyncapi.yaml');
console.log('Done!');
} catch (e) {
console.error(e);
}
Generates files from a given template and AsyncAPI file.
Kind: instance method of Generator
Param | Type | Description |
---|---|---|
asyncapiFile | String |
AsyncAPI file to use as source. |
Example
generator
.generateFromFile('asyncapi.yaml')
.then(() => {
console.log('Done!');
})
.catch(console.error);
Example (Using async/await)
try {
await generator.generateFromFile('asyncapi.yaml');
console.log('Done!');
} catch (e) {
console.error(e);
}
Downloads and installs a template and its dependencies
Kind: instance method of Generator
Param | Type | Default | Description |
---|---|---|---|
[force] | Boolean |
false |
Whether to force installation (and skip cache) or not. |
Returns the content of a given template file.
Kind: static method of Generator
Param | Type | Default | Description |
---|---|---|---|
templateName | String |
Name of the template to generate. | |
filePath | String |
Path to the file to render. Relative to the template directory. | |
[templatesDir] | String |
DEFAULT_TEMPLATES_DIR |
Path to the directory where the templates are installed. |
Example
const Generator = require('asyncapi-generator');
const content = await Generator.getTemplateFile('@asyncapi/html-template', 'partials/content.html');
Example (Using a custom `templatesDir`)
const Generator = require('asyncapi-generator');
const content = await Generator.getTemplateFile('@asyncapi/html-template', 'partials/content.html', '~/my-templates');