Files
yourpart3/frontend/scripts/merge-ceb-locale-patch.mjs
Torsten Schulz (local) 1ab9407e79
All checks were successful
Deploy to production / deploy (push) Successful in 2m56s
Refactor code structure for improved readability and maintainability; optimize performance across multiple modules.
2026-07-21 09:08:15 +02:00

46 lines
1.5 KiB
JavaScript
Executable File

#!/usr/bin/env node
/**
* Tiefes Zusammenführen eines Patch-Objekts in eine Ceb-Locale-Datei.
* Nutzung: node merge-ceb-locale-patch.mjs <ziel.json> <patch.json>
*/
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 <target.json> <patch.json>');
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);