123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- #!/usr/bin/env node
- // Copyright 2019-2021 Tauri Programme within The Commons Conservancy
- // SPDX-License-Identifier: Apache-2.0
- // SPDX-License-Identifier: MIT
- import chalk from 'chalk'
- import updateNotifier from 'update-notifier'
- import { findUpSync } from 'find-up'
- import { existsSync, readFileSync } from 'fs'
- import { resolve as resolvePath, dirname } from 'path'
- import { createRequire } from 'module'
- const require = createRequire(import.meta.url)
- const pkg = require('../package.json')
- const cmds = ['deps']
- const rustCliCmds = ['dev', 'build', 'init', 'info', 'sign']
- const cmd = process.argv[2]
- /**
- * @description This is the bootstrapper that in turn calls subsequent
- * Tauri Commands
- *
- * @param {string|array} command
- */
- const tauri = async function (command) {
- // notifying updates.
- if (!process.argv.some((arg) => arg === '--no-update-notifier')) {
- updateNotifier({
- pkg,
- updateCheckInterval: 0
- }).notify()
- }
- if (typeof command === 'object') {
- // technically we just care about an array
- command = command[0]
- }
- const help =
- !command || command === '-h' || command === '--help' || command === 'help'
- if (help) {
- console.log(`
- ${chalk.cyan(`
- :oooodddoooo; ;oddl, ,ol, ,oc, ,ldoooooooc, ,oc,
- ';;;cxOx:;;;' ;xOxxko' :kx: lkd, :xkl;;;;:okx: lkd,
- 'dOo' 'oOd;:xkc :kx: lkd, :xx: ;xkc lkd,
- 'dOo' ckx: lkx; :kx: lkd, :xx: :xkc lkd,
- 'dOo' ;xkl ,dko' :kx: lkd, :xx:.....xko, lkd,
- 'dOo' 'oOd, :xkc :kx: lkd, :xx:,;cokko' lkd,
- 'dOo' ckk: lkx; :kx: lkd, :xx: ckkc lkd,
- 'dOo' ;xOl lko; :xkl;,....;oOd, :xx: :xkl' lkd,
- 'okl' 'kd' 'xx' 'dxxxddddxxo' :dd; ;dxc 'xo'`)}
- ${chalk.yellow('Description')}
- This is the Tauri CLI
- ${chalk.yellow('Usage')}
- $ tauri ${[...rustCliCmds, ...cmds].join('|')}
- ${chalk.yellow('Options')}
- --help, -h Displays this message
- --version, -v Displays the Tauri CLI version
- `)
- process.exit(0)
- // eslint-disable-next-line no-unreachable
- return false // do this for node consumers and tests
- } else if (command === '-v' || command === '--version') {
- console.log(`${pkg.version}`)
- return false // do this for node consumers and tests
- } else if (cmds.includes(command)) {
- if (process.argv && process.env.NODE_ENV !== 'test') {
- process.argv.splice(2, 1)
- }
- console.log(`[tauri]: running ${command}`)
- await import(`./tauri-${command}.js`)
- } else {
- const { runOnRustCli } = await import('../dist/helpers/rust-cli.js')
- if (process.argv && process.env.NODE_ENV !== 'test') {
- process.argv.splice(0, 3)
- }
- let cwd = null
- const pkgJsonPath = findUpSync('package.json')
- if (pkgJsonPath) {
- const packageJson = JSON.parse(readFileSync(pkgJsonPath).toString())
- if ('tauri' in packageJson) {
- const { tauri: tauriConfig } = packageJson
- if (tauriConfig.appPath) {
- cwd = resolvePath(dirname(pkgJsonPath), tauriConfig.appPath)
- console.log(cwd)
- if (!existsSync(cwd)) {
- console.error(
- `Configured appPath in package.json '${cwd}' does not exist.`
- )
- process.exit(1)
- }
- }
- }
- }
- ;(
- await runOnRustCli(
- command,
- (process.argv || []).filter((v) => v !== '--no-update-notifier'),
- { cwd }
- )
- ).promise
- .then(() => {
- if (
- command === 'init' &&
- !process.argv.some((arg) => arg === '--ci' || arg === 'plugin')
- ) {
- return import('../dist/api/dependency-manager.js').then(
- ({ installDependencies }) => installDependencies()
- )
- }
- })
- .catch(() => process.exit(1))
- }
- }
- export default tauri
- // on test we use the module.exports
- if (process.env.NODE_ENV !== 'test') {
- tauri(cmd).catch((e) => {
- throw e
- })
- }
|