Skip to content

Commit 84070ba

Browse files
authored
fix(cli): plugin ios init cmd not generating iOS folder, closes #10661 (#10792)
1 parent edb2ca3 commit 84070ba

File tree

5 files changed

+60
-18
lines changed

5 files changed

+60
-18
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-cli": patch:bug
3+
"@tauri-apps/cli": patch:bug
4+
---
5+
6+
Fix `tauri plugin ios init` not generating the iOS folder.

tooling/cli/src/plugin/init.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5+
use super::PluginIosFramework;
56
use crate::helpers::prompts;
67
use crate::Result;
78
use crate::{
89
helpers::{resolve_tauri_path, template},
910
VersionMetadata,
1011
};
1112
use anyhow::Context;
12-
use clap::{Parser, ValueEnum};
13+
use clap::Parser;
1314
use handlebars::{to_json, Handlebars};
1415
use heck::{ToKebabCase, ToPascalCase, ToSnakeCase};
1516
use include_dir::{include_dir, Dir};
@@ -56,15 +57,8 @@ pub struct Options {
5657
pub(crate) mobile: bool,
5758
/// Type of framework to use for the iOS project.
5859
#[clap(long)]
59-
pub(crate) ios_framework: Option<IosFrameworkKind>,
60-
}
61-
62-
#[derive(Debug, Clone, ValueEnum)]
63-
pub enum IosFrameworkKind {
64-
/// Swift Package Manager project
65-
Spm,
66-
/// Xcode project
67-
Xcode,
60+
#[clap(default_value_t = PluginIosFramework::default())]
61+
pub(crate) ios_framework: PluginIosFramework,
6862
}
6963

7064
impl Options {
@@ -167,7 +161,7 @@ pub fn command(mut options: Options) -> Result<()> {
167161
None
168162
};
169163

170-
let ios_framework = options.ios_framework.unwrap_or(IosFrameworkKind::Spm);
164+
let ios_framework = options.ios_framework;
171165

172166
let mut created_dirs = Vec::new();
173167
template::render_with_generator(
@@ -208,8 +202,8 @@ pub fn command(mut options: Options) -> Result<()> {
208202
}
209203
}
210204
"ios-spm" | "ios-xcode" if !(options.ios || options.mobile) => return Ok(None),
211-
"ios-spm" if !matches!(ios_framework, IosFrameworkKind::Spm) => return Ok(None),
212-
"ios-xcode" if !matches!(ios_framework, IosFrameworkKind::Xcode) => return Ok(None),
205+
"ios-spm" if !matches!(ios_framework, PluginIosFramework::Spm) => return Ok(None),
206+
"ios-xcode" if !matches!(ios_framework, PluginIosFramework::Xcode) => return Ok(None),
213207
"ios-spm" | "ios-xcode" => {
214208
let folder_name = components.next().unwrap().as_os_str().to_string_lossy();
215209
let new_folder_name = folder_name.replace("{{ plugin_name }}", &plugin_name);

tooling/cli/src/plugin/ios.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5+
use super::PluginIosFramework;
56
use crate::{helpers::template, Result};
67
use clap::{Parser, Subcommand};
78
use handlebars::Handlebars;
89

910
use std::{
1011
collections::BTreeMap,
1112
env::current_dir,
12-
ffi::OsStr,
13+
ffi::{OsStr, OsString},
1314
fs::{create_dir_all, File},
1415
path::{Component, PathBuf},
1516
};
@@ -42,6 +43,10 @@ pub struct InitOptions {
4243
#[clap(short, long)]
4344
#[clap(default_value_t = current_dir().expect("failed to read cwd").to_string_lossy().into_owned())]
4445
out_dir: String,
46+
/// Type of framework to use for the iOS project.
47+
#[clap(long)]
48+
#[clap(default_value_t = PluginIosFramework::default())]
49+
ios_framework: PluginIosFramework,
4550
}
4651

4752
pub fn command(cli: Cli) -> Result<()> {
@@ -62,6 +67,11 @@ pub fn command(cli: Cli) -> Result<()> {
6267
let mut data = BTreeMap::new();
6368
super::init::plugin_name_data(&mut data, &plugin_name);
6469

70+
let ios_folder_name = match options.ios_framework {
71+
PluginIosFramework::Spm => OsStr::new("ios-spm"),
72+
PluginIosFramework::Xcode => OsStr::new("ios-xcode"),
73+
};
74+
6575
let mut created_dirs = Vec::new();
6676
template::render_with_generator(
6777
&handlebars,
@@ -72,7 +82,19 @@ pub fn command(cli: Cli) -> Result<()> {
7282
let mut components = path.components();
7383
let root = components.next().unwrap();
7484
if let Component::Normal(component) = root {
75-
if component == OsStr::new("ios") {
85+
if component == ios_folder_name {
86+
let folder_name = components.next().unwrap().as_os_str().to_string_lossy();
87+
let new_folder_name = folder_name.replace("{{ plugin_name }}", &plugin_name);
88+
let new_folder_name = OsString::from(&new_folder_name);
89+
90+
let path = [
91+
Component::Normal(OsStr::new("ios")),
92+
Component::Normal(&new_folder_name),
93+
]
94+
.into_iter()
95+
.chain(components)
96+
.collect::<PathBuf>();
97+
7698
let path = out_dir.join(path);
7799
let parent = path.parent().unwrap().to_path_buf();
78100
if !created_dirs.contains(&parent) {

tooling/cli/src/plugin/mod.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5-
use std::path::Path;
5+
use std::{fmt::Display, path::Path};
66

7-
use clap::{Parser, Subcommand};
7+
use clap::{Parser, Subcommand, ValueEnum};
88

99
use crate::Result;
1010

@@ -13,6 +13,24 @@ mod init;
1313
mod ios;
1414
mod new;
1515

16+
#[derive(Debug, Clone, ValueEnum, Default)]
17+
pub enum PluginIosFramework {
18+
/// Swift Package Manager project
19+
#[default]
20+
Spm,
21+
/// Xcode project
22+
Xcode,
23+
}
24+
25+
impl Display for PluginIosFramework {
26+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27+
match self {
28+
Self::Spm => write!(f, "spm"),
29+
Self::Xcode => write!(f, "xcode"),
30+
}
31+
}
32+
}
33+
1634
#[derive(Parser)]
1735
#[clap(
1836
author,

tooling/cli/src/plugin/new.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5+
use super::PluginIosFramework;
56
use crate::Result;
67
use clap::Parser;
78
use std::path::PathBuf;
@@ -37,7 +38,8 @@ pub struct Options {
3738
mobile: bool,
3839
/// Type of framework to use for the iOS project.
3940
#[clap(long)]
40-
pub(crate) ios_framework: Option<super::init::IosFrameworkKind>,
41+
#[clap(default_value_t = PluginIosFramework::default())]
42+
pub(crate) ios_framework: PluginIosFramework,
4143
}
4244

4345
impl From<Options> for super::init::Options {

0 commit comments

Comments
 (0)