sarif-explorer
Version:
A modern SARIF report viewer that converts SARIF files into interactive, shareable HTML reports with file explorer, collapsible issue lists, and code snippets.
60 lines • 1.7 kB
JavaScript
import fs from 'fs/promises';
import path from 'path';
/**
* Load artifact content from file system
*/
export async function loadArtifactContent(artifactUri, sourceDir) {
try {
// Resolve the artifact path relative to the source directory
const resolvedPath = path.resolve(sourceDir, artifactUri);
// Check if file exists
try {
await fs.access(resolvedPath);
}
catch {
return {
success: false,
error: `File not found: ${resolvedPath}`,
filePath: resolvedPath
};
}
// Read file content
const content = await fs.readFile(resolvedPath, 'utf8');
return {
success: true,
content,
filePath: resolvedPath
};
}
catch (error) {
return {
success: false,
error: error instanceof Error ? error.message : 'Unknown error reading file',
filePath: path.resolve(sourceDir, artifactUri)
};
}
}
/**
* Load multiple artifacts and return a map of URI to content
*/
export async function loadArtifactsFromDirectory(artifactUris, sourceDir) {
const results = new Map();
for (const uri of artifactUris) {
const result = await loadArtifactContent(uri, sourceDir);
results.set(uri, result);
}
return results;
}
/**
* Validate source directory exists and is readable
*/
export async function validateSourceDirectory(sourceDir) {
try {
const stats = await fs.stat(sourceDir);
return stats.isDirectory();
}
catch {
return false;
}
}
//# sourceMappingURL=artifact-loader.js.map