0.0.11 • Published 8 years ago

generator-app-gen v0.0.11

Weekly downloads
6
License
ISC
Repository
github
Last release
8 years ago

app-gen

Join the chat at https://gitter.im/tarcisiojr/generator-app-gen Build Status Coverage Status npm version Codacy Badge Code Climate NPM

Customizable code generator based on Yeoman Generator.

Usage

First install de Yeoman:

npm install -g yo

Install generator-app-gen:

npm install -g generator-app-gen

Go into your project directory:

cd my-project

Create a file app-gen.[json|js] (see above for more details):

vi app-gen.json

Run yo app-gen to start code generation.

Configuration (app-gen.json|js)

The app-gen.[json|js] file contains information about code generation for your project. In this file going to describe the configurations for artifacts code generation. This file can be a json or a JavaScript module.

The artifact code generation is performed by 3 configurations: from, in and to.

The configuration from is the template source. The configuration in is the input source. The configuration to is the destination.

Below are the available drivers for each configuration.

From

In

To

Configuration Structure

In this example, the artifact "Sample1" is getting a template from a file, reading the inputs from JSON and will write resultant text on console and in a file.

{
    "name": "Project Name",
    "helper" : {
    	"filter": "/helpers/filter.js"
  	},
    "artifacts": {
        "Sample1": {
            "from": {
                "driver": "FILE",
                "template": ["./templates/sample-from.js"]
            },
            "in": {
                "driver": "JSON",
                "config": {
                    "message": "Hello World!"
                }
            },
            "to": [{
                "driver": "CONSOLE"
            }, {
                "driver": "FILE",
                "out" : "./out/sample-out.js"
            }]
        },
        "Sample2": { ... },
        ...
        "SampleN": { ... }
    }
}

From

In

...
"in": { # required
    "driver": "JSON",
    "config": {
        "message": "Hello World!"
    }
}
...
...
"in": { # required
    "driver": "JSONFILE",
    "config": ["file name.json"]
}
...
...
"in": {
    "driver": "PROMPT",
    "config": [{
        "message": "Supply the message",
        "name" : "message"
    }]
}
...
...
"in": {
    "driver": "MYSQL",
    "config": {
        "host": "localhost",
        "port" : "3306",
        "user" : "root",
        "password": "root",
        "query": "SELECT NULL"
    }
}
...
...
"in": {
    "driver": "POSTGRESQL",
    "config": {
        "host": "localhost",
        "port" : 5432,
        "database": "postgres"
        "user" : "user",
        "password": "password",
        "query": "SELECT NULL"
    }
}
...
...
"in": { 
    "driver": "JS",
    "config": "javascrip_file_name.js"
}
...

JavaScript Sample:

module.exports = function(
    generator,  // Instance of Yo Generator
    inValues,   // Previous IN values
    callback    // Callback function
    ) {
    
    // Your code goes here
    var newValues = {
        newValue: "newValue"
    };

    console.log('>>', Object.assign({}, inValues, newValues));
    
    callback(null, Object.assign({}, inValues, newValues));
}

To

// Optional - Replace ocurrences in file.
"replace" : {
    "regex": "JS RegExp",
    "flags": "JS RegExp flags."
}

}

<a name="plugin-console" />
### CONSOLE
Writes the rendered template at console output.
```js
{
    "driver": "CONSOLE"
}

Examples

Prints a string at console from a JSON template where the input is supplied by user.

app-gen.json

{
    "name": "Examples",
    "artifacts": {
        "Example1": {
            "from": {
                "driver": "JSON",
                "template": ["Hello <%=message%>"]
            },

            "in": {
                "driver": "PROMPT",
                "config": [{
                    "message": "Supply the message:",
                    "name": "message"
                }]
            },

            "to": {
                "driver": "CONSOLE"
            }
        }
    }
}

Run app-gen and select the artifact "Example1". Will be prompted a message. If you supply "world", the output will be like this:

? Choose the artifact Example1
? Supply the message: world

------------- OUT -------------
Hello world
------------- END -------------
0.0.11

8 years ago

0.0.10

8 years ago

0.0.9

9 years ago

0.0.8

9 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago