CLI Commands
Asena CLI provides command-line utilities to help you manage your Asena applications efficiently.
Installation
Prerequisite: Bun runtime (v1.2.8 or higher)
bun install -g @asenajs/asena-cli
Verify installation:
asena --version
asena create
Bootstrap a new Asena project with a complete development environment setup.
Features
- Interactive Setup - User-friendly setup experience with inquirer
- Multi-Adapter Support - Choose between Hono or Ergenecore adapters
- Project Structure - Creates complete project structure with necessary files
- Default Components - Generates default controller and server setup
- Development Tools - Optional ESLint and Prettier integration
- Dependency Management - Automatically installs required dependencies
Usage
asena create
Interactive Prompts
✔ Enter your project name: my-asena-app
✔ Select adapter: Ergenecore
✔ Do you want to setup ESLint? Yes
✔ Do you want to setup Prettier? Yes
⠙ Creating asena project...
Generated Project Structure
my-asena-app/
├── src/
│ ├── controllers/ # Route controllers
│ ├── services/ # Business logic
│ ├── middlewares/ # Middleware files
│ ├── config/ # Server configuration classes
│ ├── namespaces/ # WebSocket namespaces
│ └── index.ts # Application entry point
├── tests/ # Test files
├── public/ # Static assets
├── asena.config.ts # Configuration
├── package.json
└── tsconfig.json
asena generate
Quickly and consistently create project components with proper structure and imports.
Shortcut: asena g
Features
- Multi-Component Support - Generate controllers, services, middlewares, configs, and websockets
- Automatic Code Generation - Creates template code with base structure and necessary imports
- Adapter-Aware - Generates adapter-specific code based on project configuration
- Project Structure Integration - Places files in the correct directories
- Command Shortcuts - Faster usage with aliases
Commands
Component | Full Command | Shortcut | Description |
---|---|---|---|
Controller | asena generate controller | asena g c | Generates a controller |
Service | asena generate service | asena g s | Generates a service |
Middleware | asena generate middleware | asena g m | Generates a middleware |
Config | asena generate config | asena g config | Generates a server config |
WebSocket | asena generate websocket | asena g ws | Generates a WebSocket namespace |
Examples
Generate Controller
asena g c
# or
asena generate controller
Prompt:
✔ Enter controller name: User
Generated: src/controllers/UserController.ts
import { Controller } from '@asenajs/asena/server';
import { Get } from '@asenajs/asena/web';
import type { Context } from '@asenajs/ergenecore/types';
@Controller('/user')
export class UserController {
@Get({ path: '/' })
async index(context: Context) {
return context.send({ message: 'Hello from UserController!' });
}
}
Generate Service
asena g s
# or
asena generate service
Prompt:
✔ Enter service name: User
Generated: src/services/UserService.ts
import { Service } from '@asenajs/asena/server';
@Service()
export class UserService {
async getUsers() {
// Add your business logic here
return [];
}
}
Generate Middleware
asena g m
# or
asena generate middleware
Prompt:
✔ Enter middleware name: Auth
Generated: src/middlewares/AuthMiddleware.ts
import { Middleware } from '@asenajs/asena/server';
import { MiddlewareService, type Context } from '@asenajs/ergenecore';
@Middleware()
export class AuthMiddleware extends MiddlewareService {
async handle(context: Context, next: () => Promise<void>) {
// Add your middleware logic here
await next();
}
}
Generate Config
asena g config
# or
asena generate config
Prompt:
✔ Enter config name: Server
Generated: src/config/ServerConfig.ts
import { Config } from '@asenajs/asena/server';
import { ConfigService, type Context } from '@asenajs/ergenecore';
@Config()
export class ServerConfig extends ConfigService {
onError(error: Error, context: Context): Response {
console.error('Error:', error);
return context.send({ error: 'Internal server error' }, 500);
}
}
Generate WebSocket
asena g ws
# or
asena generate websocket
Prompt:
✔ Enter websocket namespace name: Chat
Generated: src/namespaces/ChatNamespace.ts
import { Websocket } from '@asenajs/asena/server';
import { WebsocketService, type Context } from '@asenajs/ergenecore';
@Websocket({ namespace: '/chat' })
export class ChatNamespace extends WebsocketService {
onConnect(context: Context): void {
console.log('Client connected to /chat');
}
onMessage(context: Context, message: any): void {
console.log('Message received:', message);
}
onDisconnect(context: Context): void {
console.log('Client disconnected from /chat');
}
}
Adapter-Specific Generation
The CLI automatically detects your adapter (Ergenecore or Hono) from asena.config.ts
and generates appropriate imports and base classes.
asena dev start
Start the application in development mode with automatic building.
Features
- Automatic Build - Builds the project before starting
- Component Registration - Automatically registers all controllers, services, and middlewares
- Hot Reload - Restarts server on file changes (when used with
--watch
)
Usage
asena dev start
Output
Build completed successfully.
2025-10-15 14:30:19 [info]:
___ _____ ______ _ __ ___
/ | / ___/ / ____// | / // |
/ /| | \__ \ / __/ / |/ // /| |
/ ___ | ___/ // /___ / /| // ___ |
/_/ |_|/____//_____//_/ |_//_/ |_|
2025-10-15 14:30:20 [info]: Adapter: ErgenecoreAdapter implemented
2025-10-15 14:30:20 [info]: All components registered and ready to use
2025-10-15 14:30:20 [info]: Controller: UserController found:
2025-10-15 14:30:20 [info]: Successfully registered GET route for PATH: /users
2025-10-15 14:30:20 [info]: Controller: UserController successfully registered.
2025-10-15 14:30:20 [info]: Server started on port 3000
Controller Names in Output
Controller names are visible in logs when buildOptions.minify.identifiers
is set to false
in asena.config.ts
.
asena build
Build the project for production deployment.
Features
- Configuration Processing - Reads and processes
asena.config.ts
- Code Generation - Creates a temporary build file combining all components
- Import Management - Automatically organizes imports based on project structure
- Server Integration - Integrates all components with AsenaServer
- No Manual Registration - Controllers are automatically discovered and registered
Usage
asena build
Build Process
- Reads
asena.config.ts
- Scans source folder for controllers, services, middlewares, configs, and websockets
- Generates a temporary build file with all imports
- Bundles the application using Bun's bundler
- Outputs compiled files to
buildOptions.outdir
(default:dist/
)
Build Output
Build completed successfully.
Output: dist/index.js
Production Deployment
After building, you can run your application with:
bun dist/index.js
asena init
Initialize an existing project with Asena configuration.
Features
- Configuration Generation - Creates
asena.config.ts
- Default Values - Provides sensible defaults for quick start
- No Need if Using
create
- Not required if you usedasena create
Usage
asena init
Generated Configuration
Creates asena.config.ts
:
import { defineConfig } from '@asenajs/asena-cli';
export default defineConfig({
sourceFolder: 'src',
rootFile: 'src/index.ts',
buildOptions: {
outdir: 'dist',
sourcemap: 'linked',
target: 'bun',
minify: {
whitespace: true,
syntax: true,
identifiers: false,
},
},
});
When to Use asena init
Use asena init
when:
- Adding Asena to an existing project
- Manually setting up a project without
asena create
- Resetting configuration to defaults
Command Reference
Quick Reference
Command | Shortcut | Description |
---|---|---|
asena create | - | Create a new Asena project |
asena generate | asena g | Generate project components |
asena generate controller | asena g c | Generate a controller |
asena generate service | asena g s | Generate a service |
asena generate middleware | asena g m | Generate a middleware |
asena generate config | asena g config | Generate a config |
asena generate websocket | asena g ws | Generate a WebSocket namespace |
asena dev start | - | Start development server |
asena build | - | Build for production |
asena init | - | Initialize configuration |
asena --version | asena -v | Show CLI version |
asena --help | asena -h | Show help |
Related Documentation
- Configuration - CLI configuration options
- CLI Examples - See complete project examples
- Controllers - Controller patterns
- Services - Service patterns
- Middleware - Middleware patterns
- WebSocket - WebSocket patterns
Next Steps:
- Learn about CLI Configuration
- See CLI Examples for project structure
- Understand Controllers