2024-03-24 14:31:20 -04:00
|
|
|
const fs = require('fs');
|
2024-03-24 14:43:49 -04:00
|
|
|
const path = require('path');
|
2024-03-24 14:31:20 -04:00
|
|
|
const _ = require('lodash');
|
|
|
|
|
2024-03-24 16:24:10 -04:00
|
|
|
// Initialize an empty array to store the merged nodes
|
|
|
|
let mergedNodes = [];
|
2024-03-24 14:31:20 -04:00
|
|
|
|
2024-03-24 16:24:10 -04:00
|
|
|
function getDirectories(dirPath) {
|
|
|
|
return fs.readdirSync(dirPath, { withFileTypes: true })
|
2024-03-24 14:43:49 -04:00
|
|
|
.filter(dirent => dirent.isDirectory())
|
|
|
|
.map(dirent => dirent.name);
|
|
|
|
}
|
2024-03-24 14:31:20 -04:00
|
|
|
|
2024-03-24 16:24:10 -04:00
|
|
|
const baseDirectory = 'samples';
|
|
|
|
const directories = getDirectories(baseDirectory);
|
|
|
|
|
2024-03-24 14:43:49 -04:00
|
|
|
directories.forEach(directory => {
|
2024-03-24 16:24:10 -04:00
|
|
|
const assetsPath = path.join(baseDirectory, directory, 'assets');
|
2024-03-24 14:43:49 -04:00
|
|
|
if (fs.existsSync(assetsPath)) {
|
2024-03-24 16:24:10 -04:00
|
|
|
const files = fs.readdirSync(assetsPath);
|
2024-03-24 14:43:49 -04:00
|
|
|
files.forEach(file => {
|
|
|
|
if (file === 'sample.json') {
|
2024-03-24 16:24:10 -04:00
|
|
|
const data = JSON.parse(fs.readFileSync(path.join(assetsPath, file), 'utf8'));
|
2024-03-24 17:30:15 -04:00
|
|
|
// Assuming data is an array of nodes, merge it into the mergedNodes array
|
|
|
|
Array.prototype.push.apply(mergedNodes, data);
|
|
|
|
// Or using spread operator
|
|
|
|
// mergedNodes.push(...data);
|
2024-03-24 14:43:49 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-03-24 16:24:10 -04:00
|
|
|
// Write the merged nodes to a new JSON file
|
2024-03-24 17:30:15 -04:00
|
|
|
fs.writeFileSync('sample.json', JSON.stringify(mergedNodes, null, 2));
|
2024-03-24 16:24:10 -04:00
|
|
|
|
2024-03-24 17:30:15 -04:00
|
|
|
console.log('Merged nodes saved to samples_merged.json');
|