Skip to content

Commit 522de0e

Browse files
authored
feat(core): allow a plugin build script to read the plugin config object (#7447)
1 parent aba04fa commit 522de0e

File tree

5 files changed

+43
-0
lines changed

5 files changed

+43
-0
lines changed

.changes/cli-expose-plugin-config.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-cli": patch:feat
3+
"@tauri-apps/cli": patch:feat
4+
---
5+
6+
Expose an environment variable `TAURI_${PLUGIN_NAME}_PLUGIN_CONFIG` for each defined plugin configuration object.

.changes/plugin-config-getter.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-build": patch:feat
3+
---
4+
5+
Added the `config::plugin_config` function to read the plugin configuration set from the CLI.

core/tauri-build/src/config.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
2+
// SPDX-License-Identifier: Apache-2.0
3+
// SPDX-License-Identifier: MIT
4+
5+
use serde::de::DeserializeOwned;
6+
7+
use std::{env::var, io::Cursor};
8+
9+
pub fn plugin_config<T: DeserializeOwned>(name: &str) -> Option<T> {
10+
if let Ok(config_str) = var(format!(
11+
"TAURI_{}_PLUGIN_CONFIG",
12+
name.to_uppercase().replace('-', "_")
13+
)) {
14+
serde_json::from_reader(Cursor::new(config_str))
15+
.map(Some)
16+
.expect("failed to parse configuration")
17+
} else {
18+
None
19+
}
20+
}

core/tauri-build/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ use std::{
3030
mod allowlist;
3131
#[cfg(feature = "codegen")]
3232
mod codegen;
33+
/// Tauri configuration functions.
34+
pub mod config;
3335
/// Mobile build functions.
3436
pub mod mobile;
3537
mod static_vcruntime;

tooling/cli/src/helpers/config.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,16 @@ fn get_internal(merge_config: Option<&str>, reload: bool) -> crate::Result<Confi
175175
// revert to previous working directory
176176
set_current_dir(current_dir)?;
177177

178+
for (plugin, conf) in &config.plugins.0 {
179+
set_var(
180+
format!(
181+
"TAURI_{}_PLUGIN_CONFIG",
182+
plugin.to_uppercase().replace('-', "_")
183+
),
184+
serde_json::to_string(&conf)?,
185+
);
186+
}
187+
178188
*config_handle().lock().unwrap() = Some(ConfigMetadata {
179189
inner: config,
180190
extensions,

0 commit comments

Comments
 (0)