Fred Boniface
b4d992414e
All checks were successful
Generate Release / validate_and_release (push) Successful in 12s
Co-authored-by: owlbot <owlbot@owlboard.info> Reviewed-on: #16
66 lines
1.8 KiB
JavaScript
66 lines
1.8 KiB
JavaScript
const fs = require('fs')
|
|
const yaml = require('yaml')
|
|
|
|
const directoryPath = './pis/'
|
|
|
|
function sortAndMergeYAMLFiles() {
|
|
try {
|
|
const files = fs.readdirSync(directoryPath);
|
|
|
|
let mergedData = [];
|
|
|
|
files.forEach(file => {
|
|
const data = fs.readFileSync(directoryPath + file, 'utf-8');
|
|
|
|
const parsedData = yaml.parse(data)
|
|
|
|
if (parsedData && typeof parsedData === 'object' && parsedData.pis) {
|
|
mergedData.push(...parsedData.pis)
|
|
} else {
|
|
if (Array.isArray(parsedData)) {
|
|
mergedData.push(...parsedData);
|
|
} else {
|
|
console.error("Incorrect YAML")
|
|
}
|
|
}
|
|
});
|
|
|
|
mergedData.sort((a, b) => {
|
|
const codeA = parseInt(a.code);
|
|
const codeB = parseInt(b.code);
|
|
return codeA - codeB
|
|
})
|
|
|
|
const mergedYaml = yaml.stringify(mergedData);
|
|
|
|
// Construct the output string
|
|
let outputString = "pis:\n";
|
|
mergedData.forEach(item => {
|
|
if (item.stops.length > 0) {
|
|
outputString += ` - code: "${item.code}"\n`;
|
|
outputString += ` stops: [${item.stops.map(stop => `${stop}`).join(',')}]\n`;
|
|
outputString += ` toc: "gw"\n`;
|
|
}
|
|
});
|
|
|
|
try {
|
|
fs.writeFileSync('./pis/gw.yaml', outputString);
|
|
console.log("Overwritten gw.pis")
|
|
} catch (err) {
|
|
console.error("Error writing gw.pis", err)
|
|
}
|
|
|
|
files.forEach(file => {
|
|
if (file.startsWith('dg_parser')) {
|
|
fs.unlinkSync(directoryPath + file);
|
|
console.log(`Deleted file: ${file}`);
|
|
}
|
|
});
|
|
|
|
} catch(err) {
|
|
console.error('Error merging YAML:', err)
|
|
}
|
|
}
|
|
|
|
|
|
sortAndMergeYAMLFiles(); |