-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathgenerate-cert-data.cjs
More file actions
68 lines (54 loc) · 1.93 KB
/
Copy pathgenerate-cert-data.cjs
File metadata and controls
68 lines (54 loc) · 1.93 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* Generate Cert Data JSON
*
* Extracts all SFC certification section/control data from MDX frontmatter
* and writes a JSON file for use by the ExportAllCerts component.
*
* Usage: node utils/generate-cert-data.js
*/
const fs = require('fs');
const path = require('path');
const matter = require('gray-matter');
const CERTS_DIR = path.join(__dirname, '../docs/pages/certs');
const OUTPUT_PATH = path.join(__dirname, '../public/cert-data.json');
const CERT_ORDER = [
{ file: 'sfc-devops-infrastructure.mdx', label: 'DevOps & Infrastructure' },
{ file: 'sfc-dns-registrar.mdx', label: 'DNS Registrar' },
{ file: 'sfc-identity-accounts.mdx', label: 'Identity & Accounts' },
{ file: 'sfc-incident-response.mdx', label: 'Incident Response' },
{ file: 'sfc-multisig-ops.mdx', label: 'Multisig Operations' },
{ file: 'sfc-treasury-ops.mdx', label: 'Treasury Operations' },
];
function main() {
const certs = [];
for (const { file, label } of CERT_ORDER) {
const filePath = path.join(CERTS_DIR, file);
if (!fs.existsSync(filePath)) {
console.log(` Skipping ${file} - not found`);
continue;
}
const content = fs.readFileSync(filePath, 'utf8');
const { data } = matter(content);
if (!data.cert || !Array.isArray(data.cert)) {
console.log(` Skipping ${file} - no cert data`);
continue;
}
const name = file.replace('.mdx', '');
certs.push({
name,
label,
sections: data.cert,
});
}
// Ensure output directory exists
const outputDir = path.dirname(OUTPUT_PATH);
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
fs.writeFileSync(OUTPUT_PATH, JSON.stringify(certs, null, 2));
const totalControls = certs.reduce((sum, c) =>
sum + c.sections.reduce((s, sec) => s + (sec.controls?.length || 0), 0), 0
);
console.log(`✅ Generated cert-data.json (${certs.length} certs, ${totalControls} total controls)`);
}
main();