Removed glob dependencies

This commit is contained in:
Hugo Bernier 2024-03-24 14:43:49 -04:00 committed by GitHub
parent dcaac29eb2
commit 78d4f91b0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 9 deletions

View File

@ -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

View File

@ -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));
});
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));