Skip to content

Commit

Permalink
fix(cli): plugin ios init cmd not generating iOS folder, closes #10661
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Aug 27, 2024
1 parent edb2ca3 commit 84070ba
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 18 deletions.
6 changes: 6 additions & 0 deletions .changes/fix-tauri-plugin-ios-init.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri-cli": patch:bug
"@tauri-apps/cli": patch:bug
---

Fix `tauri plugin ios init` not generating the iOS folder.
20 changes: 7 additions & 13 deletions tooling/cli/src/plugin/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

use super::PluginIosFramework;
use crate::helpers::prompts;
use crate::Result;
use crate::{
helpers::{resolve_tauri_path, template},
VersionMetadata,
};
use anyhow::Context;
use clap::{Parser, ValueEnum};
use clap::Parser;
use handlebars::{to_json, Handlebars};
use heck::{ToKebabCase, ToPascalCase, ToSnakeCase};
use include_dir::{include_dir, Dir};
Expand Down Expand Up @@ -56,15 +57,8 @@ pub struct Options {
pub(crate) mobile: bool,
/// Type of framework to use for the iOS project.
#[clap(long)]
pub(crate) ios_framework: Option<IosFrameworkKind>,
}

#[derive(Debug, Clone, ValueEnum)]
pub enum IosFrameworkKind {
/// Swift Package Manager project
Spm,
/// Xcode project
Xcode,
#[clap(default_value_t = PluginIosFramework::default())]
pub(crate) ios_framework: PluginIosFramework,
}

impl Options {
Expand Down Expand Up @@ -167,7 +161,7 @@ pub fn command(mut options: Options) -> Result<()> {
None
};

let ios_framework = options.ios_framework.unwrap_or(IosFrameworkKind::Spm);
let ios_framework = options.ios_framework;

let mut created_dirs = Vec::new();
template::render_with_generator(
Expand Down Expand Up @@ -208,8 +202,8 @@ pub fn command(mut options: Options) -> Result<()> {
}
}
"ios-spm" | "ios-xcode" if !(options.ios || options.mobile) => return Ok(None),
"ios-spm" if !matches!(ios_framework, IosFrameworkKind::Spm) => return Ok(None),
"ios-xcode" if !matches!(ios_framework, IosFrameworkKind::Xcode) => return Ok(None),
"ios-spm" if !matches!(ios_framework, PluginIosFramework::Spm) => return Ok(None),
"ios-xcode" if !matches!(ios_framework, PluginIosFramework::Xcode) => return Ok(None),
"ios-spm" | "ios-xcode" => {
let folder_name = components.next().unwrap().as_os_str().to_string_lossy();
let new_folder_name = folder_name.replace("{{ plugin_name }}", &plugin_name);
Expand Down
26 changes: 24 additions & 2 deletions tooling/cli/src/plugin/ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

use super::PluginIosFramework;
use crate::{helpers::template, Result};
use clap::{Parser, Subcommand};
use handlebars::Handlebars;

use std::{
collections::BTreeMap,
env::current_dir,
ffi::OsStr,
ffi::{OsStr, OsString},
fs::{create_dir_all, File},
path::{Component, PathBuf},
};
Expand Down Expand Up @@ -42,6 +43,10 @@ pub struct InitOptions {
#[clap(short, long)]
#[clap(default_value_t = current_dir().expect("failed to read cwd").to_string_lossy().into_owned())]
out_dir: String,
/// Type of framework to use for the iOS project.
#[clap(long)]
#[clap(default_value_t = PluginIosFramework::default())]
ios_framework: PluginIosFramework,
}

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

let ios_folder_name = match options.ios_framework {
PluginIosFramework::Spm => OsStr::new("ios-spm"),
PluginIosFramework::Xcode => OsStr::new("ios-xcode"),
};

let mut created_dirs = Vec::new();
template::render_with_generator(
&handlebars,
Expand All @@ -72,7 +82,19 @@ pub fn command(cli: Cli) -> Result<()> {
let mut components = path.components();
let root = components.next().unwrap();
if let Component::Normal(component) = root {
if component == OsStr::new("ios") {
if component == ios_folder_name {
let folder_name = components.next().unwrap().as_os_str().to_string_lossy();
let new_folder_name = folder_name.replace("{{ plugin_name }}", &plugin_name);
let new_folder_name = OsString::from(&new_folder_name);

let path = [
Component::Normal(OsStr::new("ios")),
Component::Normal(&new_folder_name),
]
.into_iter()
.chain(components)
.collect::<PathBuf>();

let path = out_dir.join(path);
let parent = path.parent().unwrap().to_path_buf();
if !created_dirs.contains(&parent) {
Expand Down
22 changes: 20 additions & 2 deletions tooling/cli/src/plugin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

use std::path::Path;
use std::{fmt::Display, path::Path};

use clap::{Parser, Subcommand};
use clap::{Parser, Subcommand, ValueEnum};

use crate::Result;

Expand All @@ -13,6 +13,24 @@ mod init;
mod ios;
mod new;

#[derive(Debug, Clone, ValueEnum, Default)]
pub enum PluginIosFramework {
/// Swift Package Manager project
#[default]
Spm,
/// Xcode project
Xcode,
}

impl Display for PluginIosFramework {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Spm => write!(f, "spm"),
Self::Xcode => write!(f, "xcode"),
}
}
}

#[derive(Parser)]
#[clap(
author,
Expand Down
4 changes: 3 additions & 1 deletion tooling/cli/src/plugin/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

use super::PluginIosFramework;
use crate::Result;
use clap::Parser;
use std::path::PathBuf;
Expand Down Expand Up @@ -37,7 +38,8 @@ pub struct Options {
mobile: bool,
/// Type of framework to use for the iOS project.
#[clap(long)]
pub(crate) ios_framework: Option<super::init::IosFrameworkKind>,
#[clap(default_value_t = PluginIosFramework::default())]
pub(crate) ios_framework: PluginIosFramework,
}

impl From<Options> for super::init::Options {
Expand Down

0 comments on commit 84070ba

Please sign in to comment.