-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
- Loading branch information
1 parent
d1c1644
commit 9807bf2
Showing
8 changed files
with
121 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/*! | ||
This file is part of CycloneDX SBOM plugin for yarn. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
SPDX-License-Identifier: Apache-2.0 | ||
Copyright (c) OWASP Foundation. All Rights Reserved. | ||
*/ | ||
import { readFileSync, writeSync } from 'fs' | ||
|
||
export function loadJsonFile (path: string): any { | ||
return JSON.parse(readFileSync(path, 'utf8')) | ||
// may be replaced by `require(f, { with: { type: "json" } })` | ||
// as soon as this spec is properly implemented. | ||
// see https://github.com/tc39/proposal-import-attributes | ||
} | ||
|
||
export async function writeAllSync (fd: number, data: string): Promise<number> { | ||
const b = Buffer.from(data) | ||
const l = b.byteLength | ||
let w = 0 | ||
while (w < l) { | ||
try { | ||
w += writeSync(fd, b, w) | ||
} catch (error: any) { | ||
if (error.code !== 'EAGAIN') { | ||
throw error | ||
} | ||
await new Promise((resolve) => setTimeout(resolve, 100)) | ||
} | ||
} | ||
return w | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/*! | ||
This file is part of CycloneDX SBOM plugin for yarn. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
SPDX-License-Identifier: Apache-2.0 | ||
Copyright (c) OWASP Foundation. All Rights Reserved. | ||
*/ | ||
|
||
import { type BaseContext } from 'clipanion' | ||
|
||
function noop (): void { | ||
// do nothing | ||
} | ||
|
||
export function makeConsoleLogger (level: number, context: BaseContext): Console { | ||
// all output shall be bound to stdError - stdOut is for result output only | ||
const myConsole = new console.Console(context.stderr, context.stderr) | ||
|
||
if (level < 3) { | ||
myConsole.debug = noop | ||
if (level < 2) { | ||
myConsole.info = noop | ||
if (level < 1) { | ||
myConsole.log = noop | ||
} | ||
} | ||
} | ||
|
||
return myConsole | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters