bin.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env node
  2. /**
  3. * Command-line entry for dsh.
  4. * @module @deepseek-ai/dsh/bin
  5. */
  6. /* v8 ignore file -- built-bin acceptance exercises this self-executing dispatch. */
  7. import { readFileSync } from 'node:fs'
  8. import { fileURLToPath } from 'node:url'
  9. import { loadLayeredEnv } from '@deepseek-ai/dsh-app-boot'
  10. import { parseDshArgs } from './args.ts'
  11. // Both the source tree (apps/cli/src) and the bundled bin (apps/cli/lib) sit
  12. // one directory under apps/cli, so the checked-in manifest resolves with the
  13. // same relative hop from either artifact.
  14. function readVersion(): string {
  15. const manifest = JSON.parse(
  16. readFileSync(fileURLToPath(new URL('../package.json', import.meta.url)), 'utf8'),
  17. ) as { version?: unknown }
  18. return typeof manifest.version === 'string' ? manifest.version : '0.0.0'
  19. }
  20. const invocation = parseDshArgs(process.argv.slice(2), readVersion())
  21. switch (invocation.mode) {
  22. case 'profile': {
  23. const { runProfile } = await import('./profile-boot.ts')
  24. await runProfile({
  25. environment: loadLayeredEnv('dsh'),
  26. profile: invocation.profile,
  27. patchFiles: invocation.patches,
  28. args: invocation.args,
  29. })
  30. break
  31. }
  32. case 'plugin': {
  33. const { runPlugin } = await import('./plugin.ts')
  34. process.exit(runPlugin(invocation.profile, invocation.args))
  35. break
  36. }
  37. case 'dump-config': {
  38. const { runDumpConfig } = await import('./dump-config.ts')
  39. runDumpConfig(invocation.profile, invocation.defaultOnly, invocation.patches)
  40. break
  41. }
  42. default:
  43. invocation satisfies never
  44. throw new Error(`dsh: unhandled invocation mode ${JSON.stringify(invocation)}`)
  45. }