From 813bf24dc5533441963a6fdf46da5845f0d9489c Mon Sep 17 00:00:00 2001 From: Hugo Bernier Date: Sun, 24 Mar 2024 16:24:10 -0400 Subject: [PATCH] Updated javascript to merge --- .github/workflows/merge.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/.github/workflows/merge.js b/.github/workflows/merge.js index 6f269819d..63464548d 100644 --- a/.github/workflows/merge.js +++ b/.github/workflows/merge.js @@ -2,26 +2,33 @@ const fs = require('fs'); const path = require('path'); const _ = require('lodash'); -let result = {}; +// Initialize an empty array to store the merged nodes +let mergedNodes = []; -function getDirectories(path) { - return fs.readdirSync(path, { withFileTypes: true }) +function getDirectories(dirPath) { + return fs.readdirSync(dirPath, { withFileTypes: true }) .filter(dirent => dirent.isDirectory()) .map(dirent => dirent.name); } -let directories = getDirectories('samples'); +const baseDirectory = 'samples'; +const directories = getDirectories(baseDirectory); + directories.forEach(directory => { - let assetsPath = path.join('samples', directory, 'assets'); + const assetsPath = path.join(baseDirectory, directory, 'assets'); if (fs.existsSync(assetsPath)) { - let files = fs.readdirSync(assetsPath); + const files = fs.readdirSync(assetsPath); files.forEach(file => { if (file === 'sample.json') { - let data = JSON.parse(fs.readFileSync(path.join(assetsPath, file))); - result = _.merge(result, data); + const data = JSON.parse(fs.readFileSync(path.join(assetsPath, file), 'utf8')); + // Assuming data is an array of nodes, concatenate it to the mergedNodes array + mergedNodes = mergedNodes.concat(data); } }); } }); -fs.writeFileSync('samples.json', JSON.stringify(result)); \ No newline at end of file +// Write the merged nodes to a new JSON file +fs.writeFileSync('samples.json', JSON.stringify(mergedNodes, null, 2)); + +console.log('Merged nodes saved to samples.json');