node package manager
Easy collaboration. Discover, share, and reuse code in your team. Create a free org »

mustgen

What is Mustgen?

Mustgen is a very simple file generator based on handlebars. It takes {{mustached}} template and javascript object as a map with values and file definitions, then generates string using handlebars, and writes it to a file.

Why it exists?

It was created as an alternative code generator for Entitas.

Quick start

0. Have Node.js installed

If you don't have node.js installed on your machine, install from Node.js website.

1. Go to your project path

$ cd pathToYourProject

1. Install Mustgen

$ npm install mustgen --save

2. Add template hello.hbs at root of your project

Hello {{name}}.
 
Random words: {{#words}}{{.}} {{/words}}
 
{{#person}}
And this is block of {{name}} {{lastname}}.
{{/person}}

3. Add map.js at root of your project

var helloFile = {
    template: 'hello.hbs',
    output: 'hello.txt',
    data: {
        name: "totally useful tool",
        words: ["Lonely", "Sad", "Depressed"],
        person: {
            name: "Stephen",
            lastname: "King"
        }
    }
}
 
module.exports = {
    files: [helloFile],
    helpers: {},
    partials: {},
    // For safety reasons, output folder name  
    // should contain '_generated'.  
    // This folder will be constantly cleaned. 
    output: '_generated'
};

4. Add server.js at root of your project

require('mustgen')('./', './map');

5. Run server

$ node server

6. Enjoy

Hello totally useful tool.
 
Random words: Lonely Sad Depressed
 
And this is block of Stephen King.

Code generation example

Check out EntitasMustgen, it's a boilerplate for Entitas API generation.

Handlebars docs

Handlebars website | Handlebars GitHub

Maintainer