JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 275
  • Score
    100M100P100Q97328F
  • License MPL-2.0

Templating package for Yellicode - an extensible code generator.

Package Exports

  • @yellicode/templating

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@yellicode/templating) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Yellicode Templating

Templating package for Yellicode

Yellicode lets you build your own code generation templates with TypeScript. It consists of a Node.js CLI and extensible APIs, making it easy for developers to create, share and re-use code generators for their favorite programming languages and frameworks.

Check out our website for more.

License: MPL-2.0

Using the Templating package

This package contains the basic templating infrastructure, as well as utilities and base classes for creating custom code writers and model transforms for Yellicode.

In order to run a code generation template, you must have the CLI installed (@yellicode/cli) and have a valid codegenconfig.json file. Please refer to the installation instructions and the quick start for more.

Very basic usage - without code model

import { Generator, TextWriter } from '@yellicode/templating';

Generator.generate({outputFile: './my-file.txt'}, (writer: TextWriter) => {
    writer.writeLine('File generated at '+new Date().toISOString());
}); 

Basic usage - with code model

When generating code from a code model, you should at least install the Model package (@yellicode/model). The template structure should be as follows:

import { Generator, TextWriter } from '@yellicode/templating';
import * as model from '@yellicode/model';

Generator.generateFromModel({outputFile: './my-file.txt'}, (writer: TextWriter, model: model.Package) => {
    // Enumerate classes
    model.getAllClasses().forEach((c) => {
        // Write a class definition here...
        // Enumerate attributes
        c.ownedAttributes.forEach(att => {
            // Write the attribute definition here...
        });                
    })
});     

Generating multiple files with a single template

import { Generator, TextWriter } from '@yellicode/templating';
import * as model from '@yellicode/model';

Generator.getModel().then((model: model.Model) => {
    // Generate a file for each class in the model  
    model.getAllClasses().forEach((c) => {
        Generator.generate({ outputFile: `${c.name}.txt` }, (writer: TextWriter) => {
            writer.writeLine(`/* This file contains the code for class '${c.name}'. */`);
        });
    });
})

API documentation

The detailed Templating API documentation can be found here.