Skip to content

Commit

Permalink
Create dir if not exists
Browse files Browse the repository at this point in the history
  • Loading branch information
cuhland committed Dec 9, 2024
1 parent c6936ab commit 52746b5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Copyright (c) OWASP Foundation. All Rights Reserved.

import { Builders, Enums, Factories, Serialize, Spec, Validation } from '@cyclonedx/cyclonedx-library'
import { Argument, Command, Option } from 'commander'
import { existsSync, openSync } from 'fs'
import { existsSync, mkdirSync, openSync } from 'fs'
import { dirname, resolve } from 'path'

import { loadJsonFile, writeAllSync } from './_helpers'
Expand Down Expand Up @@ -309,10 +309,15 @@ export async function run (process: NodeJS.Process): Promise<number> {
}

myConsole.log('LOG | writing BOM to', options.outputFile)
const directory = dirname(options.outputFile)
if (!existsSync(directory)) {
console.info(directory)
mkdirSync(directory, { recursive: true })
}
const written = await writeAllSync(
options.outputFile === OutputStdOut
? process.stdout.fd
: openSync(resolve(process.cwd(), options.outputFile), 'w'),
: openSync(resolve(options.outputFile), 'w'),
serialized
)
myConsole.info('INFO | wrote %d bytes to %s', written, options.outputFile)
Expand Down

0 comments on commit 52746b5

Please sign in to comment.