import client, { ensureAuthenticated } from '../lib/directus'; import { updateSettings, updateCollection, createItem, updateItem } from '@directus/sdk'; import fs from 'fs'; import path from 'path'; async function optimize() { await ensureAuthenticated(); console.log('🎨 Fixing Branding...'); await client.request(updateSettings({ project_name: 'KLZ Cables', public_note: '

Sustainable Energy.

Industrial Reliability.

', custom_css: 'body { font-family: Inter, sans-serif !important; } .public-view .v-card { border-radius: 20px !important; }' })); console.log('🔧 Fixing List Displays...'); const collections = ['products', 'categories', 'posts', 'pages']; for (const collection of collections) { try { await (client as any).request(updateCollection(collection, { meta: { display_template: '{{translations.name || translations.title}}' } })); } catch (e) { console.error(`Failed to update ${collection}:`, e); } } console.log('🏛️ Force-Syncing Globals...'); const de = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'messages/de.json'), 'utf8')); const en = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'messages/en.json'), 'utf8')); const payload = { id: 1, company_name: 'KLZ Cables GmbH', email: 'info@klz-cables.com', phone: '+49 711 1234567', address: de.Contact.info.address, opening_hours: `${de.Contact.hours.weekdays}: ${de.Contact.hours.weekdaysTime}`, translations: [ { languages_code: 'en-US', tagline: en.Footer.tagline }, { languages_code: 'de-DE', tagline: de.Footer.tagline } ] }; try { await client.request(createItem('globals', payload)); } catch (e) { try { await client.request(updateItem('globals', 1, payload)); } catch (err) { console.error('Globals still failing:', (err as any).message); } } console.log('✅ Optimization complete.'); } optimize().catch(console.error);