首页 > 其他分享 >Tauri cli详解

Tauri cli详解

时间:2023-09-01 20:44:52浏览次数:59  
标签:npm tauri cli completions cargo -- Tauri 详解 pnpm

1. 前言

这是一份Tauri cli中文版详细说明文档, 由philoenglish.com团队翻译.
原文位于鹏叔的技术博客空间 - Tauri cli详解, 要获得最近更新及反馈问题请访问原文!

2. info

infor命令用于显示有关Tauri依赖项和项目配置的信息

用法: cargo-tauri info [OPTIONS]


# for npm
npm run tauri info
# for yarn
yarn tauri info
# for pnpm
pnpm tauri info
# for Cargo
cargo tauri info

选项:

      --interactive  交互模式用于自动修复
  -v, --verbose...   开启详细日志
  -h, --help         打印帮助信息
  -V, --version      查询版本号

它可以用来显示了开发环境、Rust、Node.js 及其版本以及一些相关配置的简明信息列表。

当您需要快速概览应用程序时,此命令非常有用。当您请求帮助时,与我们分享此报告可能会很有用。

示例1: 查看项目配置信息


$ npm run tauri info

> [email protected] tauri
> tauri info


[✔] Environment
    - OS: Windows 10.0.22000 X64
    ✔ WebView2: 114.0.1823.51
    ✔ MSVC: Visual Studio Build Tools 2017
    ✔ rustc: 1.68.0 (2c8cc3432 2023-03-06)
    ✔ Cargo: 1.68.0 (115f34552 2023-02-26)
    ✔ rustup: 1.25.2 (17db695f1 2023-02-01)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
    - node: 18.16.1
    - npm: 9.5.1

[-] Packages
    - tauri [RUST]: 1.4.1
    - tauri-build [RUST]: 1.4.0
    - wry [RUST]: 0.24.3
    - tao [RUST]: 0.16.2
    - @tauri-apps/api [NPM]: not installed!
    - @tauri-apps/cli [NPM]: 1.4.0

[-] App
    - build-type: bundle
    - CSP: unset
    - distDir: ../dist/
    - devPath: http://localhost:4200/
    - framework: Angular
    - bundler: Webpack

示例2: 查看版本

$ npm run tauri info -- --version

> [email protected] tauri
> tauri info --version

tauri-cli-info 1.4.0

3. init

初始化Tauri项目

用法: cargo-tauri init [OPTIONS]


# for npm
npm run tauri init
# for yarn
yarn tauri init
# for pnpm
pnpm tauri init
# for Cargo
cargo tauri init

选项:

Options:
      --ci
          跳过输入提示
  -v, --verbose...
          开启详细日志
  -f, --force
          强制覆盖src-tauri文件夹
  -l, --log
          开启日志记录
  -d, --directory <DIRECTORY>
          设置init的目标目录 [默认值: /home/runner/work/tauri-docs/tauri-docs]
  -t, --tauri-path <TAURI_PATH>
          Tauri项目的保存路径(相对于当前工作目录)
  -A, --app-name <APP_NAME>
          Tauri应用程序的名称
  -W, --window-title <WINDOW_TITLE>
          Tauri应用程序的窗口标题
  -D, --dist-dir <DIST_DIR>
          Web资源文件的位置,相对于<project-dir>/src-tauri
  -P, --dev-path <DEV_PATH>
          开发服务器的Url
      --before-dev-command <BEFORE_DEV_COMMAND>
          在“tauri dev”启动之前运行的shell命令
      --before-build-command <BEFORE_BUILD_COMMAND>
          在“tauri build”开始之前运行shell命令
  -h, --help
          在控制台打印帮助信息
  -V, --version
          在控制台打印版本信息

示例: 打印版本信息


$npm run tauri init -- -V

> [email protected] tauri
> tauri init -V

tauri-cli-init 1.4.0

4. plugin init

初始化Tauri插件项目

用法: cargo-tauri plugin init [OPTIONS] --name <PLUGIN_NAME>


# for npm
npm run tauri plugin init
# for yarn
yarn tauri plugin init
# for pnpm
pnpm tauri plugin init
# for cargo
cargo tauri plugin init

选项:


Options:
  -n, --name <PLUGIN_NAME>       Tauri插件的名称
  -v, --verbose...               开启详细日志
      --api                      使用TypeScript API初始化Tauri插件
  -d, --directory <DIRECTORY>    设置init的目标目录 [默认: /home/runner/work/tauri-docs/tauri-docs]
  -t, --tauri-path <TAURI_PATH>  Tauri项目的路径 (相对于当前工作目录)
  -a, --author <AUTHOR>          作者名称
  -h, --help                     打印帮助信息
  -V, --version                  打印版本信息

示例: 打印版本信息

$npm run tauri plugin init -- -V

> [email protected] tauri
> tauri plugin init -V

tauri-cli-plugin-init 1.4.0

5. dev

用法: cargo-tauri dev [OPTIONS] [ARGS]...

# for npm
npm run tauri dev
# for yarn
yarn tauri dev
# for pnpm
pnpm tauri dev
# for cargo
cargo tauri dev

参数和选项:


参数:
  [ARGS]...  传递给运行程序的命令行参数。将“--”之后的参数传递给应用程序

Options:
  -r, --runner <RUNNER>           用于运行应用程序的二进制文件
  -v, --verbose...                开启详细日志
  -t, --target <TARGET>           针对triple目标进行构建 
  -f, --features [<FEATURES>...]  要激活的Cargo功能列表
  -e, --exit-on-panic             panic时退出
  -c, --config <CONFIG>           要与tauri.conf.JSON合并的JSON字符串或JSON文件路径
      --release                   在release模式下运行代码
      --no-watch                  禁用文件监视程序
      --no-dev-server             禁用静态文件的dev server
      --port <PORT>               为静态文件指定开发服务器的端口。默认值为1430也可以使用`TAURI_DEV_SERVER_PORT`环境变量
  -h, --help                      打印帮助信息
  -V, --version                   打印版本信息

此命令将在开发模式下打开WebView。它利用了src-tauri/tauri.conf.json文件中的build.devPath属性。
如果您在build.beforeDevCommand属性中输入了一个命令,那么这个命令将在dev命令之前执行。

TROUBLESHOOTING:
如果您没有使用build.beforeDevCommand,请确保您的build.devPath是正确的,如果使用的是开发服务器,请确保它在使用此命令之前已启动。

6. build

Tauri build

用法: cargo-tauri build [OPTIONS] [ARGS]...


# for npm
npm run tauri build
# for yarn
yarn tauri build
# for pnpm
pnpm tauri build
# for cargo
cargo tauri build

参数和选项:


参数:
  [ARGS]...
          传递给Runner的命令行参数

Options:
  -r, --runner <RUNNER>
          用于构建应用程序的二进制文件,默认为`cargo`

  -v, --verbose...
          开启详细日志

  -d, --debug
          调试标志

  -t, --target <TARGET>
          构建triple目标。
          对于通用macOS应用程序,它必须是“$rustc--print target list”或“universal apple darwin”输出的值之一。
          请注意,编译通用macOS应用程序需要同时安装“aarch64-apple-darwin”和“x86_64-apple-darwin”目标。

  -f, --features [<FEATURES>...]
          空格或逗号分隔的要激活的功能列表

  -b, --bundles [<BUNDLES>...]
          空格或逗号分隔的要打包的bundle列表。
          
          每个bundle必须是MacOS上的“deb”、“appimage”、“msi”、“app”或“dmg”中的一个,以及所有平台上的“updater”。如果指定了“none”,则将跳过绑定程序。
          
          请注意,“updater”bundle不是自动添加的,因此如果启用了updater,则必须指定它。

  -c, --config <CONFIG>
          要与tauri.conf.JSON合并的JSON字符串或JSON文件路径

      --ci
          跳过输入提示

  -h, --help
          打印帮助信息

  -V, --version
          打印版本信息

如果您使用--debug标志,此命令将打包您的应用程序,无论是在生产模式还是调试模式。它利用了src-tauri/tauri.conf.json文件中的build.distDir属性。
如果您在build.beforBuildCommand属性中设置了一个命令,则此命令将在build命令之前执行。

7. icon

为所有主要平台生成各种图标.

Tauri附带了一个基于其标志的默认图标集。当您分发应用程序时,这不是您想要的。为了纠正这种常见的情况,Tauri提供了图标命令,该命令将获取一个输入文件(默认为“./app-icon.png”),并创建各种平台所需的所有图标。

源图像文件要求:

  • png图片
  • 源图像必须为方形, 即长宽比一定要是1:1, 例如都是图片分辨率592*592

用法: cargo-tauri icon [OPTIONS] [INPUT]


# 通过npm调用
npm run tauri icon
# 通过yarn调用
yarn tauri icon
# 通过pnpm调用
pnpm tauri icon
# 通过cargo调用
cargo tauri icon

参数和选项:


Arguments:
  [INPUT]   源图标的路径(png,带透明度的1240x1240px)[默认值:./app icon.png]

Options:
  -o, --output <OUTPUT>  输出目录。默认值:tauri.conf.json文件同级的“icons”目录
  -v, --verbose...       开启详细日志
  -p, --png <PNG>        要生成的自定义PNG图标大小。设置后,不会生成默认图标
  -h, --help             打印帮助信息
  -V, --version          打印版本信息

有关更多信息,请查看完整的Tauri图标指南

8. completions

命令补全

用法: cargo-tauri completions [OPTIONS] --shell \<SHELL>


# 通过npm调用
npm run tauri completions
# 通过yarn调用
yarn tauri completions
# 通过pnpm调用
pnpm tauri completions
# 通过cargo调用
cargo tauri completions

选项:


Options:
  -s, --shell <SHELL>    要为其生成命令补全脚本的Shell类型。[可能的值:bash、elvish、fish、powershell、zsh] 
  -v, --verbose...       开启详细日志
  -o, --output <OUTPUT>  shell命令补全的输出文件。默认情况下,完成打印到控制台.
  -h, --help             打印帮助信息
  -V, --version          打印版本信息

Tauri CLI可以为Bash、Zsh、PowerShell和Fish生成shell补全。
以下是一些配置Bash、Zsh和PowerShell的说明。如果您遇到问题,请按照shell的说明进行操作。请注意,出于安全原因,建议在执行生成的完成脚本之前先进行检查。

8.1. Bash

生成Bash补全并移动到已知文件夹:

用法:


# 通过npm生成
npm run tauri completions -- --shell bash > tauri.sh
mv tauri.sh /usr/local/etc/bash_completion.d/tauri.bash

# 通过yarn生成
yarn tauri completions --shell bash > tauri.sh
mv tauri.sh /usr/local/etc/bash_completion.d/tauri.bash

# 通过pnpm生成
pnpm tauri completions --shell bash > tauri.sh
mv tauri.sh /usr/local/etc/bash_completion.d/tauri.bash


# 通过cargo生成
cargo tauri completions --shell bash > tauri.sh
mv tauri.sh /usr/local/etc/bash_completion.d/tauri.bash

通过在.bashrc中添加以下内容来加载completions脚本:


source /usr/local/etc/bash_completion.d/tauri.bash

8.2. Zsh

生成Zsh补全并移动到已知文件夹:

用法:



# 通过npm生成
npm run tauri completions -- --shell zsh > completions.zsh
mv completions.zsh $HOME/.completions/_tauri


# 通过yarn生成
yarn tauri completions --shell zsh > completions.zsh
mv completions.zsh $HOME/.completions/_tauri


# 通过pnpm生成
pnpm tauri completions --shell zsh > completions.zsh
mv completions.zsh $HOME/.completions/_tauri


# 通过cargo生成
cargo tauri completions --shell zsh > completions.zsh
mv completions.zsh $HOME/.completions/_tauri

使用fpath加载completions文件夹,并将以下内容添加到.zshrc:

fpath=(~/.completions $fpath)
autoload -U compinit

8.3. PowerShell

生成PowerShell补全并将其添加到$profile文件中,以便在所有会话上执行它:


# 通过npm生成
npm run tauri completions -- --shell powershell > ((Split-Path -Path $profile)+"\_tauri.ps1")
Add-Content -Path $profile -Value '& "$PSScriptRoot\_tauri.ps1"'

# 通过yarn生成
yarn tauri completions --shell powershell > ((Split-Path -Path $profile)+"\_tauri.ps1")
Add-Content -Path $profile -Value '& "$PSScriptRoot\_tauri.ps1"'


# 通过pnpm生成
pnpm tauri completions --shell powershell > ((Split-Path -Path $profile)+"\_tauri.ps1")
Add-Content -Path $profile -Value '& "$PSScriptRoot\_tauri.ps1"'


# 通过cargo生成
cargo tauri completions --shell powershell > ((Split-Path -Path $profile)+"\_tauri.ps1")
Add-Content -Path $profile -Value '& "$PSScriptRoot\_tauri.ps1"'

9. version

描述:
获取tauri版本信息

用法:


# 通过npm获取版本信息
npm run tauri -- --version
# 通过yarn获取版本信息
yarn tauri -- --version
# 通过pnpm获取版本信息
pnpm tauri -- --version
# 通过cargo获取版本信息
cargo tauri -- --version

10. 参考文档

Tauri Cli

使用Tauri自带命令生成各平台图标方法,超级简单,只需要一张png图片

标签:npm,tauri,cli,completions,cargo,--,Tauri,详解,pnpm
From: https://www.cnblogs.com/guoapeng/p/17672807.html

相关文章

  • 数据结构与——八大经典排序算法详解
    ......
  • 数据结构与算法——有头无头循环链表详解
    ......
  • JavaScript中exec()方法详解
    一、RegExp对象的声明及exec()方法的使用声明一个RegExp有两种方式:1)varre=newRegExp(pattern,modifiers);2)varre=/pattern/modifiers;注释:pattern(模式):描述了表达式的模式modifiers(修饰符)用于指定全局匹配、区分大小写的匹配和多行匹配,具体有i、g和m三类,这三类也......
  • Epoll详解及源码分析
    1.什么是epollepoll是当前在Linux下开发大规模并发网络程序的热门人选,epoll在Linux2.6内核中正式引入,和select相似,都是I/O多路复用(IOmultiplexing)技术,按照man手册的说法:是为处理大批量句柄而作了改进的poll。Linux下有以下几个经典的服务器模型:①Apache模型(ProcessPerCon......
  • 视频云存储/安防监控/AI视频智能分析网关V3:工服检测功能详解
    在一些工地、后厨、化工、电力等特定的场景中,工服的穿戴是必不可少的。这不仅是安全制度的要求,更能降低工作风险、提高工作效率。TSINGSEE青犀AI边缘计算网关硬件——智能分析网关可以通过实时监测和识别工人的工装穿戴情况,确保他们符合安全要求。只需在施工场地等监控区域内对......
  • 视频云存储/安防监控/视频AI智能分析:消防器材缺失检测功能详解
    在我们的日常生活中,消防器材是必不可少的,无论是在学校、园区还是工厂里,都需要摆放消防器材,做好防范措施,降低安全隐患。但有时也需防备消防器材被人为挪动甚至破坏,在危急时刻无法发挥作用。TSINGSEE青犀AI边缘计算网关硬件——智能分析网关消防器材缺失检测算法就能很好地预防这种情......
  • 软件测试|MySQL唯一约束详解
    简介MySQL唯一约束(UniqueKey)是指所有记录中字段的值不能重复出现。MySQL中的唯一约束是一种用于确保表中某列或多列的取值唯一的数据库约束。唯一约束的作用是防止表中出现重复的值,确保数据的完整性和一致性。在本文中,我们将详细介绍MySQL中唯一约束的定义、用法以及其在数据库设......
  • 软件测试|MySQL 非空约束详解
    简介MySQL中的非空约束(NOTNULLConstraint)是一种用于确保表中某列不允许为空值的数据库约束。非空约束的作用是保证特定列的数据始终包含有效值,防止在插入或更新操作时出现空值,从而维护数据的完整性和一致性。在本文中,我们将详细介绍MySQL中非空约束的定义、用法以及在数据库设计......
  • Spring源码分析(十三)ApplicationContext详解(下)
    前面两篇文章,已经对ApplicationContext的大部分内容做了介绍,包括国际化,Spring中的运行环境,Spring中的资源,Spring中的事件监听机制,还剩唯一一个BeanFactory相关的内容没有介绍,这篇文章就来介绍BeanFactory,这篇文章介绍,关于ApplicationContext相关的内容总算可以告一段落了。本文对应......
  • AtCoder Beginner Contest 292 D - Unicyclic Components
    D-UnicyclicComponents原题链接题意:判断一个连通块的边和点个数是否相同思路:对它使用并查集吧点击查看代码#include<bits/stdc++.h>usingnamespacestd;constintN=200010,M=N<<1;//维护连通图中点和边的个数intsd[N],se[N],p[N];boolf[N];//谁是祖宗int......