|
| 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 | +} |
0 commit comments