tauri.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. if (rustCliCmds.includes(command)) {
  30. const { runOnRustCli } = require('../dist/helpers/rust-cli')
  31. if (process.argv && !process.env.test) {
  32. process.argv.splice(0, 3)
  33. }
  34. ;(
  35. await runOnRustCli(
  36. command,
  37. (process.argv || []).filter((v) => v !== '--no-update-notifier')
  38. )
  39. ).promise.then(() => {
  40. if (command === 'init' && !process.argv.some((arg) => arg === '--ci')) {
  41. const {
  42. installDependencies
  43. } = require('../dist/api/dependency-manager')
  44. return installDependencies()
  45. }
  46. })
  47. } else {
  48. if (
  49. !command ||
  50. command === '-h' ||
  51. command === '--help' ||
  52. command === 'help'
  53. ) {
  54. console.log(`
  55. ${chalk.cyan(`
  56. :oooodddoooo; ;oddl, ,ol, ,oc, ,ldoooooooc, ,oc,
  57. ';;;cxOx:;;;' ;xOxxko' :kx: lkd, :xkl;;;;:okx: lkd,
  58. 'dOo' 'oOd;:xkc :kx: lkd, :xx: ;xkc lkd,
  59. 'dOo' ckx: lkx; :kx: lkd, :xx: :xkc lkd,
  60. 'dOo' ;xkl ,dko' :kx: lkd, :xx:.....xko, lkd,
  61. 'dOo' 'oOd, :xkc :kx: lkd, :xx:,;cokko' lkd,
  62. 'dOo' ckk: lkx; :kx: lkd, :xx: ckkc lkd,
  63. 'dOo' ;xOl lko; :xkl;,....;oOd, :xx: :xkl' lkd,
  64. 'okl' 'kd' 'xx' 'dxxxddddxxo' :dd; ;dxc 'xo'`)}
  65. ${chalk.yellow('Description')}
  66. This is the Tauri CLI
  67. ${chalk.yellow('Usage')}
  68. $ tauri ${[...rustCliCmds, ...cmds].join('|')}
  69. ${chalk.yellow('Options')}
  70. --help, -h Displays this message
  71. --version, -v Displays the Tauri CLI version
  72. `)
  73. process.exit(0)
  74. // eslint-disable-next-line no-unreachable
  75. return false // do this for node consumers and tests
  76. }
  77. if (command === '-v' || command === '--version') {
  78. console.log(`${pkg.version}`)
  79. return false // do this for node consumers and tests
  80. }
  81. if (cmds.includes(command)) {
  82. if (process.argv && !process.env.test) {
  83. process.argv.splice(2, 1)
  84. }
  85. console.log(`[tauri]: running ${command}`)
  86. require(`./tauri-${command}`)
  87. } else {
  88. console.log(`Invalid command ${command}. Use one of ${cmds.join(', ')}.`)
  89. }
  90. }
  91. }
  92. module.exports = {
  93. tauri
  94. }
  95. tauri(cmd).catch((e) => {
  96. throw e
  97. })