Penggunaan CLI
LensCore CLI adalah antarmuka baris perintah yang powerful untuk testing aksesibilitas dan web crawling. Menyediakan alat komprehensif untuk menganalisis website terhadap kepatuhan aksesibilitas, crawl halaman web, dan menghasilkan laporan detail.
Instalasi
LensCore CLI dipublikasikan sebagai paket npm @accesstime/lenscore dan membutuhkan Node.js 20+.
# Instal global (direkomendasikan)
npm install -g @accesstime/lenscore
# Atau jalankan tanpa instal global
npx @accesstime/lenscore --helpSetelah instal global, CLI tersedia di mana saja sebagai perintah lens-core.
Panduan Mulai Cepat
1. Setup LensCore
lens-core setup --port 30092. Build dan Jalankan Services
lens-core build3. Cek Status Service
lens-core status4. Test Satu Halaman
lens-core test https://example.com5. Crawl Website
lens-core crawl https://example.com6. Scan Website Lengkap
lens-core scan https://example.comCatatan
Setelah setup, Anda bisa menjalankan lens-core build (yang build dan start services) atau lens-core up (yang hanya start services). Gunakan lens-core status untuk mengecek apakah services berjalan dengan baik.
Ringkasan Perintah
Setup & Konfigurasi
setup [options]
Setup konfigurasi LensCore dan environment Docker.
# Setup interaktif
lens-core setupOpsi:
--port <port>: Set port API (default: 3001)-u, --url <url>: Set base URL kustom (contoh:http://localhost:3003)--ai: Aktifkan fitur AI saat setup-k, --openai-key <key>: Set OpenAI API key
config [options]
Kelola pengaturan konfigurasi LensCore.
Opsi:
-s, --set <key=value>: Set nilai konfigurasi (contoh: docker.port=3003)-g, --get <key>: Get nilai konfigurasi (contoh: docker.port)-l, --list: Tampilkan semua pengaturan konfigurasi
Contoh:
# Tampilkan semua konfigurasi
lens-core config --list
# Get nilai konfigurasi tertentu
lens-core config --get docker.port
# Set nilai konfigurasi
lens-core config --set "docker.port=3009"
# Set OpenAI API key
lens-core config --set "openai.apiKey=your-key-here"Testing Aksesibilitas
test [options] <url>
Test aksesibilitas satu halaman.
Opsi:
--enable-ai: Aktifkan analisis berbasis AI-k, --openai-key <key>: OpenAI API key-c, --project-context <context>: Konteks proyek (contoh: "react,tailwind")-w, --web: Generate laporan HTML-t, --timeout <ms>: Timeout load halaman (default: 30000)-r, --rules <rules>: Rule spesifik untuk di-test (dipisahkan koma)-g, --tags <tags>: Tag WCAG untuk di-test (contoh: "wcag2a,wcag2aa")--custom-tests <tests>: Custom tests untuk dijalankan (dipisahkan koma, contoh: "responsive")--no-screenshot: Skip capture screenshot--ci: Mode CI: output terformat untuk continuous integration-o, --output <file>: File output untuk laporan JSON (default: report.json saat menggunakan --ci)--no-exit-on-violations: Jangan exit dengan error code saat violations ditemukan (mode CI)--no-show-details: Sembunyikan informasi detail violations (mode CI)--skip-cache: Lewati cache dan paksa test baru
Contoh:
lens-core test https://example.com
lens-core test https://example.com --enable-ai
lens-core test https://example.com --timeout 30000
lens-core test https://example.com --rules "color-contrast,keyboard"
lens-core test https://example.com --project-context "react,tailwind"
lens-core test https://example.com --web
lens-core test https://example.com --no-screenshot
lens-core test https://example.com --custom-tests=responsive --enable-aitest-multiple [options] <urls...>
Test aksesibilitas beberapa halaman secara bersamaan.
Contoh:
lens-core test-multiple https://example.com https://google.com
lens-core test-multiple https://example.com https://google.com --enable-ai
lens-core test-multiple https://example.com https://google.com --webWeb Crawling
crawl [options] <url>
Crawl website dan temukan halaman.
Opsi:
-w, --web: Generate laporan HTML-u, --max-urls <number>: Maksimum URL untuk di-crawl-d, --max-depth <number>: Kedalaman maksimum crawl-t, --timeout <ms>: Timeout load halaman-j, --concurrency <number>: Request bersamaan-l, --wait-until <event>: Tunggu hingga event (load|domcontentloaded|networkidle)--skip-cache: Lewati cache dan paksa crawl baru
Contoh:
lens-core crawl https://example.com
lens-core crawl https://example.com --max-urls 50 --max-depth 3
lens-core crawl https://example.com --concurrency 5
lens-core crawl https://example.com --webscan [options] <url>
Crawl website dan test aksesibilitas (operasi gabungan).
Opsi:
--enable-ai: Aktifkan analisis berbasis AI-k, --openai-key <key>: OpenAI API key-c, --project-context <context>: Konteks proyek (contoh: "react,tailwind")-w, --web: Generate laporan HTML-u, --max-urls <number>: Maksimum URL untuk di-crawl (default: 10)-d, --max-depth <number>: Kedalaman maksimum crawl (default: 2)-t, --timeout <ms>: Timeout request dalam milliseconds (default: 15000)-j, --concurrency <number>: Jumlah request bersamaan (default: 3)--skip-cache: Bypass cache dan paksa scan baru--ci: Mode CI: output terformat untuk continuous integration-o, --output <file>: File output untuk laporan JSON (default: report.json saat menggunakan --ci)--no-exit-on-violations: Jangan exit dengan error code saat violations ditemukan (mode CI)--no-show-details: Sembunyikan informasi detail violations (mode CI)
Contoh:
lens-core scan https://example.com
lens-core scan https://example.com --enable-ai
lens-core scan https://example.com --max-urls 50 --max-depth 3
lens-core scan https://example.com --project-context "react,tailwind"
lens-core scan https://example.com --web
lens-core scan https://example.com --ci
lens-core scan https://example.com --ci --no-exit-on-violations
lens-core scan https://example.com --custom-tests=responsive --enable-ai --max-urls 10Ringkasan opsi:
- Semua opsi
crawl:--max-urls,--max-depth,--timeout,--concurrency,--wait-until,--skip-cache - Semua opsi
test:--enable-ai,--openai-key,--project-context,--web,--timeout,--rules,--tags,--custom-tests,--no-screenshot
Manajemen Docker
build
Build Docker image dan start containers.
lens-core buildup
Start Docker containers (tanpa building).
lens-core updown
Stop dan remove Docker containers.
lens-core downstatus
Cek status Docker container dan API.
lens-core statushealth
Cek API health endpoint.
lens-core healthManajemen Cache
cache:clear
Menghapus semua data cache yang digunakan oleh LensCore (baik in-memory maupun cache eksternal tergantung konfigurasi Anda).
lens-core cache:clearcache:stats
Menampilkan statistik cache seperti hit rate dan ukuran cache.
lens-core cache:statsFormat Output
Output JSON (Default)
lens-core test https://example.comMengembalikan JSON dengan:
- Hasil test
- Pelanggaran
- Passes
- Test incomplete
- Screenshots (base64)
Output Web (Laporan HTML)
lens-core test https://example.com --webGenerate laporan HTML disimpan ke direktori web/output/ dengan:
- Representasi visual
- Deskripsi pelanggaran detail
- Preview screenshot
- Code snippets
- Rekomendasi
Output CI (Continuous Integration)
Flag --ci menyediakan output terformat yang dioptimalkan untuk pipeline CI/CD:
lens-core scan https://example.com --ci
lens-core test https://example.com --ciFitur:
- ✅ Output terformat: Output bersih dan terstruktur untuk log CI
- ✅ Exit code otomatis: Exit code 1 jika violations ditemukan, 0 jika tidak ada
- ✅ Detail violations: Menampilkan detail violations dengan help URL
- ✅ Laporan JSON: Otomatis menyimpan laporan ke
report.json(atau file kustom dengan-o) - ✅ Fallback handling: Otomatis fallback ke test command jika scan gagal
- ✅ Integrasi GitHub Actions: Termasuk anotasi
::error::untuk violations
Opsi Mode CI:
--ci: Aktifkan mode CI dengan output terformat-o, --output <file>: Tentukan file output untuk laporan JSON (default:report.json)--no-exit-on-violations: Jangan gagalkan workflow pada violations (berguna untuk monitoring)--no-show-details: Sembunyikan informasi detail violations (hanya ringkasan)
Contoh Output CI:
==========================================
ACCESSIBILITY VIOLATIONS DETECTED
==========================================
Pages scanned: 3
Total violations: 5
--- Violation Details ---
Page: https://example.com
❌ color-contrast [serious]
Description: Ensures the contrast between foreground and background colors meets WCAG 2 AA contrast ratio thresholds
Help: Elements must have sufficient color contrast
Help URL: https://dequeuniversity.com/rules/axe/4.8/color-contrast
- Element: button.submit-btn
HTML: <button class="submit-btn">Submit</button>
Summary: Element has insufficient color contrast
==========================================
How to fix:
1. Review each violation above
2. Check the Help URL for detailed guidance
3. Fix the issues in your code
4. Re-run the workflow to verify fixes
==========================================
::error::Accessibility violations detected: 5Kasus Penggunaan:
Enforcing Quality (perilaku default):
bashlens-core scan https://example.com --ci # Workflow gagal jika violations ditemukanMonitoring Saja (non-blocking):
bashlens-core scan https://example.com --ci --no-exit-on-violations # Workflow sukses tapi violations dilaporkanFile Output Kustom:
bashlens-core scan https://example.com --ci -o custom-report.json
File Konfigurasi
Konfigurasi LensCore disimpan di ~/.lenscore/config.json:
{
"mode": "local",
"docker": {
"image": "lenscore:latest",
"port": 3001
},
"remote": {
"baseUrl": "http://localhost:3001"
},
"openai": {
"apiKey": "",
"model": "gpt-3.5-turbo",
"enabled": false
},
"project": {
"framework": "",
"cssFramework": "",
"language": "",
"buildTool": ""
}
}Environment Variables
LENSCORE_PORT: Port API serverOPENAI_API_KEY: OpenAI API keyCACHE_TYPE: Tipe cache (memory|redis|none)CACHE_TTL: Time-to-live cache (detik)CACHE_MAX_SIZE: Ukuran maksimum cache
Contoh Penggunaan Real-World
Analisis Website Lengkap
lens-core setup --ai --openai-key your-api-key
lens-core build
lens-core health
lens-core scan https://example.com --max-urls 50 --enable-ai --webBatch Testing
lens-core test-multiple \
https://example.com \
https://example.com/about \
https://example.com/contact \
--enable-ai \
--project-context "react,tailwind" \
--webCrawling Kustom
lens-core crawl https://example.com \
--max-urls 50 \
--max-depth 3 \
--concurrency 5 \
--wait-until networkidle \
--webIntegrasi CI/CD
LensCore menyediakan mode CI khusus untuk integrasi seamless dengan pipeline CI/CD:
Integrasi CI Dasar:
lens-core setup --port 3001
lens-core build
lens-core scan https://example.com --ciContoh GitHub Actions:
- name: Run accessibility scan
run: |
lens-core scan "$SCAN_URL" \
-u 20 \
-d 2 \
-t 10000 \
--skip-cache \
--ci \
-o report.jsonIntegrasi CI Lanjutan:
# Dengan analisis AI
lens-core scan https://example.com --ci --enable-ai
# Non-blocking (monitoring saja)
lens-core scan https://example.com --ci --no-exit-on-violations
# File output kustom
lens-core scan https://example.com --ci -o accessibility-report.json
# Output minimal (tanpa detail)
lens-core scan https://example.com --ci --no-show-detailsIntegrasi Legacy (tanpa --ci):
lens-core setup --port 3001 --ai --openai-key $OPENAI_API_KEY
lens-core build
lens-core health
lens-core test https://example.com > results.jsonAlur CI & Rilis
Bagian ini ditujukan untuk kontributor dan maintainer yang mengerjakan LensCore CLI.
Continuous Integration (GitHub Actions)
Setiap push ke main dan setiap pull request akan menjalankan workflow GitHub Actions berikut:
- Build Check (
.github/workflows/build.yml): menjalankannpm run typecheckdannpm run build - Test Check (
.github/workflows/test.yml): menjalankannpm run testdannpm run test:coverage - Lint Check (
.github/workflows/lint.yml): menjalankannpm run lintdannpm run format:check
Selain itu, workflow Security Check (.github/workflows/security.yml) berjalan terjadwal untuk:
- Menjalankan
npm auditdengan threshold severitas moderate - Menghasilkan laporan dependency yang ketinggalan versi
Deploy Dokumentasi
Dokumentasi dibuild dan dideploy ke GitHub Pages oleh .github/workflows/deploy-docs.yml:
- Terpicu saat push ke
mainyang menyentuhdocs/**,package.json,package-lock.json, atau workflow itu sendiri - Menjalankan
npm cidannpm run docs:build - Mempublikasikan dokumentasi ke GitHub Pages
Merilis Versi CLI Baru ke npm
Rilis paket npm @accesstime/lenscore dipublikasikan secara otomatis ketika GitHub release dibuat. Workflow CI (npm-release.yml) menangani proses publikasi:
- Update versi
- Gunakan
npm version patch|minor|major(disarankan) atau editpackage.jsonsecara manual. - Perintah
npm versionakan mengupdate field versi dan membuat Git tag.
- Gunakan
- Buat GitHub release
- Buat GitHub release baru dengan tag versi tersebut.
- Workflow CI akan secara otomatis mengecek apakah versi sudah ada, build project, dan publish ke npm jika versi baru.
- Verifikasi versi baru
- Instal global di environment bersih:
npm install -g @accesstime/lenscore - Jalankan
lens-core --versionuntuk memastikan versi yang terpasang sama dengan yang dirilis.
- Instal global di environment bersih:
Troubleshooting
Masalah Umum
# Docker tidak berjalan
docker info
lens-core up
# Konflik port
lens-core setup --port 3002
# Masalah permission
ls -la ~/.lenscore/
lens-core config --resetMendapatkan Bantuan
- Gunakan
lens-core --helpuntuk list perintah - Gunakan
lens-core help <command>untuk bantuan perintah spesifik - Cek
lens-core statusuntuk kesehatan service - Review logs di
~/.lenscore/logs/
Penggunaan Lanjutan
Custom Tests
LensCore mendukung custom tests tambahan untuk analisis yang lebih mendalam. Saat ini tersedia:
Responsive Test
Test responsivitas layout website menggunakan AI untuk mendeteksi masalah desain responsif di berbagai ukuran viewport.
Persyaratan:
- Memerlukan
--enable-aiatau--openai-keyuntuk mengaktifkan analisis AI - Menggunakan model OpenAI yang mendukung Vision API (otomatis menggunakan
gpt-4ojika diperlukan)
Cara Menggunakan:
# Test responsivitas satu halaman
lens-core test https://example.com --custom-tests=responsive --enable-ai
# Test responsivitas dengan scan
lens-core scan https://example.com --custom-tests=responsive --enable-ai --max-urls 10
# Dengan web report
lens-core test https://example.com --custom-tests=responsive --enable-ai --webApa yang Dilakukan:
- Mengambil screenshot di berbagai viewport (mobile, tablet, desktop)
- Menganalisis screenshot menggunakan AI untuk mendeteksi masalah responsif
- Menghasilkan laporan dengan screenshot dan rekomendasi perbaikan
Hasil Test:
- Screenshot untuk setiap viewport
- Daftar masalah responsif yang terdeteksi
- Rekomendasi perbaikan untuk setiap masalah
- Status pass/fail untuk setiap viewport
Custom Rules
LensCore mendukung custom rules untuk menambahkan aturan aksesibilitas tambahan. Custom rules dapat berupa Axe-core rules atau Playwright tests.
Approved Rules
LensCore menyediakan set approved rules yang sudah dikurasi dan tersedia secara default:
button-has-accessible-name- Memastikan button punya accessible namelink-has-accessible-name- Memastikan link punya accessible nameheading-order- Memastikan heading punya hierarchy yang logispage-has-heading-one- Memastikan halaman punya heading level 1image-alt-text- Memastikan image punya alt text yang sesuai
Approved rules otomatis dijalankan saat test. Untuk menonaktifkan:
lens-core test https://example.com --no-approved-rulesCustom Rules dari Project
Buat custom rules di project dengan membuat file di salah satu lokasi berikut:
.lenscore/rules/lenscore-rules/.lenscore-rules/
Contoh Axe Rule:
Buat file .lenscore/rules/my-rule.json:
{
"id": "my-custom-rule",
"enabled": true,
"metadata": {
"description": "Custom rule description",
"help": "Help text for the rule"
},
"rule": {
"id": "color-contrast",
"enabled": true,
"tags": ["wcag2aa"]
},
"severity": "serious"
}Contoh Playwright Test:
Buat file .lenscore/rules/my-test.js:
export default {
id: 'my-test',
name: 'My Custom Test',
enabled: true,
severity: 'moderate',
run: async (context) => {
const { page } = context;
const elements = await page.$$eval('button', (buttons) => buttons.length);
return {
id: 'my-test',
name: 'My Custom Test',
passed: elements > 0,
severity: 'moderate',
description:
elements > 0 ? `Found ${elements} buttons` : 'No buttons found',
};
},
};Opsi Custom Rules
# Gunakan custom rules dari path tertentu
lens-core test https://example.com --custom-rules-paths ./my-rules,./team-rules
# Gunakan custom rules dari config file
lens-core test https://example.com --custom-rules-config ./rules-config.json
# Nonaktifkan default rules
lens-core test https://example.com --disable-default-rules color-contrast,keyboard
# Aktifkan specific default rules
lens-core test https://example.com --enable-default-rules color-contrastTest Rule Aksesibilitas Spesifik
lens-core test https://example.com --rules "color-contrast,keyboard"
lens-core test https://example.com --tags "wcag2a,wcag2aa"Tuning Performa
Optimalkan performa crawling:
lens-core scan https://example.com \
--concurrency 5 \
--timeout 30000 \
--max-urls 50 \
--max-depth 3Contoh Integrasi
Integrasi Node.js
const { exec } = require('child_process');
exec('lens-core test https://example.com', (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
return;
}
const results = JSON.parse(stdout);
console.log(`Ditemukan ${results.violations.length} pelanggaran`);
});Integrasi Shell Script
#!/bin/bash
# test-suite.sh
lens-core health || exit 1
lens-core test https://example.com > results.json
if [ $(jq '.violations | length' results.json) -gt 0 ]; then
echo "Pelanggaran aksesibilitas ditemukan!"
exit 1
fiDukungan
- Repository GitHub: https://github.com/Access-Time/LensCore
- Issue Tracker: https://github.com/Access-Time/LensCore/issues
- Dokumentasi: https://accesstime.github.io/LensCore
Untuk informasi lebih lanjut tentang fitur spesifik, lihat:
- Referensi API - Dokumentasi RESTful API
- Panduan Aksesibilitas - Informasi kepatuhan WCAG
- Panduan Kontribusi - Cara berkontribusi ke LensCore
