tauri.js 3.0 KB

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