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 cliScaffolding Commands
make:controller - Create a new controller:
deno task cli make:controller User
# With automatic view generation
deno task cli make:controller User --viewThe --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 --viewSupported 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 abovemake:middleware - Create a new middleware:
deno task cli make:middleware Authmake:service - Create a new service:
deno task cli make:service Usermake:repository - Create a new repository:
deno task cli make:repository Postmake:job - Create a background job:
deno task cli make:job SendWelcomeEmailmake:command - Create a custom CLI command:
deno task cli make:command Greetmake:component - Create a JSX component:
deno task cli make:component Buttonmake:view - Create a new view/page:
deno task cli make:view homemake:error-pages - Generate all error pages (404, 401, 403, 500):
deno task cli make:error-pagesCreates error pages in app/view/pages/errors/ with minimal HTML (no styling). After generation, configure the error handler in app/kernel.tsx.
make:crud - Scaffold complete CRUD (model, repository, service, controller, views):
deno task cli make:crud PostGenerates:
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 providersDatabase Commands
db:generate - Generate migration from schema:
deno task cli db:generatedb:migrate - Run pending migrations:
deno task cli db:migratedb:push - Push schema directly to database:
deno task cli db:pushdb:studio - Launch Drizzle Studio:
deno task cli db:studiodb:seed - Run database seeders:
deno task cli db:seed # Run all seeders
deno task cli db:seed User # Run specific seederCustom 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:
1. Reads the lockness.packages array. 2. Dynamically imports @lockness/{name}. 3. 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=jsonInteractive REPL (Tinker)
Explore your application interactively:
deno task cli tinkerThe 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:workqueue:clear - Clear all jobs from queue:
deno task cli queue:clear