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 🙏

© 2025 – Pkg Stats / Ryan Hefner

code-generator-by-template

v1.0.7

Published

Automate your coding process through auto generated code by providing a template.

Downloads

360

Readme

code-generator-by-template

Automate your coding process through auto generated code by command lines.

Description

There are two different usages for this library. It's possible to generate a single file or a whole structure based off the templates.

Usage

Base command (generate single file)

generate-file [pathToTemplateFile] [variables]

<pathToFileToCreate> (required)

Ex.: tasks/taskKinds/taskKinds.routes.ts Path for the file to be created. If one wants to create a new file on the project nested in a parent folder, this can be specified by adding the parent folder's name before the file name. For example, if one wants to create a CRUD for task kinds in a kanban project and they want to place it inside the tasks folder, they could use generate tasks/taskKinds/taskKinds.routes.ts. That would create the folders as:

- tasks
  - taskKinds
    taskKinds.routes.ts
[pathToTemplateFile] (optional)

Ex.: templates/template.test.ts If provided, should point to the path of the template to be used on the file creation. If not provided, by default, it looks for a folder named "templates" on the root folder and a file with the same name inputted file name.

[variables] (optional)

Ex.: camelCase=Test plural=tests Variables to be used on the template file. It should have the same key as specified on the template file for it to work.

Base command (generate multiple files)

generate-structure [--parentFolders] [--templateFolderPath] [--pathToDesignPatternFile] [variables]

[--parentFolders] (optional)

Ex.: tasks/taskKinds If one wants to create some parent folders before the folder names with placeholder, this can be specified by adding the parent folder's name before the file name. For example, if one wants to create a CRUD for task kinds in a kanban project and they want to place it inside the tasks folder, they could use generate tasks/taskKinds/taskKinds.routes.ts. That would create the folders as:

- tasks
  - taskKinds
[--templateFolderPath] (optional)

Ex.: templates/template.test.ts If provided, should point to the path of the template folder to be used on the file creation. If not provided, by default, it looks for a folder named "templates" on the root folder.

[--pathToDesignPatternFile] (optional)

Ex.: templates/code-generator-design-pattern.json If provided, should point to the path of the design pattern file. If not provided, by default, it looks for a folder named "templates" on the root folder and then a file named code-generator-design-pattern.json.

[variables] (optional)

Ex.: camelCase=Test plural=tests Variables to be used on the template file. It should have the same key as specified on the template file for it to work.

Template files

The template files should be text (.txt) files, with the parameters placeholders under square brackets ([]).

Process explanation

generate-file

The script will receive a path (ex.: tests/new-test.ts) and check if the folders on this path exist. If they don't, they will be created. If they exist, it will proceed to create the file, following a template. The template path can be specified on the command or use the default behaviour (which is to use the template file in a folder named "templates"). The template may have placeholders, which then may be provided in the template and the command line args.

generate-structure

The script may receive some parent folders to create before the folders with placeholders on their names on the design pattern file, the path to the template folder, the path to the design pattern file and/or the variables to replace on the placeholders. The script will check the design pattern file to create the necessary folders and files that are specified there. Then, for the files, it shall look for the template files with the same name that is specified on the design pattern file. For the placeholder in the files contents and in the design patterns, it looks for the placeholders parameters that come from the program args, inputted by the user.

Development

Requirements

  • NodeJS 20+

Steps to run

  • Install
  • Compile
  • Run

Installing

  • yarn install

Compiling

  • npx tsc

Running

  • node dist/index.js