Fred Boniface
b10df9b578
All checks were successful
Generate Release / validate_and_release (push) Successful in 18s
41 lines
1.1 KiB
JavaScript
41 lines
1.1 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);
|
|
console.log(mergedYaml)
|
|
} catch(err) {
|
|
console.error('Error merging YAML:', err)
|
|
}
|
|
}
|
|
|
|
sortAndMergeYAMLFiles(); |