-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
8,274 additions
and
2,566 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
/coverage | ||
/coverage-ts | ||
/node_modules | ||
/.DS_Store | ||
/.env | ||
/.nyc_output | ||
/.vscode | ||
|
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,171 @@ | ||
import { existsSync, promises as fs } from 'node:fs' | ||
import path from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
|
||
import chalk from 'chalk' | ||
import { $ } from 'execa' | ||
import yargsParse from 'yargs-parser' | ||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url)) | ||
|
||
const toLower = (/** @type {string} */ arg) => arg.toLowerCase() | ||
const arrayToLower = (/** @type {string[]} */ arg) => arg.map(toLower) | ||
|
||
const execaConfig = { | ||
env: { NODE_ENV: '' }, | ||
localDir: path.join(__dirname, 'node_modules'), | ||
} | ||
|
||
const nodejsPlatformTypes = [ | ||
'javascript', | ||
'js', | ||
'nodejs', | ||
'npm', | ||
'pnpm', | ||
'ts', | ||
'tsx', | ||
'typescript' | ||
] | ||
|
||
const yargsConfig = { | ||
configuration: { | ||
'camel-case-expansion': false, | ||
'strip-aliased': true, | ||
'parse-numbers': false, | ||
'populate--': true, | ||
}, | ||
coerce: { | ||
author: arrayToLower, | ||
filter: arrayToLower, | ||
only: arrayToLower, | ||
profile: toLower, | ||
standard: arrayToLower, | ||
type: toLower | ||
}, | ||
default: { | ||
profile: 'generic', | ||
type: 'js', | ||
validate: true, | ||
}, | ||
alias: { | ||
help: ['h'], | ||
output: ['o'], | ||
print: ['p'], | ||
recurse: ['r'], | ||
'resolve-class': ['c'], | ||
type: ['t'], | ||
version: ['v'], | ||
}, | ||
array: [ | ||
{ key: 'author', type: 'string' }, | ||
{ key: 'exclude', type: 'string' }, | ||
{ key: 'filter', type: 'string' }, | ||
{ key: 'only', type: 'string' }, | ||
{ key: 'standard', type: 'string' } | ||
], | ||
boolean: [ | ||
'auto-compositions', | ||
'babel', | ||
'deep', | ||
'evidence', | ||
'fail-on-error', | ||
'generate-key-and-sign', | ||
'help', | ||
'include-formulation', | ||
'include-crypto', | ||
'install-deps', | ||
'print', | ||
'required-only', | ||
'server', | ||
'validate', | ||
'version', | ||
], | ||
string: [ | ||
'api-key', | ||
'output', | ||
'parent-project-id', | ||
'profile', | ||
'project-group', | ||
'project-name', | ||
'project-version', | ||
'project-id', | ||
'server-host', | ||
'server-port', | ||
'server-url', | ||
'spec-version', | ||
] | ||
} | ||
|
||
/** | ||
* | ||
* @param {{ [key: string]: boolean | null | number | string | (string | number)[]}} argv | ||
* @returns {string[]} | ||
*/ | ||
function argvToArray (/** @type {any} */ argv) { | ||
if (argv['help']) return ['--help'] | ||
const result = [] | ||
for (const { 0: key, 1: value } of Object.entries(argv)) { | ||
if (key === '_' || key === '--') continue | ||
if (key === 'babel' || key === 'install-deps' || key === 'validate') { | ||
result.push(`--${value ? key : `no-${key}`}`) | ||
} else if (value === true) { | ||
result.push(`--${key}`) | ||
} else if (typeof value === 'string') { | ||
result.push(`--${key}=${value}`) | ||
} else if (Array.isArray(value)) { | ||
result.push(`--${key}`, ...value) | ||
} | ||
} | ||
if (argv['--']) { | ||
result.push('--', ...argv['--']) | ||
} | ||
return result | ||
} | ||
|
||
/** @type {import('../../utils/meow-with-subcommands.js').CliSubcommand} */ | ||
export const cyclonedx = { | ||
description: 'Create an SBOM with CycloneDX', | ||
async run (argv_) { | ||
const /** @type {any} */ yargv = { | ||
__proto__: null, | ||
// @ts-ignore | ||
...yargsParse(argv_, yargsConfig) | ||
} | ||
|
||
let cleanupPackageLock = false | ||
if ( | ||
yargv.type !== 'yarn' && | ||
nodejsPlatformTypes.includes(yargv.type) && | ||
existsSync('./yarn.lock') | ||
) { | ||
if (existsSync('./package-lock.json')) { | ||
yargv.type = 'npm' | ||
} else { | ||
// Use synp to convert yarn.lock into package-lock.json for a more | ||
// accurate sbom. | ||
try { | ||
await $(execaConfig)`synp --source-file ./yarn.lock` | ||
yargv.type = 'npm' | ||
cleanupPackageLock = true | ||
} catch {} | ||
} | ||
} | ||
|
||
if (yargv.output === undefined) { | ||
yargv.output = 'socket-cyclonedx.json' | ||
} | ||
|
||
await $({ | ||
...execaConfig, | ||
stdout: 'inherit' | ||
})`cdxgen ${argvToArray(yargv)}` | ||
|
||
if (cleanupPackageLock) { | ||
try { | ||
await fs.unlink('./package-lock.json') | ||
} catch {} | ||
} | ||
// eslint-disable-next-line no-console | ||
console.log(chalk.cyanBright(`${yargv.output} created!`)) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
export * from './cyclonedx/index.js' | ||
export * from './info/index.js' | ||
export * from './report/index.js' | ||
export * from './npm/index.js' | ||
export * from './npx/index.js' | ||
export * from './login/index.js' | ||
export * from './logout/index.js' | ||
export * from './wrapper/index.js' | ||
export * from './npm/index.js' | ||
export * from './npx/index.js' | ||
export * from './raw-npm/index.js' | ||
export * from './raw-npx/index.js' | ||
export * from './report/index.js' | ||
export * from './wrapper/index.js' |
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
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
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
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
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
Oops, something went wrong.