Skip to content

Commit

Permalink
solved issues with current working directory
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoabernier authored Apr 18, 2024
1 parent 09099bd commit d31616e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions .github/scripts/merge-samples/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const fs = require('fs');
const path = require('path');

const samplesDir = '../../../samples';
const outputDir = '../../../.metadata';
const repoRoot = process.cwd(); // Gets the current working directory
const samplesDir = path.join(repoRoot, 'samples');
const outputDir = path.join(repoRoot, '.metadata');
const outputFile = path.join(outputDir, 'samples.json');

async function readSampleJson(filePath) {
Expand All @@ -16,7 +17,7 @@ async function readSampleJson(filePath) {
resolve(jsonData);
} catch (parseErr) {
console.error(`Invalid JSON in ${filePath}`);
resolve(null); // Return null if JSON is invalid
resolve(null); // Return null if JSON is invalid
}
}
});
Expand All @@ -33,7 +34,9 @@ async function mergeSamples() {
const samplePath = path.join(samplesDir, dir.name, 'assets', 'sample.json');
if (fs.existsSync(samplePath)) {
const sampleData = await readSampleJson(samplePath);
samples = samples.concat(sampleData);
if (sampleData) { // Check if the data is not null (valid JSON)
samples = samples.concat(sampleData);
}
}
}
}
Expand Down

0 comments on commit d31616e

Please sign in to comment.