1.0.5 • Published 4 months ago

hono-cli v1.0.5

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

Hono-CLI 🦊

A powerful CLI tool for scaffolding and managing Hono.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 Hono
  • Path aliases for better imports
  • Environment configuration
  • Developer-friendly CLI interface

Installation šŸš€

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

Usage šŸ“š

Create New Project

hono-cli init my-project

This will create a new Hono.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

hono-cli g:m 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
ā”œā”€ā”€ user.validation.ts
└── index.ts

Generate Router Only

hono-cli g:r user

This generates a minimal module with just routing functionality:

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

The router generator:

  • Creates only routing-related files
  • Automatically registers routes in the route manager
  • Perfect for simple API endpoints without complex business logic

Version Check

hono-cli version
# or
hono-cli v

Shows detailed package information:

  • Current package version
  • List of installed dependencies and their versions
  • List of development dependencies and their versions

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 || 'hono_dev'
    },
  test: {
        url: process.env.TEST_DB_URL || 'mongodb://localhost:27017',
        name: process.env.TEST_DB_NAME || 'hono_test',
        options: {
            maxPoolSize: 5,
            minPoolSize: 1
        }
    },
    production: {
        url: process.env.PROD_DB_URL || 'mongodb://localhost:27017',
        name: process.env.PROD_DB_NAME || 'hono_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=hono_dev

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

Commands Reference šŸ“–

CommandDescription
hono-cli init <name>Create new Hono.js project
hono-cli g:m <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

4 months ago

1.0.4

6 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago