Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/fcouceiro/nutiljs

A node.js command-line tool for generating boilerplate (controllers, services, models and resources) based on placeholders provided by the user.
https://github.com/fcouceiro/nutiljs

boilerplate cli generator nodejs placeholder utility

Last synced: about 2 months ago
JSON representation

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

Awesome Lists containing this project

README

        

logoxhdpi

# 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](https://www.npmjs.com/package/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](https://github.com/fcouceiro/nutil/tree/master/placeholders/controllers):

nutil --controller (-c)

Create a service based on [provided placeholder](https://github.com/fcouceiro/nutil/tree/master/placeholders/services):

nutil --service (-s)

Create a model based on [provided placeholder](https://github.com/fcouceiro/nutil/tree/master/placeholders/models):

nutil --model (-m)

Create a resource based on [provided placeholder](https://github.com/fcouceiro/nutil/tree/master/placeholders/resources):

nutil --resource (-r)


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

nutil -s -c

__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:

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](https://www.npmjs.com/package/inflection).

## 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](#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](https://www.npmjs.com/package/joi) for model validation).