tauri.js 3.1 KB

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