tauri.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/env node
  2. const cmds = ['help', 'icon', 'deps']
  3. const rustCliCmds = ['dev', 'build', 'init', 'info']
  4. const cmd = process.argv[2]
  5. /**
  6. * @description This is the bootstrapper that in turn calls subsequent
  7. * Tauri Commands
  8. *
  9. * @param {string|array} command
  10. */
  11. const tauri = function (command) {
  12. if (typeof command === 'object') {
  13. // technically we just care about an array
  14. command = command[0]
  15. }
  16. if (rustCliCmds.includes(command)) {
  17. const { runOnRustCli } = require('../dist/helpers/rust-cli')
  18. if (process.argv && !process.env.test) {
  19. process.argv.splice(0, 3)
  20. }
  21. runOnRustCli(command, process.argv || []).promise.then(() => {
  22. if (command === 'init') {
  23. const {
  24. installDependencies
  25. } = require('../dist/api/dependency-manager')
  26. return installDependencies()
  27. }
  28. })
  29. return
  30. }
  31. if (
  32. !command ||
  33. command === '-h' ||
  34. command === '--help' ||
  35. command === 'help'
  36. ) {
  37. console.log(`
  38. Description
  39. This is the Tauri CLI.
  40. Usage
  41. $ tauri ${[...cmds, ...rustCliCmds].join('|')}
  42. Options
  43. --help, -h Displays this message
  44. --version, -v Displays the Tauri CLI version
  45. `)
  46. process.exit(0)
  47. // eslint-disable-next-line no-unreachable
  48. return false // do this for node consumers and tests
  49. }
  50. if (command === '-v' || command === '--version') {
  51. console.log(require('../package.json').version)
  52. return false // do this for node consumers and tests
  53. }
  54. if (cmds.includes(command)) {
  55. if (process.argv && !process.env.test) {
  56. process.argv.splice(2, 1)
  57. }
  58. console.log(`[tauri]: running ${command}`)
  59. // eslint-disable-next-line security/detect-non-literal-require
  60. require(`./tauri-${command}`)
  61. } else {
  62. console.log(`Invalid command ${command}. Use one of ${cmds.join(', ')}.`)
  63. }
  64. }
  65. module.exports = {
  66. tauri
  67. }
  68. tauri(cmd)