Skip to content

senuda-d/NodeCrudify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

46 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

CRUD Builder CLI

npm version npm downloads MIT License Node.js Version Build Status

A powerful, customizable, and developer-friendly Command Line Interface (CLI) tool designed to automate the scaffolding of Node.js/Express projects and Mongoose-backed CRUD (Create, Read, Update, Delete) components.


πŸš€ Features

  • πŸ“‚ Project Scaffolding: Initialize a complete Express.js boilerplate structure in one command.
  • ⚑ Custom Template Engine: Uses clean template files (templates/) instead of fragile inline code strings.
  • πŸ—ƒοΈ Smart Code Generators: Generates Mongoose models, controller logic, and Express routing files.
  • πŸ§ͺ Field-Aware Validation: Pass field schemas through the CLI to automatically generate database models and request body validators.
  • πŸ› οΈ Extensible Architecture: Built on Commander.js for a robust command structure.

πŸ“¦ Installation

To install the CLI globally via npm:

npm install -g crud-builder-cli

Alternatively, to run/link it locally from source:

  1. Clone the repository:

    git clone https://github.com/senuda-d/CRUD-generator-CLI.git
    cd CRUD-generator-CLI
  2. Install dependencies:

    npm install
  3. Link the package globally:

    npm link

Now you can use the global command crud-builder anywhere on your system!


πŸ› οΈ Usage Guide

The CLI provides two main commands: init and generate.

1. Initialize a New Project

To scaffold a new Node/Express application structure:

crud-builder init my-awesome-app

This command creates a new folder my-awesome-app with the following structure:

my-awesome-app/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app.js             # Starter Express application
β”‚   β”œβ”€β”€ controllers/       # Folder for controllers
β”‚   β”œβ”€β”€ models/            # Folder for Mongoose models
β”‚   └── routes/            # Folder for Express routes
β”œβ”€β”€ .gitignore
└── package.json

2. Generate CRUD Components

Generate modular CRUD components for a database entity. You must navigate to your project directory and run:

crud-builder generate <EntityName> [options]

CLI Options & Flags

Flag Description
--model Generates a Mongoose schema model.
--controller Generates a controller with standard CRUD request handlers.
--route Generates REST routes mapping HTTP verbs to controllers.
--crud Shortcut to generate model, controller, and routes (same as using all three flags).
--fields <fields> Comma-separated list of field names and types (e.g. title:string,price:number).

Examples

  • Generate a basic model and controller with validation fields:

    crud-builder generate Task --model --controller --fields "title:string,completed:boolean,dueDate:date"
  • Generate complete CRUD routes, models, and controllers in one go:

    crud-builder generate User --crud --fields "email:string,age:number,active:boolean"

πŸ“ Repository Structure

CRUD-generator-CLI/
β”œβ”€β”€ bin/
β”‚   └── cli.js            # CLI entrypoint
β”œβ”€β”€ commands/
β”‚   β”œβ”€β”€ generate.js       # Action handler for component generation
β”‚   └── init.js           # Action handler for project initialization
β”œβ”€β”€ generators/
β”‚   β”œβ”€β”€ controllerGenerator.js
β”‚   β”œβ”€β”€ modelGenerator.js
β”‚   β”œβ”€β”€ projectGenerator.js
β”‚   └── routeGenerator.js
β”œβ”€β”€ templates/            # Source templates used by generators
β”‚   β”œβ”€β”€ app.template.js
β”‚   β”œβ”€β”€ controller.template.js
β”‚   β”œβ”€β”€ model.template.js
β”‚   └── route.template.js
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ fileWriter.js
β”‚   β”œβ”€β”€ nameHelper.js
β”‚   └── templateEngine.js # Custom regex-based replacement helper
└── tests/                # Automated tests
    β”œβ”€β”€ generators.test.js
    └── templateEngine.test.js

πŸ§ͺ Running Tests

The project utilizes the native Node.js test runner (introduced in Node v18+), requiring no third-party test runners or heavy testing frameworks.

To execute the test suite:

npm test

This runs both unit tests for the template engine and integration tests for the generators.


🀝 Contributing

Contributions are what make the open-source community an amazing place to learn, inspire, and create.

  1. Fork the Project.
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature).
  3. Commit your changes (git commit -m 'feat: add some AmazingFeature').
  4. Push to the Branch (git push origin feature/AmazingFeature).
  5. Open a Pull Request.

πŸ“„ License

Distributed under the MIT License. See LICENSE for more information.

About

A modular CLI tool that generates full CRUD backend structures (models, controllers, routes) instantly using a template-driven system.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors