From 78d4f91b0f2dc366cba5e57d0d3d23c5f37b7af0 Mon Sep 17 00:00:00 2001 From: Hugo Bernier Date: Sun, 24 Mar 2024 14:43:49 -0400 Subject: [PATCH] Removed glob dependencies --- .github/workflows/merge-json.yml | 2 +- .github/workflows/merge.js | 29 +++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/.github/workflows/merge-json.yml b/.github/workflows/merge-json.yml index a66d047a1..7b16fe2d6 100644 --- a/.github/workflows/merge-json.yml +++ b/.github/workflows/merge-json.yml @@ -27,7 +27,7 @@ jobs: run: wget https://raw.githubusercontent.com/pnp/sp-dev-fx-extensions/main/.metadata/samples.json - name: Install dependencies - run: npm install glob lodash + run: npm install lodash - name: Merge JSON files run: node .github/workflows/merge.js diff --git a/.github/workflows/merge.js b/.github/workflows/merge.js index 2a6b414ba..6f269819d 100644 --- a/.github/workflows/merge.js +++ b/.github/workflows/merge.js @@ -1,14 +1,27 @@ -const glob = require('glob'); const fs = require('fs'); +const path = require('path'); const _ = require('lodash'); let result = {}; -glob("samples/**/assets/sample.json", function (er, files) { - files.forEach(file => { - const data = JSON.parse(fs.readFileSync(file)); - result = _.merge(result, data); - }); +function getDirectories(path) { + return fs.readdirSync(path, { withFileTypes: true }) + .filter(dirent => dirent.isDirectory()) + .map(dirent => dirent.name); +} - fs.writeFileSync('samples.json', JSON.stringify(result)); -}); \ No newline at end of file +let directories = getDirectories('samples'); +directories.forEach(directory => { + let assetsPath = path.join('samples', directory, 'assets'); + if (fs.existsSync(assetsPath)) { + let 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); + } + }); + } +}); + +fs.writeFileSync('samples.json', JSON.stringify(result)); \ No newline at end of file