1.3.2 • Published 5 years ago

asyncapi-node-codegen v1.3.2

Weekly downloads
81
License
-
Repository
github
Last release
5 years ago

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)

1.3.2

5 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.9.0

7 years ago

0.8.0

7 years ago

0.7.1

7 years ago

0.7.0

7 years ago

0.6.4

7 years ago

0.6.3

7 years ago

0.6.2

7 years ago

0.6.1

7 years ago

0.6.0

7 years ago

0.5.0

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago