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

template-gen

v2.1.0

Published

A flexible template generator for any project

Downloads

1

Readme

❯ Why

It's tedious to always copy & past the same file or file content over and over again. In addition the content has be clean up over and over because mostly we need a clean version of the content. This module can be used as a cli or integrated into any node based project.

❯ Table of Contents

❯ Installation

As global CLI

You can install this module globally by

npm install -g template-gen

Have a look at RC configuration how you can setup a template path.

As project dependency

Add this module to your project dependencies

npm install template-gen --save-dev

then add the following entry to your npm scripts

{
    "tg": "tg -d ./templates"
}

❯ Getting Started

Setup a template file

First you need to create a template folder. We recommend to use templates as name as this module will look for this folder automatically.

mkdir templates

Alternatively you can pass the template path with parameter as shown in the installation instructions.

Next we need a template file. Create a file (e.g. controller.js) within the templates folder with the following content

module.exports = {
    name: 'Controller',
    description: 'Creating a controller',
    target: 'controllers',
    wrapFolder: params => `${params.controller.toLowerCase()}`,
    parameters: [
        {
            type: 'text',
            name: 'controller',
            message: 'Whats the controller name?'
        },
        {
            type: 'confirm',
            name: 'haveConstructor',
            message: 'With a constructor?'
        }
    ],
    files: [
        {
            template: params => {
                return `export default class ${params.controller} {
    someAttribute = '';` +
                    (params.haveConstructor ? `

    constructor () {

    }` : '') +
                    `
}
`;
            },
            fileName: params => `${params.controller}Controller.ts`
        },
        {
            template: () => '<template></template>',
            fileName: params => `${params.controller}Controller.html`
        }
    ]
}

Don't forget to create the controllers folder

| Attribute | Description | | -------------- | ----------- | | name | The name to enter or select in the CLI | | description | Will be shown after you selected the name in the CLI | | target | The target directory from the root where the file will be created in | | wrapFolder | Should be undefined or a function which returns the parent folder name | | parameters | The CLI prompts to ask the user, you can use this prompts options | | files.template | The content of the generated file | | files.fileName | The file name of the generated file |

The parameters attribute can be a object or an array of prompts options.

Usage

With the above example setup you can now run

npm run tg

Then you will be asked for the template parameters and finally create the file.

Use Parameters

If you have template like the above with name Controller and prompt controller then you could use this to execute without prompts

npm run tg -- Controller --controller User --haveConstructor true

Or just if you just like to create a controller with prompts

npm run tg Controller

❯ RC configuration

In you project root you can create a file named .tgrc to configure you template path

{
    "path": "./templates"
}

❯ Related Projects

❯ License

MIT