An AsyncAPI codegen for Node.js
Clone or download
fmvilas Merge tag '1.3.1' into develop
Fix documentation
Latest commit 5ea59e8 Apr 10, 2018
Permalink
Failed to load latest commit information.
lib
templates Update for using AsyncAPI version 1.0.0 Sep 20, 2017
tests Update outdated test file Mar 28, 2018
.editorconfig Initial version Apr 17, 2017
.eslintignore Initial version Apr 17, 2017
.eslintrc EsLint parsing error Mar 27, 2018
.gitignore Initial version Apr 17, 2017
.npmignore Update .npmignore Apr 17, 2017
.travis.yml
README.md Fix docs Apr 10, 2018
cli.js feat(templates): adds an argument to define a custom template directory Apr 9, 2018
logo.ai Improve README Dec 22, 2017
logo.png Improve README Dec 22, 2017
package-lock.json Bump version to 1.3.1 Apr 10, 2018
package.json Bump version to 1.3.1 Apr 10, 2018

README.md

AsyncAPI Node.js
Code Generator

Use your AsyncAPI definition to
generate the code for your API.



The generated code features:

  • Default Node.js template, featuring:
    • ES7
    • ESLint
    • YAML config file
    • Hermes
    • No transpiling
  • Custom templates. Check --templates option in the Usage section. Kudos to @jantoniucci.

Install

To use it from the CLI:

npm install -g asyncapi-node-codegen

To use it as a module in your project:

npm install --save asyncapi-node-codegen

Usage

From the command-line interface (CLI)

  Usage: anc [options] <asyncAPI>


  Options:

    -V, --version                  output the version number
    -o, --output <outputDir>       directory where to put the generated files (defaults to current directory)
    -t, --templates <templateDir>  directory where templates are located (defaults to internal nodejs templates)
    -h, --help                     output usage information

Examples

The shortest possible syntax:

anc asyncapi.yaml

Specify where to put the generated code:

anc asyncapi.yaml -o ./my-api

Specify where to find the code templates:

anc asyncapi.yaml -t ../my-specific-templates-dir -o ./my-api

As a module in your project

const path = require('path');
const codegen = require('asyncapi-node-codegen');
const asyncapi = '/path/to/asyncapi.yaml'; // Or a path to a JSON file

codegen.process(asyncapi, path.resolve(__dirname, './my-api')).then(() => {
  console.log('Done!');
}).catch(err => {
  console.error(`Something went wrong: ${err.message}`);
});

Using async/await

The function codegen.process returns a Promise, so it means you can use async/await:

const path = require('path');
const codegen = require('asyncapi-node-codegen');
const asyncapi = '/path/to/asyncapi.yaml'; // Or a path to a JSON file

try {
  await codegen.process(asyncapi, path.resolve(__dirname, './my-api'));
  console.log('Done!');
} catch (err) {
  console.error(`Something went wrong: ${err.message}`);
}

Author

Fran Méndez (@fmvilas)