-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-risk-parser.ts
More file actions
54 lines (45 loc) · 1.85 KB
/
Copy pathdebug-risk-parser.ts
File metadata and controls
54 lines (45 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* Debug script for risk parser
*/
import fs from 'fs'
import path from 'path'
import yaml from 'js-yaml'
console.log('Debugging risk parser...')
// Simulate the exact code from listAllRisks
const risksDir = path.join(__dirname, 'src', 'parser', '..', '..', '..', 'catalogue', 'risks')
console.log('risksDir:', risksDir)
console.log('risksDir exists:', fs.existsSync(risksDir))
if (fs.existsSync(risksDir)) {
const categories = fs.readdirSync(risksDir)
console.log('Categories found:', categories.length)
for (const category of categories) {
const categoryPath = path.join(risksDir, category)
console.log(`Checking category: ${category}`)
console.log(` Path: ${categoryPath}`)
console.log(` Is directory: ${fs.statSync(categoryPath).isDirectory()}`)
if (fs.statSync(categoryPath).isDirectory()) {
const riskFiles = fs.readdirSync(categoryPath).filter(f => f.endsWith('.md'))
console.log(` Found ${riskFiles.length} .md files`)
if (riskFiles.length > 0) {
console.log(` First file: ${riskFiles[0]}`)
// Try to read the first file
try {
const filePath = path.join(category, riskFiles[0])
const content = fs.readFileSync(path.join(categoryPath, riskFiles[0]), 'utf-8')
console.log(` File content length: ${content.length}`)
const frontmatterMatch = content.match(/^---\s*([\s\S]*?)\s*---/)
if (frontmatterMatch) {
console.log(` Frontmatter found`)
const metadata = yaml.load(frontmatterMatch[1]) as any
console.log(` Metadata: ${JSON.stringify(metadata, null, 2)}`)
} else {
console.log(` No frontmatter found`)
}
} catch (error) {
console.error(` Error reading file:`, error)
}
break // Only test first file
}
}
}
}