Skip to content

Commit

Permalink
provide all errors in one file
Browse files Browse the repository at this point in the history
Signed-off-by: Mirko Mollik <[email protected]>
  • Loading branch information
cre8 committed Oct 7, 2024
1 parent c02bc34 commit ea4f6c9
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions viewer/scripts/link-checker.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// this script checks if all the links in the json files are still reachable
import { readdirSync, readFileSync, writeFileSync, mkdirSync, existsSync, rmSync } from 'fs';
import axios from 'axios';
import { join, dirname } from 'path';
import { join, dirname, basename, extname } from 'path';

let counter = 0;
let validFiles = 0;
let invalidFiles = 0;
const errorLog = {};
const consolidatedErrors = {};

async function isLinkReachable(url, filePath, jsonPath) {
try {
Expand All @@ -27,6 +28,18 @@ async function isLinkReachable(url, filePath, jsonPath) {
errorLog[filePath] = {};
}
errorLog[filePath][jsonPath] = url;

// Add to consolidated errors
const folderName = filePath.split('/')[1];
const fileNameWithoutExt = basename(filePath, extname(filePath));
if (!consolidatedErrors[folderName]) {
consolidatedErrors[folderName] = {};
}
if (!consolidatedErrors[folderName][fileNameWithoutExt]) {
consolidatedErrors[folderName][fileNameWithoutExt] = {};
}
consolidatedErrors[folderName][fileNameWithoutExt][jsonPath] = url;

return false;
}
}
Expand Down Expand Up @@ -60,7 +73,7 @@ async function checkLinksInObject(obj, filePath, currentPath = '') {
}

async function validateFolder(folder) {
if(!existsSync(folder)) {
if (!existsSync(folder)) {
return;
}
const files = readdirSync(folder);
Expand Down Expand Up @@ -104,6 +117,7 @@ const folders = ['case-studies', 'wallets', 'dependencies'];
}

console.log('\nError Log:');
console.log(errorLog);
for (const [filePath, errors] of Object.entries(errorLog)) {
const relativePath = filePath.replace('../', '');
const errorFilePath = join(errorsDir, relativePath);
Expand All @@ -114,4 +128,7 @@ const folders = ['case-studies', 'wallets', 'dependencies'];
}
writeFileSync(errorFilePath, JSON.stringify(errors, null, 2));
}

// Write all errors to a single errors.json file
writeFileSync(join(errorsDir, 'errors.json'), JSON.stringify(consolidatedErrors, null, 2));
})();

0 comments on commit ea4f6c9

Please sign in to comment.