1.0.5 • Published 10 months ago

backend-smith v1.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

Backend Smith (CLI Tool)

Backend Smith is a custom CLI tool, invoked using the command bs, designed to help automate the creation of various components such as modules, schemas, routes, services, controllers, validations, and DTOs for an Express.js backend. It simplifies backend structure generation.

What's new

Bug fixes, enum support and auto-formatting for generated files

Table of Contents

Installation

To use Backend Smith, install it globally or locally.

Global Installation

npm install -g backend-smith

Local Installation

To use it locally in your project:

npm install backend-smith --save-dev

Then, you can run it with npx:

npx bs <operation> <name> [fields...]

Usage

Run the CLI using the following syntax:

bs <operation> <name> [fields...]

Available Commands

Backend Smith supports the following operations:

OperationDescription
createCreates a base structure for the given name
create:moduleCreates a module with the specified fields
create:schemaCreates a schema with the specified fields
create:routeCreates a route
create:serviceCreates a service
create:controllerCreates a controller
create:validationCreates validation logic for the fields
create:dtoCreates a Data Transfer Object (DTO)

Command Options

  • <operation>: Specifies the type of component to create (e.g., create:module, create:route, etc.).
  • <name>: The name of the component to be created.
  • [fields...]: An optional list of fields to be used in schemas, DTOs, or validations. Fields should be provided in the format fieldName:fieldType (e.g., username:String, age:Number).

You can also pass fields as an array or object:

  • Array: Pass multiple fields as separate arguments (e.g., username:String age:Number email:String).
  • Object: Pass fields in the format { fieldName: fieldType } (e.g., { username:String, age:Number, email:String }).
  • enum: Pass fields in the format fieldName:fieldTypes (e.g., role:USER|ADMIN).

To mark a field as required, prepend the field name with an asterisk (e.g., *username:String).

Examples

  1. Create a base structure:

    bs create app-name

  2. Create a module with fields:

    bs create:module user *username:String age:Number *email:String *role:USER|ADMIN

  3. Create a schema:

    bs create:schema user *username:String age:Number *email:String *role:USER|ADMIN

  4. Create a route:

    bs create:route user

  5. Create a service:

    bs create:service user

  6. Create a controller:

    bs create:controller user

  7. Create validation for fields:

    bs create:validation user *username:String age:Number *email:String *role:USER|ADMIN

  8. Create a Data Transfer Object (DTO):

    bs create:dto user *username:String age:Number *email:String *role:USER|ADMIN

Error Handling

  • If no operation is provided, the CLI will log:

    Operation is required!

  • If no name is provided for the component, the CLI will log:

    Name is required!

  • If an invalid operation is provided, the CLI will log:

    Invalid <operation> operation

Contributing

Contributions are welcome! To contribute to Backend Smith, feel free to fork the repository and submit a pull request.

Repository: Backend Smith GitHub