#!/usr/bin/env node 'use strict'; const fs = require('fs'); const path = require('path'); const iconMap = { 'sunny': 'sun', 'partly cloudy': 'cloud-sun', 'cloudy': 'cloud', 'foggy': 'cloud-fog', 'drizzle': 'cloud-drizzle', 'rain': 'cloud-rain', 'snow': 'cloud-snow', 'thunderstorm': 'cloud-lightning' }; const wrapAttrs = 'width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"'; function buildSvg(iconName) { const src = path.resolve(__dirname, '..', 'node_modules', 'lucide-static', 'icons', iconName + '.svg'); const raw = fs.readFileSync(src, 'utf8'); const inner = raw .replace(/^[\s\S]*?]*>/, '') .replace(/<\/svg>[\s\S]*$/, '') .replace(/\s+/g, ' ') .trim(); return `${inner}`; } const entries = Object.entries(iconMap); const lines = entries.map(([condition, iconName], i) => { const svg = buildSvg(iconName).replace(/'/g, "\\'"); const pad = ' '.repeat(Math.max(0, 16 - condition.length)); const comma = i < entries.length - 1 ? ',' : ''; return ` '${condition}':${pad}'${svg}'${comma}`; }); const twig = [ '{# Auto-generated by scripts/gen-weather-icons.js — do not edit directly #}', '{% set weather_icons = {', ...lines, '} %}' ].join('\n') + '\n'; const dest = path.resolve(__dirname, '..', 'templates', 'partials', 'weather-icons.html.twig'); fs.writeFileSync(dest, twig); console.log('Generated ' + path.relative(path.resolve(__dirname, '..'), dest));