#!/usr/bin/env node /** * Tiefes Zusammenführen eines Patch-Objekts in eine Ceb-Locale-Datei. * Nutzung: node merge-ceb-locale-patch.mjs */ import fs from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); function isPlainObject(value) { return value !== null && typeof value === 'object' && !Array.isArray(value); } function deepMerge(target, source) { if (!isPlainObject(source)) return target; const base = isPlainObject(target) ? { ...target } : {}; for (const key of Object.keys(source)) { const sv = source[key]; const tv = base[key]; if (isPlainObject(sv) && isPlainObject(tv)) { base[key] = deepMerge(tv, sv); } else if (isPlainObject(sv)) { base[key] = deepMerge({}, sv); } else { base[key] = sv; } } return base; } const targetPath = path.resolve(process.argv[2] || ''); const patchPath = path.resolve(process.argv[3] || ''); if (!targetPath || !patchPath || !fs.existsSync(targetPath) || !fs.existsSync(patchPath)) { console.error('Usage: node merge-ceb-locale-patch.mjs '); process.exit(1); } const base = JSON.parse(fs.readFileSync(targetPath, 'utf8')); const patch = JSON.parse(fs.readFileSync(patchPath, 'utf8')); const merged = deepMerge(base, patch); fs.writeFileSync(targetPath, JSON.stringify(merged, null, 4) + '\n', 'utf8'); console.log('Merged patch into', targetPath);