0.4.2 • Published 6 years ago

nutiljs v0.4.2

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

nutil - Node Utility

A command-line tool for generating boilerplate (controllers, services, models and resources) based on placeholders provided by the user.

Installation

Globally:

  • yarn global add nutiljs

or

  • npm i -g nutiljs

You will then be able to run nutil from the command line.

Locally:

  • yarn add nutiljs

or

  • npm i nutiljs

Use a package runner like npx to run locally installed packages.

You will then be able to run npx nutil from the command line.

Usage

Create a controller based on the provided placeholder:

nutil --controller (-c) <controllerName>

Create a service based on provided placeholder:

nutil --service (-s) <serviceName>

Create a model based on provided placeholder:

nutil --model (-m) <modelName>

Create a resource based on provided placeholder:

nutil --resource (-r) <resourceName>

Multiple generations can take place with a single command, by concatenatig different options. Example: create both a controller and a service:

nutil -s <serviceName> -c <controllerName>

Note: Generated files will be created in the directory where you run nutil from (cwd)

How it works

There is a pre-defined set of placeholder keys, as represented in the following table:

KeyMeaning
nameSingular lower case
NAMESingular upper case
NameSingular pascal case
namesPlural lower case
NAMESPlural upper case
NamesPlural pascal case

When the user requests the generation of a certain type, the generator spawns a process that "search and replace" the corresponding type placeholders (both in file name and file content). It substitutes all found keys with the appropriate casing (e.g. name would be replaced by the controller name in singular lower case; Names in plural pascal case; etc).

Case representations are generated by the great inflection package.

Placeholders

All boilerplate is generated based on placeholders provided by the user. Feel free to use different placeholder keys in both file name and content, as described in How it works section.

Placeholders must be placed inside placeholders/ folder.

A few basic placeholders are included by default (using mongoose for model generation and Joi for model validation).