import fs from 'node:fs'; import type { Component } from './collector.js'; /** * Write a CycloneDX BOM XML file manually, with basic components and licenses */ export function writeCycloneDX(components: Component[], file: string) { const lines: string[] = []; lines.push(''); lines.push(''); lines.push(' '); for (const c of components) { lines.push(' '); lines.push(` ${c.name}`); lines.push(` ${c.version}`); if (c.licenses) { const licenses = Array.isArray(c.licenses) ? c.licenses : [c.licenses]; lines.push(' '); for (const l of licenses) { lines.push(` ${l}`); } lines.push(' '); } lines.push(' '); } lines.push(' '); lines.push(''); fs.writeFileSync(file, lines.join('\n')); }