feat: add QR code generation script for seeded zones
Adds scripts/generate-qr.ts that generates one 400px PNG per warehouse zone into public/qr/ (gitignored). Encodes /report?zone=<token> URL per zone using NEXT_PUBLIC_APP_URL (default http://localhost:3000). Adds public/qr/.gitkeep so the output directory is tracked. All 8 tests pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AWxyMibCuGGtSQSqfajDQ7
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
// scripts/generate-qr.ts
|
||||
import QRCode from 'qrcode'
|
||||
import { mkdirSync } from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
const BASE_URL = process.env.NEXT_PUBLIC_APP_URL ?? 'http://localhost:3000'
|
||||
|
||||
// Matches seeded zone qr_code_token values in 20260709000008_seed.sql
|
||||
const ZONES = [
|
||||
{ token: 'scw1-dock-a-qr-2026', name: 'SCW1 — Dock A' },
|
||||
{ token: 'scw1-cold-storage-qr-2026', name: 'SCW1 — Cold Storage' },
|
||||
{ token: 'scw1-loading-bay-qr-2026', name: 'SCW1 — Loading Bay' },
|
||||
]
|
||||
|
||||
async function main() {
|
||||
const outDir = path.join(process.cwd(), 'public', 'qr')
|
||||
mkdirSync(outDir, { recursive: true })
|
||||
|
||||
for (const zone of ZONES) {
|
||||
const url = `${BASE_URL}/report?zone=${zone.token}`
|
||||
const outputPath = path.join(outDir, `${zone.token}.png`)
|
||||
|
||||
await QRCode.toFile(outputPath, url, {
|
||||
width: 400,
|
||||
margin: 2,
|
||||
color: { dark: '#000000', light: '#FFFFFF' },
|
||||
})
|
||||
|
||||
console.log(`✓ ${zone.name}`)
|
||||
console.log(` → ${url}`)
|
||||
console.log(` → ${outputPath}`)
|
||||
}
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
})
|
||||
Reference in New Issue
Block a user