Typescript Code Generator - Zontroy
Typescript

Typescript Code Generator

How to generate typescript code with Zontroy

Typescript is getting more popular every day. If you are a typescript developer, you should think about using a Typescript Code generator. Because robotic tasks are nightmares for a developer while writing typescript code as in other scripting languages.

In this article, we are going to begin code generation for typescript. The diagram provided below includes a sample and easy database model just as start. You can apply the method provided in this article to your own database model and project.

Zontroy is very flexible to use with any type of software project and well-known databases. Also, you can generate typescript code according to your entity classes. Generating typescript is very simple and productive.

After designing our data model, we need a typescript template code file. Template code files are input for Zontroy to generate code. There are 3 types of template files.

Zontroy Repeating File (zref) : This template file generates one file for each entity in data model.

Zontroy Repeating File

Zontroy Single File (zsif) : This template file generates one single file for all entities in data model.

Zontroy Single File

Zontroy Inner Repeating File (ziref) : This template file generates a directory and a file for each entity in data model.

Zontroy Inner Repeating File

After this brief explanation about Zontroy template file types, we can create a Zontroy Project.

Download Zontroy Free using this link and after the installation, go to File -> New Project -> Create (Empty Zontroy Project).

After clicking Create button, you will see your entities on Entity Window.

On Project Window, there will be only Zontroy Project file.

Right click on typescript folder and click Add File.

On the New File form, select Zontroy Repeating File and give it a name like below.

This file name means that Zontroy will create code file for each entity and name it the same as entity name. Open the file created, and write the following template code to generate typescript code files.

//[[[zg-entity...zg-name]]].ts.zref
class [[[zg-entity...zg-name]]] {
    zg-for(((zg-item:::[[[zg-entity...zg-fields]]]))){{{
    [[[zg-item...zg-name]]]: [[[zg-item...zg-targetType]]];}}}
    
    constructor(zg-for(((zg-item:::[[[zg-entity...zg-fields]]]))){{{[[[zg-item...zg-name]]]: [[[zg-item...zg-targetType]]],}}} ) {
    zg-for(((zg-item:::[[[zg-entity...zg-fields]]]))){{{
        this.[[[zg-item...zg-name]]] = [[[zg-item...zg-targetType]]];}}}
    }
}

After that, click Generate button on the top to get the code files below.

Generated code files will be as following:

class country {
    
    country_id: number;
    country: string;
    last_update: Date;
    
    constructor(country_id: number,country: string,last_update: Date, ) {
    
        this.country_id = number;
        this.country = string;
        this.last_update = Date;
    }
}

This is just a beginning to Zontroy Generator. You can generate dozens of any kind of code files in a few minutes like this after preparing templates. You can create template files in order to meet your coding needs. Also you can go tothe official typescript website to find more examples and generate them with Zontroy.

Post a Comment