mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-08-17 03:40:23 +03:00
parent
06833f4fa8
commit
93e0e1392e
6
.changes/cli-add-@-spec.md
Normal file
6
.changes/cli-add-@-spec.md
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"tauri-cli": "minor:feat"
|
||||||
|
"@tauri-apps/cli": "minor:feat"
|
||||||
|
---
|
||||||
|
|
||||||
|
Support specifying a version for `tauri add` subcommand, for example: `tauri add window-state@2.0.0-beta.2`
|
@ -80,18 +80,24 @@ pub struct Options {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn command(options: Options) -> Result<()> {
|
pub fn command(options: Options) -> Result<()> {
|
||||||
let plugin = options.plugin;
|
let (plugin, version) = options
|
||||||
|
.plugin
|
||||||
|
.split_once("@")
|
||||||
|
.map(|(p, v)| (p, Some(v)))
|
||||||
|
.unwrap_or((&options.plugin, None));
|
||||||
|
|
||||||
let plugin_snake_case = plugin.replace('-', "_");
|
let plugin_snake_case = plugin.replace('-', "_");
|
||||||
let crate_name = format!("tauri-plugin-{plugin}");
|
let crate_name = format!("tauri-plugin-{plugin}");
|
||||||
let npm_name = format!("@tauri-apps/plugin-{plugin}");
|
let npm_name = format!("@tauri-apps/plugin-{plugin}");
|
||||||
|
|
||||||
let mut plugins = plugins();
|
let mut plugins = plugins();
|
||||||
let metadata = plugins.remove(plugin.as_str()).unwrap_or_default();
|
let metadata = plugins.remove(plugin).unwrap_or_default();
|
||||||
|
|
||||||
let tauri_dir = tauri_dir();
|
let tauri_dir = tauri_dir();
|
||||||
|
|
||||||
cargo::install_one(cargo::CargoInstallOptions {
|
cargo::install_one(cargo::CargoInstallOptions {
|
||||||
name: &crate_name,
|
name: &crate_name,
|
||||||
|
version,
|
||||||
branch: options.branch.as_deref(),
|
branch: options.branch.as_deref(),
|
||||||
rev: options.rev.as_deref(),
|
rev: options.rev.as_deref(),
|
||||||
tag: options.tag.as_deref(),
|
tag: options.tag.as_deref(),
|
||||||
@ -108,17 +114,20 @@ pub fn command(options: Options) -> Result<()> {
|
|||||||
.map(PackageManager::from_project)
|
.map(PackageManager::from_project)
|
||||||
.and_then(|managers| managers.into_iter().next())
|
.and_then(|managers| managers.into_iter().next())
|
||||||
{
|
{
|
||||||
let npm_spec = match (options.tag, options.rev, options.branch) {
|
let npm_spec = match (version, options.tag, options.rev, options.branch) {
|
||||||
(Some(tag), None, None) => {
|
(Some(version), _, _, _) => {
|
||||||
|
format!("{npm_name}@{version}")
|
||||||
|
}
|
||||||
|
(None, Some(tag), None, None) => {
|
||||||
format!("tauri-apps/tauri-plugin-{plugin}#{tag}")
|
format!("tauri-apps/tauri-plugin-{plugin}#{tag}")
|
||||||
}
|
}
|
||||||
(None, Some(rev), None) => {
|
(None, None, Some(rev), None) => {
|
||||||
format!("tauri-apps/tauri-plugin-{plugin}#{rev}")
|
format!("tauri-apps/tauri-plugin-{plugin}#{rev}")
|
||||||
}
|
}
|
||||||
(None, None, Some(branch)) => {
|
(None, None, None, Some(branch)) => {
|
||||||
format!("tauri-apps/tauri-plugin-{plugin}#{branch}")
|
format!("tauri-apps/tauri-plugin-{plugin}#{branch}")
|
||||||
}
|
}
|
||||||
(None, None, None) => npm_name,
|
(None, None, None, None) => npm_name,
|
||||||
_ => anyhow::bail!("Only one of --tag, --rev and --branch can be specified"),
|
_ => anyhow::bail!("Only one of --tag, --rev and --branch can be specified"),
|
||||||
};
|
};
|
||||||
manager.install(&[npm_spec])?;
|
manager.install(&[npm_spec])?;
|
||||||
|
@ -9,6 +9,7 @@ use anyhow::Context;
|
|||||||
#[derive(Debug, Default, Clone, Copy)]
|
#[derive(Debug, Default, Clone, Copy)]
|
||||||
pub struct CargoInstallOptions<'a> {
|
pub struct CargoInstallOptions<'a> {
|
||||||
pub name: &'a str,
|
pub name: &'a str,
|
||||||
|
pub version: Option<&'a str>,
|
||||||
pub rev: Option<&'a str>,
|
pub rev: Option<&'a str>,
|
||||||
pub tag: Option<&'a str>,
|
pub tag: Option<&'a str>,
|
||||||
pub branch: Option<&'a str>,
|
pub branch: Option<&'a str>,
|
||||||
@ -49,26 +50,32 @@ pub fn install(dependencies: &[String], cwd: Option<&Path>) -> crate::Result<()>
|
|||||||
|
|
||||||
pub fn install_one(options: CargoInstallOptions) -> crate::Result<()> {
|
pub fn install_one(options: CargoInstallOptions) -> crate::Result<()> {
|
||||||
let mut cargo = Command::new("cargo");
|
let mut cargo = Command::new("cargo");
|
||||||
cargo.args(["add", options.name]);
|
cargo.arg("add");
|
||||||
|
|
||||||
if options.tag.is_some() || options.rev.is_some() || options.branch.is_some() {
|
if let Some(version) = options.version {
|
||||||
cargo.args(["--git", "https://github.com/tauri-apps/plugins-workspace"]);
|
cargo.arg(format!("{}@{}", options.name, version));
|
||||||
|
} else {
|
||||||
|
cargo.arg(options.name);
|
||||||
|
|
||||||
|
if options.tag.is_some() || options.rev.is_some() || options.branch.is_some() {
|
||||||
|
cargo.args(["--git", "https://github.com/tauri-apps/plugins-workspace"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
match (options.tag, options.rev, options.branch) {
|
||||||
|
(Some(tag), None, None) => {
|
||||||
|
cargo.args(["--tag", &tag]);
|
||||||
|
}
|
||||||
|
(None, Some(rev), None) => {
|
||||||
|
cargo.args(["--rev", &rev]);
|
||||||
|
}
|
||||||
|
(None, None, Some(branch)) => {
|
||||||
|
cargo.args(["--branch", &branch]);
|
||||||
|
}
|
||||||
|
(None, None, None) => {}
|
||||||
|
_ => anyhow::bail!("Only one of --tag, --rev and --branch can be specified"),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
match (options.tag, options.rev, options.branch) {
|
|
||||||
(Some(tag), None, None) => {
|
|
||||||
cargo.args(["--tag", &tag]);
|
|
||||||
}
|
|
||||||
(None, Some(rev), None) => {
|
|
||||||
cargo.args(["--rev", &rev]);
|
|
||||||
}
|
|
||||||
(None, None, Some(branch)) => {
|
|
||||||
cargo.args(["--branch", &branch]);
|
|
||||||
}
|
|
||||||
(None, None, None) => {}
|
|
||||||
_ => anyhow::bail!("Only one of --tag, --rev and --branch can be specified"),
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(target) = options.target {
|
if let Some(target) = options.target {
|
||||||
cargo.args(["--target", target]);
|
cargo.args(["--target", target]);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user