@kapeta/codegen
TypeScript icon, indicating that this package has built-in type declarations

1.6.1 • Public • Published

Kapeta Code generator module

Uses code generator targets to generate code for blocks in any language and framework

Currently only able to generate code for "Block YML" using BlockCodeGenerator, but could easily be extended to handle more types

The library pulls together the different parts involved in code generation:

  1. Loading code generation targets (languages)
  2. Actually generating the code
  3. Writing it to files

Basic usage

//Create a code generator for a block YML structure
//This will load the correct codegen-target based on the configuration in the YML
const codeGenerator = new BlockCodeGenerator(blockYML);

//Generate the code itself - output will contain file names, content and
//file permissions
const output = await codeGenerator.generate();

//Code writer takes the generated output and writes it to disk
//Base dir is the is prepended to all paths
const writer = new CodeWriter(baseDir);

//Will perform the actual writes to disk
writer.write(output);

Language Targets

Language targets is what defines how a particular data structure should be expressed in a given language / framework / context

This library uses a "Target Registry" to contain information about what language targets are available.

The default target registry is available as "registry" in the export from this library. If you register targets to this registry it will automatically be picked up by the rest of the code generation framework

const { registry } = require('@kapeta/codegen');

To register a language target we do this:

registry.register('target-identifier', TargetClass);

TargetClass is expected to extend Target which is found in the @kapeta/codegen-target module: https://github.com/kapetacom/codegen-target/blob/master/src/Target.js

License

This project is licensed under the MIT License - see the LICENSE file for details

Readme

Keywords

Package Sidebar

Install

npm i @kapeta/codegen

Weekly Downloads

357

Version

1.6.1

License

MIT

Unpacked Size

133 kB

Total Files

57

Last publish

Collaborators

  • wejendorp
  • sorenmat
  • vonhofmeister