Introduction

Yellicode lets you build your own code generation templates with TypeScript, for any programming language, in any IDE (integrated development environment) you like. In addition to the code generator itself, Yellicode provides a free, cross-platform modeling tool.

How Yellicode generates code

Yellicode is template based text generation framework. Basically, the code generator transforms a model - more about models below - to text using a template. The output of a template can be one or more text files. Yellicode is cross-platform and uses TypeScript (or, plain Javascript if you prefer) as a template language. Yellicode can be easily extended with code generators for specific programming languages or technologies.

Why TypeScript?

We choose TypeScript as the template language because it is one of the worlds most popular programming languages at this time. The reason for its popularity is that it is a strongly typed language which is easy to grasp. TypeScript is supported by every popular IDE.

About models

Code generation has little value without a model. A model contains the domain knowledge that is unique to your application. For Yellicode, a model can be any JSON file. You can define your own JSON structure and use that as the input for your template. For example, consider the following model:

{
    "pages": [
        {
            "name": "Home",
            "route": "/",
            "showInTopNav": true            
        },
        {
            "name": "Account",            
            "showInTopNav": true            
        }
    ]
}

As you might guess, this model outlines the structure of a website. Using this as input, we could make a template that generates a top level navigation menu:

import { TextWriter, NameUtility } from '@yellicode/core';
import { Generator } from '@yellicode/templating';  
import { WebsiteModel } from './website-model';

Generator.generateFromModel({ outputFile: './navigation.html' }, (writer: TextWriter, model: WebsiteModel) => {
    // Generate the top navigation HTML
    writer.writeLine('<ul class="top-nav">');
    writer.increaseIndent();
    // Generate a link element for each page that should be in the top navigation
    model.pages
        .filter(page => page.showInTopNav)
        .forEach(page => {
            const route = page.route || NameUtility.camelToKebabCase(page.name);
            writer.writeLine(`<li><a routerLink="${route}">${page.name}</a></li>`);
        })
    writer.decreaseIndent();
    writer.writeLine('</ul>');
});

This sample is just a very basic scenario, which demonstrates a simple code generation setup. However, you can easily extend your code generation templates with extra APIs and more sophisticated models.

In fact, a Yellicode template does not even require a model file: your code generator can use only arbitrary TypeScript/Javascript objects as well.

Extending Yellicode

Yellicode is based on Node.js. This means that you can easily integrate modules from NPM - the world’s largest software registry – into your code generation templates. But it also means that you can share your own code generation libraries with the community. This is a huge advantage compared to most code generators, which are often hard to customize and only provide little control.

At this moment, there are already some extensions for generating TypeScript, C#, HTML and Angular code. Check out the extensions page for more information.

Simple but powerful modeling

While using a custom JSON model might sometimes be sufficient for your model driven development needs, you can also create class models using our free modeling tool, Yellicode Modeler.

Yellicode Modeler is an easy to use modeling tool that can create UML class models. Yellicode models are stored as special JSON files with a .ymn extension, which are recognised by the code generation engine. When you use a Yellicode UML model for code generation, your templates can import our Model API (which you can, of course, install from NPM) to navigate all packages, classes and other elements of your model. And you can even extend UML models with custom data (also known as 'profiles') and tailor them to your own domain.

Get started  »