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.
- π 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.
To install the CLI globally via npm:
npm install -g crud-builder-cliAlternatively, to run/link it locally from source:
-
Clone the repository:
git clone https://github.com/senuda-d/CRUD-generator-CLI.git cd CRUD-generator-CLI -
Install dependencies:
npm install
-
Link the package globally:
npm link
Now you can use the global command crud-builder anywhere on your system!
The CLI provides two main commands: init and generate.
To scaffold a new Node/Express application structure:
crud-builder init my-awesome-appThis 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
Generate modular CRUD components for a database entity. You must navigate to your project directory and run:
crud-builder generate <EntityName> [options]| 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). |
-
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"
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
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 testThis runs both unit tests for the template engine and integration tests for the generators.
Contributions are what make the open-source community an amazing place to learn, inspire, and create.
- Fork the Project.
- Create your Feature Branch (
git checkout -b feature/AmazingFeature). - Commit your changes (
git commit -m 'feat: add some AmazingFeature'). - Push to the Branch (
git push origin feature/AmazingFeature). - Open a Pull Request.
Distributed under the MIT License. See LICENSE for more information.