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

repetitive-code-generator

v1.0.4

Published

Code generator designed to automate repetitive task of generating the same files with only different names, for example controllers, tests etc. It can works with any documents and languages (JS, TS, C#, PHP, PYTHON, etc).

Downloads

29

Readme

RCG

VERY simple and fast to use tool that automates creating repetitive files with customized parts. No configuration required, only template files!

Getting started

What is RCG?

RCG was created to automate a repetitive files generation. Let’s say you are creating a new CRUD project. Often you’d have to copy the existing files like Controllers, Services, database Entities, Tests etc. and change the name of a file and some internal content to mach a new name. RCG can automate this proceses. You only need to create a template file with folder structure, replace content to rename it with a custome placeholders and fire up RCG whenever you'd like to create a new CRUD operation. RCG will ask you to provide necessary placeholder replacement, and will put those files in a proper places.

Instalation

$ npm install -g repetitive-code-generator

Setting up

Create a new folder rcg - this is where your templates will be stored.

Optionaly create a new file in a root directory of your project.

// rcg.json
{
  "templateFolder": "rcg",
  "entryTargetFolder": ""
}

templateFolder - name of the folder with templates. Default rcg. entryTargetFolder - entry folder where the content should be generated. Default empty string (root directory).

First template

You can have many templates configured for one project. RCG will ask you which template to use. Create a new folder inside rcg folder. You can name it whatever you like. For example crud. This folder will contain all files you want to generate. Now, it's important, to recreate a folder structure of an existing project, so RCG knows where to put new files. For example you want to create a controller, service and entity. Project structure: folder structure

backend is a folder where we want to add new files

rcgTemplateFolder is a folder where we have two templates: crud and someOtherTemplate

crud template contains the same folder structure as backend. The only difference is that there are only files which we want to generate. You can create a new folder (if you want to have folders generated with specific name), and as many files as you like.

someOtherTemplate is empty template folder, just for demonstration

Let's see some sample file:

//{{MainNamePlural}}Controller.cs
using API.Entities;
using API.Services.{{MainNamePlural}};
using Microsoft.AspNetCore.Mvc;
namespace API.Controllers;
public class {{MainNamePlural}}Controller : ControllerBase
{
    [HttpGet]
    public async Task<{{MainName}}> Get(CancellationToken cancellationToken)
    {
        return new {{MainName}}();
    }
    [HttpPost]
    public async Task Create({{MainName}} request, CancellationToken cancellationToken)
    {
        var service = new {{MainName}}Service();
        service.Create{{MainName}}(request);
    }
    [HttpPut("{{{mainName}}Id}")]
    public async Task Update(long {{mainName}}Id, {{MainName}} {{mainName}}, CancellationToken cancellationToken)
    {
        var {{mainName}}Service = new {{MainName}}Service();
        {{mainName}}Service.Update{{MainName}}({{mainName}});
    }
}

As you can see, we are using placeholders to replace them with some data lateron. Placeholder format: {{placeholderName}}. You can create as many placeholders as you want. The same placeholder can be used in folder and file names.

Now to generate new files just open the console and type: rcg.

rcg console

Select templace and fill all placeholder values:

rcg filled placeholders

In this example we create a new CRUD for Cities. The result should be visible in our project:

result

And the controller content:

using API.Entities;
using API.Services.Cities;
using Microsoft.AspNetCore.Mvc;
namespace API.Controllers;
public class CitiesController : ControllerBase
{
    [HttpGet]
    public async Task<City> Get(CancellationToken cancellationToken)
    {
        return new City();
    }
    [HttpPost]
    public async Task Create(City request, CancellationToken cancellationToken)
    {
        var service = new CityService();
        service.CreateCity(request);
    }
    [HttpPut("{cityId}")]
    public async Task Update(long cityId, City city, CancellationToken cancellationToken)
    {
        var cityService = new CityService();
        cityService.UpdateCity(city);
    }
}

That's it. Have fun with saving lots of time :)