feat(core): add option for custom Xcode project template (XcodeGen) (#10496)

This commit is contained in:
Lucas Fernandes Nogueira 2024-08-07 13:17:01 -03:00 committed by GitHub
parent 02c00abc63
commit 8dc81b6cc2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 40 additions and 1 deletions

View File

@ -0,0 +1,7 @@
---
"tauri-utils": patch:feat
"tauri-cli": patch:feat
"@tauri-apps/cli": patch:feat
---
Added `bundle > ios > template` configuration option for custom Xcode project YML Handlebars template using XcodeGen.

View File

@ -2900,6 +2900,13 @@
"description": "General configuration for the iOS target.",
"type": "object",
"properties": {
"template": {
"description": "A custom [XcodeGen] project.yml template to use.\n\n [XcodeGen]: <https://github.com/yonaskolb/XcodeGen>",
"type": [
"string",
"null"
]
},
"frameworks": {
"description": "A list of strings indicating any iOS frameworks that need to be bundled with the application.\n\n Note that you need to recreate the iOS project for the changes to be applied.",
"type": [

View File

@ -1893,6 +1893,10 @@ pub struct TrayIconConfig {
#[cfg_attr(feature = "schema", derive(JsonSchema))]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct IosConfig {
/// A custom [XcodeGen] project.yml template to use.
///
/// [XcodeGen]: <https://github.com/yonaskolb/XcodeGen>
pub template: Option<PathBuf>,
/// A list of strings indicating any iOS frameworks that need to be bundled with the application.
///
/// Note that you need to recreate the iOS project for the changes to be applied.

View File

@ -2900,6 +2900,13 @@
"description": "General configuration for the iOS target.",
"type": "object",
"properties": {
"template": {
"description": "A custom [XcodeGen] project.yml template to use.\n\n [XcodeGen]: <https://github.com/yonaskolb/XcodeGen>",
"type": [
"string",
"null"
]
},
"frameworks": {
"description": "A list of strings indicating any iOS frameworks that need to be bundled with the application.\n\n Note that you need to recreate the iOS project for the changes to be applied.",
"type": [

View File

@ -221,6 +221,7 @@ pub fn exec(
super::ios::get_config(&app, tauri_config_, None, &Default::default());
map.insert("apple", &config);
super::ios::project::gen(
tauri_config_,
&config,
&metadata,
(handlebars, map),

View File

@ -2,7 +2,10 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
use crate::{helpers::template, Result};
use crate::{
helpers::{config::Config as TauriConfig, template},
Result,
};
use anyhow::Context;
use cargo_mobile2::{
apple::{
@ -27,6 +30,7 @@ const TEMPLATE_DIR: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/templates/mobile
// unprefixed app_root seems pretty dangerous!!
// TODO: figure out what cargo-mobile meant by that
pub fn gen(
tauri_config: &TauriConfig,
config: &Config,
metadata: &Metadata,
(handlebars, mut map): (Handlebars, template::JsonMap),
@ -164,6 +168,15 @@ pub fn gen(
)
.with_context(|| "failed to process template")?;
if let Some(template_path) = tauri_config.bundle.ios.template.as_ref() {
let template = std::fs::read_to_string(template_path)
.context("failed to read custom Xcode project template")?;
let mut output_file = std::fs::File::create(dest.join("project.yml"))?;
handlebars
.render_template_to_write(&template, map.inner(), &mut output_file)
.expect("Failed to render template");
}
let mut dirs_to_create = asset_catalogs.to_vec();
dirs_to_create.push(dest.join(DEFAULT_ASSET_DIR));
dirs_to_create.push(dest.join("Externals"));