Files
route-maps/scripts/parse-maps.js
2026-02-06 23:54:50 +00:00

34 lines
966 B
JavaScript

import yaml from 'js-yaml';
import fs from 'fs';
import path from 'path';
const inputDir = './static/mapFiles/yaml';
const outputDir = './static/mapFiles/json';
const indexFile = './static/map-index.json';
if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true });
const mapList = [];
fs.readdirSync(inputDir).forEach((file) => {
if (file.endsWith('.yaml')) {
const fullPath = path.join(inputDir, file);
const content = yaml.load(fs.readFileSync(fullPath, 'utf8'));
const fileName = file.replace('.yaml', '.json');
fs.writeFileSync(path.join(outputDir, fileName), JSON.stringify(content));
mapList.push({
routeId: content.routeId || null,
routeStart: content.routeStart || null,
routeEnd: content.routeEnd || null,
created: content.created || null,
checked: content.checked || null
});
}
});
fs.writeFileSync(indexFile, JSON.stringify(mapList));
console.log(`Generated ${mapList.length} map files and index.`);