Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 10 additions & 4 deletions .config/rollup.dist.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ function moveDtsFilesSync(namePattern, srcPath, destPath) {
}
}

function copyInitGradle() {
const filepath = path.join(rootSrcPath, 'commands', 'manifest', 'init.gradle')
const destPath = path.join(rootDistPath, 'init.gradle')
copyFileSync(filepath, destPath)
}

function removeDtsFilesSync(namePattern, srcPath) {
for (const filepath of tinyGlobSync([`**/${namePattern}.d.ts{.map,}`], {
absolute: true,
Expand All @@ -81,16 +87,15 @@ function updateDepStatsSync(depStats) {
const oldDepStats = existsSync(depStatsPath)
? readJsonSync(depStatsPath)
: undefined
Object.assign(depStats.dependencies, {
Object.assign(depStats.dependencies,
// Add existing package.json dependencies without old transitives. This
// preserves dependencies like '@cyclonedx/cdxgen' and 'synp' that are
// indirectly referenced through spawned processes and not directly imported.
...Object.fromEntries(
Object.fromEntries(
Object.entries(pkgJson.dependencies).filter(
({ 0: key }) => !oldDepStats?.transitives?.[key]
)
)
})
))
// Remove transitives from dependencies.
for (const key of Object.keys(oldDepStats?.transitives ?? {})) {
if (pkgJson.dependencies[key]) {
Expand Down Expand Up @@ -212,6 +217,7 @@ export default () => {
},
writeBundle() {
moveDtsFilesSync(CONSTANTS, distRequirePath, rootDistPath)
copyInitGradle()
removeDtsFilesSync('*', distRequirePath)
updateDepStatsSync(requireConfig.meta.depStats)
}
Expand Down
4 changes: 2 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { cmdFix } from './commands/fix/cmd-fix.ts'
import { cmdInfo } from './commands/info/cmd-info.ts'
import { loginCommand } from './commands/login'
import { logoutCommand } from './commands/logout'
import { manifestCommand } from './commands/manifest'
import { cmdManifest } from './commands/manifest/cmd-manifest.ts'
import { npmCommand } from './commands/npm'
import { npxCommand } from './commands/npx'
import { optimizeCommand } from './commands/optimize'
Expand Down Expand Up @@ -68,7 +68,7 @@ void (async () => {
analytics: cmdAnalytics,
'diff-scan': cmdDiffScan,
'threat-feed': threatFeedCommand,
manifest: manifestCommand
manifest: cmdManifest
},
{
aliases: {
Expand Down
41 changes: 41 additions & 0 deletions src/commands/manifest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Manifest

(At the time of writing...)

## Dev

First build the bundle:

```
npm run build:dist
```

Then run it like these examples:

```
# Scala:
npm exec socket manifest scala -- --bin ~/apps/sbt/bin/sbt ~/socket/repos/scala/akka
# Gradle/Kotlin
npm exec socket manifest yolo -- --cwd ~/socket/repos/kotlin/kotlinx.coroutines
```

And upload with this:

```
npm exec socket scan create -- --repo=depscantmp --branch=mastertmp --tmp --cwd ~/socket/repos/scala/akka socketdev .
npm exec socket scan create -- --repo=depscantmp --branch=mastertmp --tmp --cwd ~/socket/repos/kotlin/kotlinx.coroutines .
```

(The `cwd` option for `create` is necessary because we can't go to the dir and run `npm exec`).

## Prod

User flow look something like this:

```
socket manifest scala .
socket manifest kotlin .
socket manifest yolo

socket scan create --repo=depscantmp --branch=mastertmp --tmp socketdev .
```
78 changes: 0 additions & 78 deletions src/commands/manifest/auto.ts

This file was deleted.

116 changes: 116 additions & 0 deletions src/commands/manifest/cmd-auto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import fs from 'node:fs'
import path from 'node:path'

import meow from 'meow'

import { cmdManifestGradle } from './cmd-gradle.ts'
import { cmdManifestScala } from './cmd-scala.ts'
import { commonFlags } from '../../flags.ts'
import { getFlagListOutput } from '../../utils/output-formatting.ts'

import type { CliCommandConfig } from '../../utils/meow-with-subcommands'

const config: CliCommandConfig = {
commandName: 'auto',
description: 'Auto-detect build and attempt to generate manifest file',
hidden: false,
flags: {
...commonFlags,
cwd: {
type: 'string',
description: 'Set the cwd, defaults to process.cwd()'
},
verbose: {
type: 'boolean',
default: false,
description: 'Enable debug output, may help when running into errors'
}
// TODO: support output flags
},
help: (parentName, config) => `
Usage
$ ${parentName} ${config.commandName}

Options
${getFlagListOutput(config.flags, 6)}

Tries to figure out what language your current repo uses. If it finds a
supported case then it will try to generate the manifest file for that
language with the default or detected settings.
`
}

export const cmdManifestAuto = {
description: config.description,
hidden: config.hidden,
run
}

async function run(
argv: readonly string[],
importMeta: ImportMeta,
{ parentName }: { parentName: string }
): Promise<void> {
const cli = meow(config.help(parentName, config), {
argv,
description: config.description,
importMeta,
flags: config.flags,
allowUnknownFlags: false
})

const verbose = cli.flags['verbose'] ?? false
const cwd = String(cli.flags['cwd']) || false
if (verbose) {
console.group('- ', parentName, config.commandName, ':')
console.group('- flags:', cli.flags)
console.groupEnd()
console.log('- input:', cli.input)
console.log('- cwd:', cwd || process.cwd())
console.groupEnd()
}

const subArgs = []
if (verbose) subArgs.push('--verbose')

const dir = cwd || '.'

if (fs.existsSync(path.join(dir, 'build.sbt'))) {
console.log(
'Detected a Scala sbt build, running default Scala generator...'
)
if (cwd) subArgs.push('--cwd', cwd)
subArgs.push(dir)
await cmdManifestScala.run(subArgs, importMeta, { parentName })
return
}

if (fs.existsSync(path.join(dir, 'gradlew'))) {
console.log('Detected a gradle build, running default gradle generator...')
if (cwd) subArgs.push(cwd) // This command takes the cwd as first arg
await cmdManifestGradle.run(subArgs, importMeta, { parentName })
return
}

// Show new help screen and exit
meow(
`
$ ${parentName} ${config.commandName}

Unfortunately this script did not discover a supported language in the
current folder.

- Make sure this script would work with your target build
- Make sure to run it from the correct folder
- Make sure the necessary build tools are available (\`PATH\`)

If that doesn't work, see \`${parentName} <lang> --help\` for config details for
your target language.
`,
{
argv: [],
description: config.description,
importMeta
}
).showHelp()
}
Loading
Loading