Skip to content

Commit ccf21b4

Browse files
authored
Merge pull request #311 from SocketDev/add-sbom
Add `socket manifest <lang>` including scala as first lang
2 parents cda2d91 + 71a86f4 commit ccf21b4

File tree

5 files changed

+411
-0
lines changed

5 files changed

+411
-0
lines changed

Diff for: README.md

+13
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,19 @@ use of the `projectIgnorePaths` to excludes files when creating a report.
8686

8787
## Contributing
8888

89+
### Setup
90+
91+
To run dev locally you can run these steps
92+
93+
```
94+
npm install
95+
npm run build:dist
96+
npm exec socket
97+
```
98+
99+
That should invoke it from local sources. If you make changes you run
100+
`build:dist` again.
101+
89102
### Environment variables for development
90103

91104
- `SOCKET_SECURITY_API_BASE_URL` - if set, this will be the base for all

Diff for: src/commands/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ export * from './dependencies'
1919
export * from './analytics'
2020
export * from './diff-scan'
2121
export * from './threat-feed'
22+
export * from './manifest'

Diff for: src/commands/manifest/auto.ts

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import fs from 'node:fs'
2+
3+
import meow from 'meow'
4+
5+
import { scala } from './scala.ts'
6+
7+
import type { CliSubcommand } from '../../utils/meow-with-subcommands'
8+
9+
const description = 'Auto-detect build and attempt to generate manifest file'
10+
11+
const help = (name: string) => `
12+
Usage
13+
$ ${name}
14+
15+
Tries to figure out what language your current repo uses. If it finds a
16+
supported case then it will try to generate the manifest file for that
17+
language with the default or detected settings.
18+
19+
This command takes no arguments except --verbose.
20+
`
21+
22+
export const auto: CliSubcommand = {
23+
description,
24+
async run(argv, importMeta, { parentName }) {
25+
// Allow `--verbose` to pass through
26+
let verbose = false
27+
const args = argv.filter(arg => {
28+
if (arg === '--verbose') {
29+
verbose = true
30+
return false
31+
}
32+
return true
33+
})
34+
35+
const name = `${parentName} auto`
36+
if (args.length) {
37+
// note: meow will exit if it prints the --help screen
38+
meow(help(name), {
39+
argv: ['--help'],
40+
description,
41+
importMeta
42+
})
43+
}
44+
45+
const subArgs = []
46+
if (verbose) subArgs.push('--verbose', '1')
47+
const scalaDir = '.'
48+
if (fs.existsSync(scalaDir)) {
49+
console.log(
50+
'Detected a Scala sbt build, running default Scala generator...'
51+
)
52+
subArgs.push(scalaDir)
53+
await scala.run(subArgs, importMeta, { parentName })
54+
return
55+
}
56+
57+
// Show new help screen and exit
58+
meow(
59+
`
60+
$ ${name}
61+
62+
Unfortunately this script did not discover a supported language in the
63+
current folder.
64+
65+
- Make sure this script would work with your target build
66+
- Make sure to run it from the correct folder
67+
- Make sure the necessary build tools are available (\`PATH\`)
68+
69+
If that doesn't work, see \`${name} <lang> --help\` for config details
70+
`,
71+
{
72+
argv: ['--help'],
73+
description,
74+
importMeta
75+
}
76+
)
77+
}
78+
}

Diff for: src/commands/manifest/index.ts

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import meow from 'meow'
2+
3+
import { auto } from './auto.ts'
4+
import { scala } from './scala'
5+
import { meowWithSubcommands } from '../../utils/meow-with-subcommands'
6+
7+
import type { CliSubcommand } from '../../utils/meow-with-subcommands'
8+
9+
const description = 'Generate a dependency manifest for given file or dir'
10+
const help = (name: string) => `
11+
Usage
12+
13+
$ ${name} <language> <target>
14+
15+
Generates a declarative dependency manifest (like a package.json for Node.JS
16+
or requirements.txt for PyPi), but for certain supported ecosystems
17+
where it's common to use a dynamic manifest, like Scala's sbt.
18+
19+
Only certain languages are supported and there may be language specific
20+
configurations available. See \`manifest <language> --help\` for usage details
21+
per language.
22+
23+
Currently supported language: scala
24+
25+
Examples
26+
27+
$ ${name} scala .
28+
29+
To have it auto-detect and attempt to run:
30+
31+
$ ${name} yolo
32+
`
33+
34+
export const manifest: CliSubcommand = {
35+
description,
36+
hidden: true,
37+
async run(argv, importMeta, { parentName }) {
38+
const name = `${parentName} manifest`
39+
40+
// Note: this won't catch `socket manifest -xyz --help` sort of cases which
41+
// would fallback to the default meow help behavior. That's fine.
42+
if (argv.length === 0 || argv[0] === '--help') {
43+
meow(help(name), {
44+
argv: ['--help'] as const, // meow will exit() when --help is passed
45+
description,
46+
importMeta
47+
})
48+
}
49+
50+
await meowWithSubcommands(
51+
{
52+
scala,
53+
auto
54+
},
55+
{
56+
argv,
57+
aliases: {
58+
yolo: {
59+
description: auto.description,
60+
hidden: true,
61+
argv: ['auto']
62+
}
63+
},
64+
description,
65+
importMeta,
66+
name
67+
}
68+
)
69+
}
70+
}

0 commit comments

Comments
 (0)