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
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.
import { Generator, TextWriter } from '@yellicode/templating';
Generator.generate({outputFile: './my-file.txt'}, (writer: TextWriter) => {
writer.writeLine('File generated at '+new Date().toISOString());
});
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...
});
})
});
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}'. */`);
});
});
})
The detailed Templating API documentation can be found here.