Animated Circular Progress Bar0
Font.Lokio
Get Started

Getting Started

Panduan untuk memulai menggunakan Lokio CLI


Getting Started#

Apa itu Lokio?#

Lokio adalah CLI untuk membuat code generator dari template milikmu sendiri. Alih-alih copy-paste file lama setiap kali membuat service/component baru, kamu cukup definisikan template sekali — lalu generate sebanyak apapun hanya dengan satu perintah.

Cocok untuk:

  • Tim yang punya struktur folder/file yang konsisten
  • Project dengan banyak boilerplate berulang (service, controller, screen, dll.)
  • Onboarding developer baru agar langsung ikut konvensi tim

Instalasi#

# Menggunakan bun
bun install -g lokio
 
# Menggunakan npm
npm install -g lokio
 
# Verifikasi instalasi
lokio --version

Inisialisasi Project#

Jalankan perintah ini di root folder project kamu:

lokio init

Ikuti promptnya:

◇  Select your primary language:
│  TypeScript

◇  Enable Enterprise feature?
│  No

✓ Project initialized

  Files created ✓
  - lokio.yaml
  - .gitignore (lokio.local.yaml added)
  - lokio/configs.yaml
  - lokio/templates/component.lokio

Run 'lokio gen' to generate code from templates.

Setelah selesai, struktur berikut akan dibuat:

project-kamu/
├── lokio.yaml              ← metadata project
├── lokio.local.yaml        ← API key (auto-gitignored — jangan commit!)
├── lokio.lock              ← tracking file yang sudah di-generate (commit ini!)
└── lokio/
    ├── configs.yaml        ← semua config: templates, check, ai, standards
    └── templates/
        └── component.lokio ← contoh template pertama

Isi lokio/configs.yaml setelah init#

File ini sudah berisi konfigurasi lengkap — tidak perlu setup manual:

templates:
  - name: component
    description: TypeScript component
    path: component.lokio
    output: src/components/<%= fileNameCase(name) %>.tsx
    parameters:
      - name: name
        type: string
        required: true
        prompt: Name
 
# ─── Lokio Check ──────────────────────────────────────────────────────────────
check:
  danger_mode: block
 
# ─── AI Standards Check ────────────────────────────────────────────────────────
# Tambahkan API key di lokio.local.yaml (sudah gitignored):
#   ai:
#     api_key: YOUR_KEY_HERE
#
ai:
  provider: gemini
  model: gemini-2.0-flash
 
standards:
  - id: unit-test
    description: "Every service must have a unit test file"
    severity: danger
  - id: no-console-log
    description: "No console.log in production code"
    severity: warning

Membuat Template Pertama#

lokio add

Contoh dialog:

◇  Template name:
│  service

◇  What does this template generate?
│  REST API service class

◇  Does this template generate more than one file at a time?
│  No

╭─ How it works ─────────────────────╮
│  Use <%= name %> di output path     │
│  untuk menyisipkan input user.      │
│  e.g. src/services/<%= name %>.ts   │
│       → src/services/UserService.ts │
╰─────────────────────────────────────╯

◇  Where should the generated file be saved?
│  src/services/<%= name %>Service.ts

◇  Blueprint filename:
│  service.lokio

◇  Add extra input variables besides 'name'?
│  No

✓  Template ready! Run 'lokio g service' to generate code from it.

Buka file lokio/templates/service.lokio dan isi dengan struktur yang kamu inginkan:

// lokio/templates/service.lokio
 
import { Injectable } from '@nestjs/common';
 
@Injectable()
export class <%= pascalCase(name) %>Service {
  async findAll() {
    return [];
  }
 
  async findOne(id: number) {
    return { id };
  }
}

Generate Code#

lokio gen

Atau langsung:

lokio g service User

Hasilnya: file src/services/UserService.ts otomatis dibuat dengan isi:

import { Injectable } from '@nestjs/common';
 
@Injectable()
export class UserService {
  async findAll() {
    return [];
  }
 
  async findOne(id: number) {
    return { id };
  }
}

Cek Setup dengan lokio doctor#

Setelah init, jalankan ini untuk memastikan semua berjalan dengan benar:

lokio doctor

Output contoh:

  Project Config
  ✓  lokio.yaml                     project: my-app v2.0.14

  Templates & Config
  ✓  lokio/configs.yaml             1 template(s)
  ✓    template: component          lokio/templates/component.lokio
  ✓  check config                   danger_mode: block

  AI Integration
  ✓  AI config                      provider: gemini, model: gemini-2.0-flash
  ✗  AI api_key                     not set — add api_key to lokio.local.yaml

  Security
  ✓  .gitignore                     lokio.local.yaml is listed

  Lock File
  –  lokio.lock                     no lock file yet

Alur Kerja Tipikal#

1. lokio init          → setup sekali di awal project
2. lokio doctor        → pastikan setup benar
3. lokio add           → buat template baru
4. Edit .lokio file    → isi dengan struktur kode tim kamu
5. lokio g [template]  → generate berulang kali
6. lokio check         → validasi file sesuai struktur template
7. lokio ai            → validasi standar tim dengan AI
8. lokio sync          → update file lama kalau template berubah

Langkah Selanjutnya#