1.0.5 ⢠Published 6 months ago
ely-cli v1.0.5
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 š
Command | Description |
---|---|
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 š”
Module Organization:
- Keep related functionality together
- Use clear naming conventions
- Separate concerns (controller, service, routes)
Database Handling:
- Use services for database operations
- Implement proper error handling
- Follow MongoDB best practices
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
- Email: alexveros46@mail.com
- GitHub: @Jorlex27