tauri.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.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.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.then(() => {
  74. if (command === 'init' && !process.argv.some((arg) => arg === '--ci')) {
  75. const {
  76. installDependencies
  77. } = require('../dist/api/dependency-manager')
  78. return installDependencies()
  79. }
  80. })
  81. }
  82. }
  83. module.exports = {
  84. tauri
  85. }
  86. tauri(cmd).catch((e) => {
  87. throw e
  88. })