1.0.5 • Published 6 months ago

ely-cli v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Ely-CLI 🦊

A powerful CLI tool for scaffolding and managing Elysia.js projects. Create new projects, generate modules, and streamline your development workflow with MongoDB integration.

Features ✨

  • Quick project initialization with best practices
  • Module generation with CRUD operations
  • MongoDB integration out of the box
  • Swagger documentation
  • Type-safe routes with Elysia
  • Path aliases for better imports
  • Environment configuration
  • Developer-friendly CLI interface

Installation šŸš€

npm install -g ely-cli
# or
bun install -g ely-cli

Usage šŸ“š

Create New Project

ely-cli init my-project

This will create a new Elysia.js project with the following structure:

my-project/
ā”œā”€ā”€ src/
│   ā”œā”€ā”€ modules/      # Feature modules
│   ā”œā”€ā”€ shared/       # Shared utilities and middleware
│   │   ā”œā”€ā”€ middleware/
│   │   └── utils/
│   ā”œā”€ā”€ config/      # Configuration files
│   ā”œā”€ā”€ index.ts     # Application entry point
│   └── routes.ts    # Route manager
ā”œā”€ā”€ .env             # Environment variables
ā”œā”€ā”€ .gitignore
ā”œā”€ā”€ package.json
ā”œā”€ā”€ README.md
└── tsconfig.json

Generate Module

ely-cli generate:module user

This generates a new module with:

  • Controller with CRUD operations
  • Service layer with MongoDB integration
  • Type definitions
  • Route configuration with Swagger docs
  • Automatic route registration

Generated module structure:

src/modules/user/
ā”œā”€ā”€ user.controller.ts
ā”œā”€ā”€ user.service.ts
ā”œā”€ā”€ user.routes.ts
ā”œā”€ā”€ user.types.ts
└── index.ts

Configuration šŸ› 

Database

Database configuration is located in src/config/db.config.ts:

export const dbConfig = {
  development: {
        url: process.env.DB_URL || 'mongodb://localhost:27017',
        name: process.env.DB_NAME || 'elysia_dev'
    },
  test: {
        url: process.env.TEST_DB_URL || 'mongodb://localhost:27017',
        name: process.env.TEST_DB_NAME || 'elysia_test',
        options: {
            maxPoolSize: 5,
            minPoolSize: 1
        }
    },
    production: {
        url: process.env.PROD_DB_URL || 'mongodb://localhost:27017',
        name: process.env.PROD_DB_NAME || 'elysia_prod',
        options: {
            maxPoolSize: 20,
            minPoolSize: 10,
            retryWrites: true,
            retryReads: true
        }
    }
}

Environment Variables

Available environment variables:

NODE_ENV=development
PORT=3000

# Database Configuration
DB_URL=mongodb://localhost:27017
DB_NAME=elysia_dev

# Production Database
PROD_DB_URL=mongodb://your-production-url:27017
PROD_DB_NAME=elysia_prod

Commands Reference šŸ“–

CommandDescription
ely-cli init <name>Create new Elysia.js project
ely-cli generate:module <name>Generate new module with CRUD

Project Structure šŸ—

src/
ā”œā”€ā”€ modules/           # Feature modules
│   └── user/         # Example module
│       ā”œā”€ā”€ user.controller.ts
│       ā”œā”€ā”€ user.service.ts
│       ā”œā”€ā”€ user.routes.ts
│       └── user.types.ts
ā”œā”€ā”€ shared/
│   ā”œā”€ā”€ middleware/   # Custom middleware
│   └── utils/        # Utility functions
ā”œā”€ā”€ config/           # Configuration files
│   ā”œā”€ā”€ db.config.ts
│   └── collections.config.ts
ā”œā”€ā”€ index.ts          # Application entry
└── routes.ts         # Route manager

Best Practices šŸ’”

  1. Module Organization:

    • Keep related functionality together
    • Use clear naming conventions
    • Separate concerns (controller, service, routes)
  2. Database Handling:

    • Use services for database operations
    • Implement proper error handling
    • Follow MongoDB best practices
  3. Type Safety:

    • Define clear interfaces
    • Use TypeScript features
    • Validate API inputs

Contributing šŸ¤

Contributions are welcome! Please feel free to submit a Pull Request.

License šŸ“„

MIT Ā© Alex Veros

Author ✨

Alex Veros

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.0

6 months ago