CLI
binja includes a CLI tool for template pre-compilation, validation, and linting.
Installation
The CLI is included with binja:
bun add binjaRun with:
bunx binja <command># orbun x binja <command>Commands
compile
Compile templates to JavaScript for production.
binja compile ./templates -o ./distOptions:
| Option | Description |
|---|---|
-o, --output <dir> | Output directory |
-w, --watch | Watch for changes |
--minify | Minify output |
Example:
# Compile all templatesbinja compile ./views -o ./dist/templates
# Watch modebinja compile ./views -o ./dist/templates --watchcheck
Validate templates for syntax errors.
binja check ./templatesOptions:
| Option | Description |
|---|---|
--strict | Fail on warnings |
--format <type> | Output format (text, json) |
Example:
# Check all templatesbinja check ./views
# JSON output for CIbinja check ./views --format jsonwatch
Watch templates and recompile on changes.
binja watch ./templates -o ./distlint
Check templates for issues (syntax, security, best practices).
binja lint ./templatesOptions:
| Option | Description |
|---|---|
--ai | Enable AI-powered analysis |
--ai=<provider> | Use specific AI provider |
--format <type> | Output format (text, json) |
Example:
# Syntax check onlybinja lint ./views
# With AI analysis (auto-detect provider)binja lint ./views --ai
# With specific AI providerbinja lint ./views --ai=anthropicbinja lint ./views --ai=openaibinja lint ./views --ai=ollamabinja lint ./views --ai=groq
# JSON output for CI/CDbinja lint ./views --ai --format=jsonCI/CD Integration
GitHub Actions
name: Template Check
on: [push, pull_request]
jobs: check: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: oven-sh/setup-bun@v1
- name: Install dependencies run: bun install
- name: Check templates run: bunx binja check ./templates --format jsonWith AI Linting
name: Template Lint
on: [push, pull_request]
jobs: lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: oven-sh/setup-bun@v1
- name: Install dependencies run: bun install
- name: Lint templates env: ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} run: bunx binja lint ./templates --ai --format jsonExit Codes
| Code | Description |
|---|---|
0 | Success |
1 | Error (syntax error, file not found) |
2 | Warnings (with —strict) |
Compiled Output
When using compile, templates are converted to JavaScript:
Input: views/user.html
<h1>{{ name|upper }}</h1><p>Email: {{ email }}</p>Output: dist/user.js
export function render(ctx) { let __out = ''; __out += '<h1>'; __out += escape(ctx.name.toUpperCase()); __out += '</h1>\n<p>Email: '; __out += escape(ctx.email); __out += '</p>'; return __out;}Using Compiled Templates
import { render as renderUser } from './dist/user.js'
const html = renderUser({ name: 'john', email: 'john@example.com'})