Files
e-tib.com/scripts/fix_map.mjs
Marc Mintel 275a857554
Some checks failed
Build & Deploy / 🔍 Prepare (push) Failing after 4s
Build & Deploy / 🧪 QA (push) Has been skipped
Build & Deploy / 🏗️ Build (push) Has been skipped
Build & Deploy / 🚀 Deploy (push) Has been skipped
Build & Deploy / 🧪 Post-Deploy Verification (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 2s
fix: ui component updates and project formatting
2026-06-17 15:38:56 +02:00

111 lines
3.4 KiB
JavaScript

import fs from 'fs';
import path from 'path';
// 1. Rename Kabeltiefbau to Kabelnetzbau
const filesToReplace = [];
function walkDir(dir) {
if (!fs.existsSync(dir)) return;
const files = fs.readdirSync(dir);
for (const file of files) {
const fullPath = path.join(dir, file);
const stat = fs.statSync(fullPath);
if (stat.isDirectory()) {
if (['node_modules', '.next', '.git'].includes(file)) continue;
walkDir(fullPath);
} else {
if (fullPath.match(/\.(tsx|ts|mdx|json)$/)) {
filesToReplace.push(fullPath);
}
}
}
}
const baseDir = '/Volumes/Alpha SSD/Coding/e-tib.com';
walkDir(path.join(baseDir, 'content'));
walkDir(path.join(baseDir, 'messages'));
walkDir(path.join(baseDir, 'components'));
walkDir(path.join(baseDir, 'app'));
for (const file of filesToReplace) {
let content = fs.readFileSync(file, 'utf-8');
let newContent = content
.replace(/Kabeltiefbau/g, 'Kabelnetzbau')
.replace(/kabeltiefbau/g, 'kabelnetzbau')
.replace(/KABELTIEFBAU/g, 'KABELNETZBAU');
if (content !== newContent) {
fs.writeFileSync(file, newContent, 'utf-8');
console.log(`Replaced in ${file}`);
}
}
// 2. Parse text files and update map-data.ts
const txtDir = '/Users/marcmintel/Downloads/etib';
const txtFiles = ['Orte 2016 - 2022.txt', 'Orte 2023.txt', 'Orte 2024.txt', 'Orte 2025.txt', 'Orte 2026.txt'];
const projectMapping = {}; // plz -> "Typ, PLZ Ort"
for (const tf of txtFiles) {
const content = fs.readFileSync(path.join(txtDir, tf), 'utf-8');
const lines = content.split('\n');
for (let line of lines) {
line = line.trim();
if (!line) continue;
// Extract PLZ
const match = line.match(/\b\d{5}\b/);
if (match) {
const plz = match[0];
projectMapping[plz] = line;
}
}
}
// Read map-data.ts
const mapDataPath = path.join(baseDir, 'lib/map-data.ts');
let mapData = fs.readFileSync(mapDataPath, 'utf-8');
// The objects look like:
// {
// id: 'göhlsdorf-14797',
// name: 'PV-Infrastrukturprojekt, Region Berlin / Brandenburg',
// type: 'minor_node',
// x: 68.78,
// y: 35.98,
// description: 'pv',
// },
// We will use regex to find each block and replace name and type
let updatedMapData = mapData.replace(/id:\s*'([^']+)',\s*name:\s*'([^']+)',\s*type:\s*'([^']+)',/g, (match, id, name, type) => {
// Find PLZ in ID
const plzMatch = id.match(/\d{5}/);
if (plzMatch && projectMapping[plzMatch[0]]) {
const correctName = projectMapping[plzMatch[0]].replace(/'/g, "\\'");
console.log(`Updating ${id} -> ${correctName}`);
return `id: '${id}',\n name: '${correctName}',\n type: 'project',`;
}
// If it's a minor node but no PLZ match, still change to project?
if (type === 'minor_node') {
return `id: '${id}',\n name: '${name}',\n type: 'project',`;
}
return match;
});
// Fix Petershagen coordinates
updatedMapData = updatedMapData.replace(
/id:\s*'petershagen-15326'[\s\S]*?x:\s*[\d.]+,\s*y:\s*[\d.]+/,
(match) => {
return match.replace(/x:\s*[\d.]+,\s*y:\s*[\d.]+/, 'x: 82.5, y: 33.5');
}
);
// Also fix the defaultLocations petershagen if it exists
updatedMapData = updatedMapData.replace(
/id:\s*'petershagen'[\s\S]*?x:\s*36\.26,\s*y:\s*35\.79/,
(match) => {
return match.replace(/x:\s*36\.26,\s*y:\s*35\.79/, 'x: 82.5, y: 33.5');
}
);
fs.writeFileSync(mapDataPath, updatedMapData, 'utf-8');
console.log('map-data.ts updated!');