bin.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env node
  2. /**
  3. * dsh — command-line entry. Dynamic imports per mode keep unrelated modes out
  4. * of each dispatch path; the adapter prints and exits for
  5. * `--help`/`--version`/a parse error, so only a valid mode reaches the switch.
  6. * @module @deepseek-ai/dsh/bin
  7. */
  8. /* v8 ignore file -- built-bin acceptance exercises this self-executing dispatch. */
  9. import { readFileSync } from 'node:fs'
  10. import { fileURLToPath } from 'node:url'
  11. import { loadEnv } from '@deepseek-ai/dsh-app-boot'
  12. import { parseDshArgs } from './args.ts'
  13. // Both the source tree (apps/cli/src) and the bundled bin (apps/cli/lib) sit
  14. // one directory under apps/cli, so the checked-in manifest resolves with the
  15. // same relative hop from either artifact.
  16. /** This app's version, read from its checked-in package.json. */
  17. function readVersion(): string {
  18. const manifest = JSON.parse(
  19. readFileSync(fileURLToPath(new URL('../package.json', import.meta.url)), 'utf8'),
  20. ) as { version?: unknown }
  21. return typeof manifest.version === 'string' ? manifest.version : '0.0.0'
  22. }
  23. loadEnv('dsh')
  24. const invocation = parseDshArgs(process.argv.slice(2), readVersion())
  25. switch (invocation.mode) {
  26. case 'profile': {
  27. const { runProfile } = await import('./profile-boot.ts')
  28. await runProfile({
  29. profile: invocation.profile,
  30. patchFiles: invocation.patches,
  31. ...invocation.task !== undefined && { task: invocation.task },
  32. })
  33. break
  34. }
  35. case 'web': {
  36. const { runWeb } = await import('./web.ts')
  37. await runWeb(invocation)
  38. break
  39. }
  40. case 'plugin': {
  41. const { runPlugin } = await import('./plugin.ts')
  42. process.exit(runPlugin(invocation.profile, invocation.args))
  43. break
  44. }
  45. case 'dump-config': {
  46. const { runDumpConfig } = await import('./dump-config.ts')
  47. runDumpConfig(invocation.profile, invocation.defaultOnly, invocation.patches)
  48. break
  49. }
  50. default:
  51. invocation satisfies never
  52. throw new Error(`dsh: unhandled invocation mode ${JSON.stringify(invocation)}`)
  53. }