A command-line tool for generating boilerplate (controllers, services, models and resources) based on placeholders provided by the user.
yarn global add nutiljs
or
npm i -g nutiljs
You will then be able to run nutil
from the command line.
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.
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)
There is a pre-defined set of placeholder keys, as represented in the following table:
Key | Meaning |
---|---|
[name] | Singular lower case |
[NAME] | Singular upper case |
[Name] | Singular pascal case |
[names] | Plural lower case |
[NAMES] | Plural upper case |
[Names] | Plural 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.
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).