npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

generator-app-gen

v0.0.11

Published

Code generator based on Yeoman Generators.

Downloads

8

Readme

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 -------------