Skip to content

Commit

Permalink
feat(core): add option for custom Xcode project template (XcodeGen) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Aug 7, 2024
1 parent 02c00ab commit 8dc81b6
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .changes/ios-custom-project-template.md
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 7 additions & 0 deletions core/tauri-config-schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
4 changes: 4 additions & 0 deletions core/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions tooling/cli/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
1 change: 1 addition & 0 deletions tooling/cli/src/mobile/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
15 changes: 14 additions & 1 deletion tooling/cli/src/mobile/ios/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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),
Expand Down Expand Up @@ -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"));
Expand Down

0 comments on commit 8dc81b6

Please sign in to comment.