New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@lonestone/crud-generator

Package Overview
Dependencies
Maintainers
3
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lonestone/crud-generator

A simple CRUD generator for NestJS entities

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-75%
Maintainers
3
Weekly downloads
 
Created
Source

README

crud-generator is a tool that generates automatically a module with its entity, repository, service, conversion service, controller and main CRUD API entrypoints.

Usage

Go in the directory where you want to write the module and simply start crud-generator. The module's name and destination path will be prompted, and the files will be generated after confirmation.

Example of the output directory:

test-module
├── test-module.controller.ts
├── test-module.conversion.service.ts
├── test-module.entity.ts
├── test-module.module.ts
├── test-module.repository.ts
└── test-module.service.ts

Programmatic usage

It's possible to not be prompted the module's name and destination path by providing them as arguments and using the --auto flag:

# Generate module "test-module" in current directory
npm start -- test-module . --auto

How does it work

This package's source code contains a template directory to generate the module's files at runtime. If you want to add your own template, create a TypeScript file in this directory (with any name), and write the following inside:

import { Template } from '../template'

const tpl: Template = p => ({
  fileName: 'genius.ts',
  script: true,
  source: `
    console.log("I'm a genius!");
  `
})

export default tpl

In the exported callback's returned object, fileName is the name of the file to write and source its content. The p argument contains the callback's parameters, whose type is defined in src/cli/template.ts.

Then, register the template in the exported object of src/cli/templates/index.ts.

The related file will then be automatically generated at runtime.

Code formatting

The generated files are automatically formatted using ESLint and Prettier, by looking at the .eslintrc.json and .prettierrc files located in the destination path or one of its parent directories.

If no ESLint / Prettier configuration file is found, a warning is displayed to indicate no formatting will occur.

Refactoring

If a template needs to be removed or changed, it can be very simply edited in the dedicated file in src/cli/templates. New parameters can easily be added by extending the related type in src/cli/template.ts. They can also be renamed easily, as most IDEs support automatic refactoring, performing the renaming in all templates that already use this parameter.

TODO

  • Handle relations correctly in default CRUD DTOs generics

FAQs

Package last updated on 31 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc