Introduction
Ace is built on top of the @adonisjs/ace package and provides AdonisJS-specific functionality like dependency injection, application lifecycle management, and seamless integration with the framework’s core features. Every AdonisJS application comes with abin/console.ts file that serves as the entry point for Ace commands. You run commands using the node ace binary:
Key Features
Dependency Injection
Ace commands in AdonisJS support full dependency injection through the IoC container. This means you can inject services, repositories, and other dependencies directly into your command classes.Application Integration
Commands have direct access to the application instance (this.app), allowing you to:
- Access configuration
- Interact with the IoC container
- Use application services
- Read from
.adonisrc.tsconfiguration
Interactive Prompts
Ace provides built-in support for interactive prompts, allowing you to:- Ask for user input
- Display choice menus
- Show confirmation dialogs
- Validate user responses
Codemods Support
Many make commands use codemods to programmatically modify source files, enabling:- AST-based code transformations
- Automatic registration in configuration files
- Safe and reliable code generation
Running Commands
Basic Syntax
The basic syntax for running Ace commands is:Listing Available Commands
To see all available commands in your application:node ace without any arguments.
Getting Help
To get help for a specific command:Global Flags
Ace supports global flags that work with all commands:--ansi / --no-ansi
Force enable or disable colorful output:
--help
Display help information for any command:
Common Commands
Here are some of the most commonly used Ace commands:Package Management
Development
Testing
Code Generation
Utilities
Ace Architecture
The Kernel
The Ace Kernel is the core component that manages command execution. It:- Registers and discovers commands
- Parses command-line arguments
- Handles command execution lifecycle
- Manages error handling
- Provides UI primitives for output
Base Command
All Ace commands extend theBaseCommand class, which provides:
- Access to the application instance
- Logger for output
- Prompt utilities for user interaction
- Lifecycle hooks (prepare, interact, run, completed)
- Codemods support for code generation
Command Lifecycle
When a command is executed, it goes through the following lifecycle:- Instantiation - Command is instantiated with dependency injection
- Hydration - Arguments and flags are parsed and assigned to class properties
- Prepare - Optional
prepare()hook is called - Interact - Optional
interact()hook is called for user prompts - Run - The main
run()method is executed - Completed - Optional
completed()hook is called - Error Handling - If an error occurs, it’s handled by the kernel’s error handler
Exit Codes
Commands can set exit codes to indicate success or failure:Next Steps
Working with Commands
Learn how to create and customize your own Ace commands
Make Commands
Explore all available make commands for code generation
Ace Kernel
Deep dive into the Ace Kernel and command registration