|
1 | | -import fs from "node:fs"; |
2 | | -import path from "node:path"; |
| 1 | +import fs from 'node:fs'; |
| 2 | +import path from 'node:path'; |
3 | 3 |
|
4 | 4 | export class AIBOMGenerator { |
5 | | - generateAIBOM(modelData: any) { // eslint-disable-line @typescript-eslint/no-explicit-any |
6 | | - const aibom = { |
7 | | - bomFormat: "CycloneDX", |
8 | | - components: [], |
9 | | - dependencies: [], |
10 | | - externalReferences: [], |
11 | | - metadata: { |
12 | | - component: { |
13 | | - name: modelData.name, |
14 | | - version: modelData.version, |
15 | | - type: "machine-learning-model", |
16 | | - description: modelData.description || "No description available", |
17 | | - copyright: modelData.copyright || "NOASSERTION", |
18 | | - // Use string literal for property name with hyphen |
19 | | - "bom-ref": `pkg:huggingface/${modelData.author}/${modelData.name}@${modelData.version}` |
20 | | - }, |
21 | | - properties: [ |
22 | | - { |
23 | | - name: "primaryPurpose", |
24 | | - value: modelData.primaryPurpose || "text-to-speech" |
25 | | - }, |
26 | | - { |
27 | | - name: "suppliedBy", |
28 | | - value: modelData.author |
29 | | - }, |
30 | | - { |
31 | | - name: "licenses", |
32 | | - value: modelData.license || "unknown" |
33 | | - }, |
34 | | - { |
35 | | - name: "downloadLocation", |
36 | | - value: modelData.downloadUrl |
37 | | - } |
38 | | - ] |
39 | | - } |
40 | | - }; |
| 5 | + generateAIBOM(modelData: any) { |
| 6 | + const aibom = { |
| 7 | + bomFormat: 'CycloneDX', |
| 8 | + components: [], |
| 9 | + dependencies: [], |
| 10 | + externalReferences: [], |
| 11 | + metadata: { |
| 12 | + component: { |
| 13 | + name: modelData.name, |
| 14 | + version: modelData.version, |
| 15 | + type: 'machine-learning-model', |
| 16 | + description: modelData.description || 'No description available', |
| 17 | + copyright: modelData.copyright || 'NOASSERTION', |
| 18 | + // Use string literal for property name with hyphen |
| 19 | + 'bom-ref': `pkg:huggingface/${modelData.author}/${modelData.name}@${modelData.version}`, |
| 20 | + }, |
| 21 | + properties: [ |
| 22 | + { |
| 23 | + name: 'primaryPurpose', |
| 24 | + value: modelData.primaryPurpose || 'text-to-speech', |
| 25 | + }, |
| 26 | + { |
| 27 | + name: 'suppliedBy', |
| 28 | + value: modelData.author, |
| 29 | + }, |
| 30 | + { |
| 31 | + name: 'licenses', |
| 32 | + value: modelData.license || 'unknown', |
| 33 | + }, |
| 34 | + { |
| 35 | + name: 'downloadLocation', |
| 36 | + value: modelData.downloadUrl, |
| 37 | + }, |
| 38 | + ], |
| 39 | + }, |
| 40 | + }; |
41 | 41 |
|
42 | | - return aibom; |
43 | | - } |
| 42 | + return aibom; |
| 43 | + } |
44 | 44 |
|
45 | | - saveAIBOM(aibom: any, filePath: string) { // eslint-disable-line @typescript-eslint/no-explicit-any |
46 | | - const dir = path.join(process.cwd(), 'generated_aiboms'); |
47 | | - if (!fs.existsSync(dir)) { |
48 | | - fs.mkdirSync(dir, { recursive: true }); |
49 | | - } |
50 | | - // Replace slashes in filename with underscores to avoid subfolders |
51 | | - const safeFileName = filePath.replace(/[\\/]/g, '_'); |
52 | | - const fullPath = path.join(dir, safeFileName); |
53 | | - fs.writeFileSync(fullPath, JSON.stringify(aibom, null, 2)); |
| 45 | + saveAIBOM(aibom: any, filePath: string) { |
| 46 | + const dir = path.join(process.cwd(), 'generated_aiboms'); |
| 47 | + if (!fs.existsSync(dir)) { |
| 48 | + fs.mkdirSync(dir, { recursive: true }); |
54 | 49 | } |
| 50 | + // Replace slashes in filename with underscores to avoid subfolders |
| 51 | + const safeFileName = filePath.replace(/[\\/]/g, '_'); |
| 52 | + const fullPath = path.join(dir, safeFileName); |
| 53 | + fs.writeFileSync(fullPath, JSON.stringify(aibom, null, 2)); |
| 54 | + } |
55 | 55 | } |
0 commit comments