Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 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 @@ -315,7 +315,11 @@ export async function run (process: NodeJS.Process): Promise<number> {
}
}
}

const directory = dirname(options.outputFile)
if (!existsSync(directory)) {
Comment thread
jkowalleck marked this conversation as resolved.
myConsole.info('INFO | Creating directory', directory)
mkdirSync(directory, { recursive: true })
}
myConsole.log('LOG | writing BOM to', options.outputFile)
const written = await writeAllSync(
options.outputFile === OutputStdOut
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/cli.args-pass-through.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
*/

const { join } = require('path')
const { mkdirSync, readFileSync } = require('fs')
const { readFileSync } = require('fs')

const { describe, expect, test } = require('@jest/globals')

Expand All @@ -31,7 +31,6 @@ describe('integration.cli.args-pass-through', () => {

describe('npm-version depending npm-args', () => {
const tmpRootRun = join(tmpRoot, 'npmVersion-depending-npmArgs')
mkdirSync(tmpRootRun)

const rMinor = Math.round(99 * Math.random())
const rPatch = Math.round(99 * Math.random())
Expand Down
5 changes: 1 addition & 4 deletions tests/integration/cli.edge-cases.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
*/

const { join } = require('path')
const { mkdirSync, writeFileSync, readFileSync } = require('fs')
const { writeFileSync, readFileSync } = require('fs')

const { describe, expect, test } = require('@jest/globals')

Expand All @@ -32,7 +32,6 @@ describe('integration.cli.edge-cases', () => {

describe('broken project', () => {
const tmpRootRun = join(tmpRoot, 'broken-project')
mkdirSync(tmpRootRun)

test.each([
['no-lockfile', /missing evidence/i],
Expand All @@ -54,7 +53,6 @@ describe('integration.cli.edge-cases', () => {

describe('with broken npm-ls', () => {
const tmpRootRun = join(tmpRoot, 'with-broken')
mkdirSync(tmpRootRun)

test('error on non-existing binary', async () => {
const logFileBase = join(tmpRootRun, 'non-existing')
Expand Down Expand Up @@ -115,7 +113,6 @@ describe('integration.cli.edge-cases', () => {
test('suppressed error on non-zero exit', async () => {
const dd = { subject: 'dev-dependencies', npm: '8', node: '14', os: 'ubuntu-latest' }

mkdirSync(join(tmpRoot, 'suppressed-error-on-non-zero-exit'))
const expectedOutSnap = join(demoResultsRoot, 'suppressed-error-on-non-zero-exit', `${dd.subject}_npm${dd.npm}_node${dd.node}_${dd.os}.snap.json`)
const logFileBase = join(tmpRoot, 'suppressed-error-on-non-zero-exit', `${dd.subject}_npm${dd.npm}_node${dd.node}_${dd.os}`)
const cwd = dummyProjectsRoot
Expand Down
5 changes: 1 addition & 4 deletions tests/integration/cli.from-collected.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
*/

const { join } = require('path')
const { mkdirSync, writeFileSync, readFileSync } = require('fs')
const { writeFileSync, readFileSync } = require('fs')

const { describe, expect, test } = require('@jest/globals')

Expand All @@ -35,7 +35,6 @@ describe('integration.cli.from-collected', () => {
const LATETS_NPM = '10'

const tmpRootRun = join(tmpRoot, 'with-prepared')
mkdirSync(tmpRootRun)

const _allDemoCases = indexNpmLsDemoData()
const useCases = [
Expand All @@ -57,8 +56,6 @@ describe('integration.cli.from-collected', () => {
]

describe.each(useCases)('$subject', (ud) => {
mkdirSync(join(tmpRootRun, ud.subject))

test.each(ud.demoCases)('$subject $args npm$npm node$node $os', async (dd) => {
const expectedOutSnap = join(demoResultsRoot, ud.subject, `${dd.subject}${dd.args}_npm${dd.npm}_node${dd.node}_${dd.os}.snap.json`)
const logFileBase = join(tmpRootRun, ud.subject, `${dd.subject}${dd.args}_npm${dd.npm}_node${dd.node}_${dd.os}`)
Expand Down