tauri.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/usr/bin/env node
  2. // Copyright 2019-2021 Tauri Programme within The Commons Conservancy
  3. // SPDX-License-Identifier: Apache-2.0
  4. // SPDX-License-Identifier: MIT
  5. import chalk from 'chalk'
  6. import updateNotifier from 'update-notifier'
  7. import { createRequire } from 'module'
  8. const require = createRequire(import.meta.url)
  9. const pkg = require('../package.json')
  10. const cmds = ['icon', 'deps']
  11. const rustCliCmds = ['dev', 'build', 'init', 'info', 'sign']
  12. const cmd = process.argv[2]
  13. /**
  14. * @description This is the bootstrapper that in turn calls subsequent
  15. * Tauri Commands
  16. *
  17. * @param {string|array} command
  18. */
  19. const tauri = async function (command) {
  20. // notifying updates.
  21. if (!process.argv.some((arg) => arg === '--no-update-notifier')) {
  22. updateNotifier({
  23. pkg,
  24. updateCheckInterval: 0
  25. }).notify()
  26. }
  27. if (typeof command === 'object') {
  28. // technically we just care about an array
  29. command = command[0]
  30. }
  31. const help =
  32. !command || command === '-h' || command === '--help' || command === 'help'
  33. if (help) {
  34. console.log(`
  35. ${chalk.cyan(`
  36. :oooodddoooo; ;oddl, ,ol, ,oc, ,ldoooooooc, ,oc,
  37. ';;;cxOx:;;;' ;xOxxko' :kx: lkd, :xkl;;;;:okx: lkd,
  38. 'dOo' 'oOd;:xkc :kx: lkd, :xx: ;xkc lkd,
  39. 'dOo' ckx: lkx; :kx: lkd, :xx: :xkc lkd,
  40. 'dOo' ;xkl ,dko' :kx: lkd, :xx:.....xko, lkd,
  41. 'dOo' 'oOd, :xkc :kx: lkd, :xx:,;cokko' lkd,
  42. 'dOo' ckk: lkx; :kx: lkd, :xx: ckkc lkd,
  43. 'dOo' ;xOl lko; :xkl;,....;oOd, :xx: :xkl' lkd,
  44. 'okl' 'kd' 'xx' 'dxxxddddxxo' :dd; ;dxc 'xo'`)}
  45. ${chalk.yellow('Description')}
  46. This is the Tauri CLI
  47. ${chalk.yellow('Usage')}
  48. $ tauri ${[...rustCliCmds, ...cmds].join('|')}
  49. ${chalk.yellow('Options')}
  50. --help, -h Displays this message
  51. --version, -v Displays the Tauri CLI version
  52. `)
  53. process.exit(0)
  54. // eslint-disable-next-line no-unreachable
  55. return false // do this for node consumers and tests
  56. } else if (command === '-v' || command === '--version') {
  57. console.log(`${pkg.version}`)
  58. return false // do this for node consumers and tests
  59. } else if (cmds.includes(command)) {
  60. if (process.argv && process.env.NODE_ENV !== 'test') {
  61. process.argv.splice(2, 1)
  62. }
  63. console.log(`[tauri]: running ${command}`)
  64. await import(`./tauri-${command}.js`)
  65. } else {
  66. const { runOnRustCli } = await import('../dist/helpers/rust-cli.js')
  67. if (process.argv && process.env.NODE_ENV !== 'test') {
  68. process.argv.splice(0, 3)
  69. }
  70. ;(
  71. await runOnRustCli(
  72. command,
  73. (process.argv || []).filter((v) => v !== '--no-update-notifier')
  74. )
  75. ).promise
  76. .then(() => {
  77. if (command === 'init' && !process.argv.some((arg) => arg === '--ci')) {
  78. return import('../dist/api/dependency-manager.js').then(
  79. ({ installDependencies }) => installDependencies()
  80. )
  81. }
  82. })
  83. .catch(() => process.exit(1))
  84. }
  85. }
  86. export default tauri
  87. // on test we use the module.exports
  88. if (process.env.NODE_ENV !== 'test') {
  89. tauri(cmd).catch((e) => {
  90. throw e
  91. })
  92. }