tauri.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env node
  2. const cli = require('./main')
  3. const path = require('path')
  4. const [bin, script, ...arguments] = process.argv
  5. const binStem = path.parse(bin).name.toLowerCase()
  6. // We want to make a helpful binary name for the underlying CLI helper, if we
  7. // can successfully detect what command likely started the execution.
  8. let binName
  9. // deno run -A --unstable --node-modules-dir npm:@tauri-apps/cli
  10. if (bin === '@tauri-apps/cli') {
  11. binName = '@tauri-apps/cli'
  12. }
  13. // Even if started by a package manager, the binary will be NodeJS.
  14. // Some distribution still use "nodejs" as the binary name.
  15. else if (binStem.match(/(nodejs|node)([1-9]*)*$/g)) {
  16. const managerStem = process.env.npm_execpath
  17. ? path.parse(process.env.npm_execpath).name.toLowerCase()
  18. : null
  19. if (managerStem) {
  20. let manager
  21. switch (managerStem) {
  22. // Only supported package manager that has a different filename is npm.
  23. case 'npm-cli':
  24. manager = 'npm'
  25. break
  26. // Yarn and pnpm have the same stem name as their bin.
  27. // We assume all unknown package managers do as well.
  28. default:
  29. manager = managerStem
  30. break
  31. }
  32. binName = `${manager} run ${process.env.npm_lifecycle_event}`
  33. } else {
  34. // Assume running NodeJS if we didn't detect a manager from the env.
  35. // We normalize the path to prevent the script's absolute path being used.
  36. const scriptNormal = path.normalize(path.relative(process.cwd(), script))
  37. binName = `${binStem} ${scriptNormal}`
  38. }
  39. } else {
  40. // We don't know what started it, assume it's already stripped.
  41. arguments.unshift(bin)
  42. }
  43. cli.run(arguments, binName).catch((err) => {
  44. cli.logError(err.message)
  45. process.exit(1)
  46. })