Files
TSinjex/scripts/fix-coverage-paths.cjs
Max P fc40d7fa83 Update coverage URL to relative path
Changed the coverage URL from an absolute web link to a relative file path to ensure compatibility with local file system references. This facilitates easier navigation and access to the coverage reports in different environments.
2024-08-16 12:11:26 +02:00

47 lines
1.5 KiB
JavaScript

const fs = require('fs');
const path = require('path');
const coverageDir = path.join(__dirname, '..', '.locale', 'coverage');
const typedocUrl = '../../';
const getAllFiles = (dir, files = []) => {
fs.readdirSync(dir).forEach(file => {
const fullPath = path.join(dir, file);
if (fs.statSync(fullPath).isDirectory()) {
getAllFiles(fullPath, files);
} else {
files.push(fullPath);
}
});
return files;
};
// Alle HTML-Dateien im coverage-Ordner finden
const htmlFiles = getAllFiles(coverageDir).filter(file => file.endsWith('.html'));
// Alle HTML-Dateien bearbeiten
htmlFiles.forEach(filePath => {
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error(`Error reading file ${filePath}:`, err);
return;
}
// Relative Pfade anpassen
let fixedData = data.replace(/(src|href)="(?!\.)/g, '$1="./');
// Link zur TypeDoc-Dokumentation hinzufügen
const linkHtml = `<div style="position: fixed; bottom: 10px; right: 10px;"><a href="${typedocUrl}">Zur TypeDoc-Dokumentation</a></div>`;
fixedData = fixedData.replace('</body>', `${linkHtml}</body>`);
fs.writeFile(filePath, fixedData, 'utf8', (err) => {
if (err) {
console.error(`Error writing file ${filePath}:`, err);
return;
}
console.log(`Fixed paths and added link in ${filePath}`);
});
});
});