Introducing Yellicode

Today I'm very excited to introduce Yellicode, a next-generation code generation engine. Yellicode lets you build your own code generation templates with TypeScript, for any programming language, in any IDE you like. In addition to the code generator itself, Yellicode provides a free, cross-platform modeling tool.

Code generation has existed for many years now. It is used in many ways, such as generating databases and data access code but also for building user interfaces. Code generation is a great way to speed up application development and prototyping. It can be a great time saver and result in better maintained software.

I created Yellicode because I didn't like the speed and flexibility of existing code generation solutions. If you are new to code generation, I hope you will try it out. If you have given up on it in the past because you felt it took too much of your freedom away, Yellicode might be for you as well.

So what is it all about?

Yellicode is all about model driven development. In a nutshell: you create a model of your code, which is saved in a (source control friendly) JSON format. Then you use plain TypeScript templates to transform your model into code, using our strongly-typed APIs to navigate and transform the model. As you update your model, your source code will be updated almost instantly.

Yellicode is created with extensibility in mind: our APIs let you create your own extensions for your favorite programming languages and technologies. Because Yellicode is based on Node.js, all your templates and extensions can be easily shared on NPM, the world's most popular software registry.

What does a Yellicode template look like?

I knew you would ask. Here is a sample template that generates a C# file from a model using a the @yellicode/csharp extension (the structure would be similar for most other target languages).

import { Generator, TextWriter } from '@yellicode/templating';  
import { CSharpWriter } from '@yellicode/csharp 
import * as elements from '@yellicode/elements'; 

Generator.generateFromModel({outputFile: './MyClasses.cs'}, (textWriter: TextWriter, model: elements.Model) => {
    const writer = new CSharpWriter(textWriter); // use a C# extension
    writer.writeUsingDirectives('System', 'System.Collections.Generic'); 
    writer.writeNamespaceBlock(pack, () => {  // write a namespace for the package    
        model.getAllClasses().forEach(c => {  // iterate over all classes in the package         
            writer.writeClassBlock(c, () => { // write a class declaration with XML summary
                c.ownedAttributes.forEach(att => { // iterate over all (non-inherited) attributes
                    writer.writeAutoProperty(att); // write a getter/setter
                })
            })            
        });
    });
});        

This is just a basic, but powerful example. You can extend your model using custom meta data and use this meta data directly in your templates, without abandoning type-safety. You can also generate multiple files from a single template, apply custom transformations to your model and pass custom arguments to your templates, just to name a few features.

Why did you create Yellicode?

In the past, I have mainly used the T4 templating engine built into Visual Studio (I mostly do .NET web development). My typical workflow has always been like the following: create a class model using a UML editor, export this to model to a XMI file (a XML representation of UML), parse this XMI document into a .NET object model and transform this model to code with T4 templates. While this can be very powerful, I felt that the code generation workflow could be better. Also, T4 uses a custom templating syntax (which you may like or not) and is not available in any IDE other than Visual Studio.

I also find myself using other IDEs such as Visual Studio Code and JetBrains Rider more and more, which asks for a code generation solution that is IDE independent. Also, I believe that generated code must meet the same standards as handwritten code. This means that code generation templates must be easy to maintain and adjust to company standards and technology changes.

Quick start

If you prefer a step-by-step guide, follow these instructions. Otherwise, the following will get you started in less than a minute:

First, make sure that you have Node.js installed on your machine (you can download Node.js here). Then open a command prompt and enter:

npm install @yellicode/cli -g

Then, create a new directory, open a command prompt and enter:

yellicode init

This command will ask a bunch of questions and then create 3 files (a basic template, an initial model and a codegenconfig.json file). It will also install 2 Yellicode NPM packages. As the last step, run the yellicode --watch command to generate a simple text file:

yellicode --watch

Now you can adjust the basic template to your needs (check out the extensions section for useful language specific extensions). Note: in order to edit the generated model (a file with .ymn extension), you will need to install Yellicode Modeler.

Try it out!

Yellicode is in an early version, but don't let this scare you off. You might still hit some bugs, but I do eat my own dog food: I use Yellicode to develop many parts of Yellicode (don’t you just love how meta this is?). I spent many hours writing the documentation, but there are still some gaps that will be filled soon.

Also, Yellicode Modeler does not support diagramming - yet. The focus of the first version was to allow developers to edit every detail of their model. While diagrams are great for showing overviews and relationships, they often fall short when it comes to showing the details like - for example - the tagged values of attributes and operations.

If you are into .NET- or Angular development, have a look at this tutorial, where you will learn how to generate a full-stack web application.

I'm looking forward to seeing what you create. If you create cool things that you want to share, just post a message in our forum. If you need help, check out the help page for the right directions.

Comments powered by Talkyard.