CLI Engine
Cli is Lockness's powerful command-line interface for scaffolding, database management, and custom commands.
Using Cli
Run any Cli command:
deno task cli [command] [arguments] [--flags]
List all available commands:
deno task cli
Scaffolding Commands
make:controller - Create a new controller:
deno task cli make:controller User
# With automatic view generation
deno task cli make:controller User --view
The --view flag automatically creates a corresponding view in
app/view/pages/{name}.tsx and generates a controller method that renders it
using c.html().
make:action - Add a new action (method) to an existing controller:
deno task cli make:action User show
# With specific HTTP method
deno task cli make:action User store --method=post
# With automatic view generation
deno task cli make:action User create --view
Supported methods: get, post, put, delete, patch. The command follows
RESTful conventions for common action names (index, show, create, store, edit,
update, destroy).
make:model - Create a model with optional related files:
deno task cli make:model Post # Just the model
deno task cli make:model Post -r # + Repository
deno task cli make:model Post -s # + Seeder
deno task cli make:model Post -c # + Controller
deno task cli make:model Post -a # All of the above
make:middleware - Create a new middleware:
deno task cli make:middleware Auth
make:service - Create a new service:
deno task cli make:service User
make:repository - Create a new repository:
deno task cli make:repository Post
make:job - Create a background job:
deno task cli make:job SendWelcomeEmail
make:command - Create a custom CLI command:
deno task cli make:command Greet
make:component - Create a JSX component:
deno task cli make:component Button
make:view - Create a new view/page:
deno task cli make:view home
make:error-pages - Generate all error pages (404, 401, 403, 500):
deno task cli make:error-pages
Creates error pages in app/view/pages/errors/ with inline CSS
(framework-agnostic). The error handler is automatically discovered by the
framework - no manual registration needed in app/kernel.tsx.
make:crud - Scaffold complete CRUD (model, repository, service, controller, views):
deno task cli make:crud Post
Generates:
app/model/post.ts- Drizzle schemaapp/repository/post_repository.ts- Data access layerapp/service/post_service.ts- Business logicapp/controller/post_controller.tsx- HTTP handlerapp/view/pages/post/index.tsx- List viewapp/view/pages/post/show.tsx- Detail view
After generation, define your schema in the model and run
deno task db:generate to create migrations.
make:auth - Scaffold authentication system:
deno task cli make:auth # Basic auth
deno task cli make:auth --social # With OAuth2 providers
Database Commands
db:generate - Generate migration from schema:
deno task cli db:generate
db:migrate - Run pending migrations:
deno task cli db:migrate
db:push - Push schema directly to database:
deno task cli db:push
db:studio - Launch Drizzle Studio:
deno task cli db:studio
db:seed - Run database seeders:
deno task cli db:seed # Run all seeders
deno task cli db:seed User # Run specific seeder
Custom Commands
Create your own CLI commands:
import { Command, type CommandContext, type ICommand } from '@lockness/cli'
@Command('greet', 'Say hello to someone')
export class GreetCommand implements ICommand {
async handle(ctx: CommandContext) {
const name = ctx.arg(0) || 'World'
if (ctx.hasFlag('verbose')) {
console.log('Running in verbose mode...')
}
console.log(`Hello, ${name}!`)
const format = ctx.getFlag('format')
if (format) {
console.log(`Format: ${format}`)
}
}
}
Plugin System & Extensions
Lockness features a zero-config extension system that allows official and third-party packages to register their own CLI commands automatically.
Automatic Package Loading
The cli.ts entry point in your project uses loadPackageCommands(cli) to
dynamically load commands from any package listed in your deno.json.
// deno.json
{
"lockness": {
"packages": [
"drizzle",
"openapi",
"queue"
]
}
}
When you run deno task cli, the engine:
- Reads the
lockness.packagesarray. - Dynamically imports
@lockness/{name}. - Executes the package's registration function.
This means that after installing a new package, its commands (like db:migrate
or openapi:generate) are immediately available without any manual code
changes.
Custom Command Discovery
Your own commands are automatically discovered from app/command/ as long as
they use the @Command decorator and the class is exported.
import { Command, type CommandContext, type ICommand } from '@lockness/cli'
@Command('greet', 'Say hello')
export class GreetCommand implements ICommand {
async handle(ctx: CommandContext) {
console.log(`Hello, ${ctx.arg(0) || 'World'}!`)
}
}
Manual Registration
For advanced scenarios, you can manually register commands in cli.ts:
import { Cli, registerCoreCommands } from '@lockness/cli'
import { MyCustomCommand } from './my_command.ts'
const cli = new Cli()
registerCoreCommands(cli)
// Manually register a class
cli.registerCommand(MyCustomCommand)
// Or a simple function
cli.register('simple', async (args) => {
console.log('Simple command')
}, 'A simple function command')
await cli.run(Deno.args)
Commands are auto-discovered from app/command/.
Run your command:
deno task cli greet John
deno task cli greet --verbose
deno task cli greet --format=json
Interactive REPL (Tinker)
Explore your application interactively:
deno task cli tinker
The REPL automatically loads:
- All models from
app/model/ - All services from
app/service/ - All repositories from
app/repository/
Example session:
🔮 Lockness Tinker - Interactive REPL
📦 Loaded: users, UserService, UserRepository
>>> 2 + 2
4
>>> await UserRepository.findAll()
[{ id: 1, email: "..." }]
>>> .exit
👋 Bye!
REPL Commands:
.help- Show available commands.context- List loaded variables.clear- Clear the screen.exit- Exit the REPL
Queue Commands
queue:work - Process background jobs:
deno task cli queue:work
queue:clear - Clear all jobs from queue:
deno task cli queue:clear