mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-11-24 04:03:52 +03:00
This commit is contained in:
parent
edb2ca31f7
commit
84070bae92
6
.changes/fix-tauri-plugin-ios-init.md
Normal file
6
.changes/fix-tauri-plugin-ios-init.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
"tauri-cli": patch:bug
|
||||
"@tauri-apps/cli": patch:bug
|
||||
---
|
||||
|
||||
Fix `tauri plugin ios init` not generating the iOS folder.
|
@ -2,6 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use super::PluginIosFramework;
|
||||
use crate::helpers::prompts;
|
||||
use crate::Result;
|
||||
use crate::{
|
||||
@ -9,7 +10,7 @@ use crate::{
|
||||
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};
|
||||
@ -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 {
|
||||
@ -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(
|
||||
@ -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);
|
||||
|
@ -2,6 +2,7 @@
|
||||
// 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;
|
||||
@ -9,7 +10,7 @@ use handlebars::Handlebars;
|
||||
use std::{
|
||||
collections::BTreeMap,
|
||||
env::current_dir,
|
||||
ffi::OsStr,
|
||||
ffi::{OsStr, OsString},
|
||||
fs::{create_dir_all, File},
|
||||
path::{Component, PathBuf},
|
||||
};
|
||||
@ -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<()> {
|
||||
@ -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,
|
||||
@ -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) {
|
||||
|
@ -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;
|
||||
|
||||
@ -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,
|
||||
|
@ -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;
|
||||
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user