diff --git a/.changes/cli-expose-plugin-config.md b/.changes/cli-expose-plugin-config.md new file mode 100644 index 000000000000..2cb4b683cfe2 --- /dev/null +++ b/.changes/cli-expose-plugin-config.md @@ -0,0 +1,6 @@ +--- +"tauri-cli": patch:feat +"@tauri-apps/cli": patch:feat +--- + +Expose an environment variable `TAURI_${PLUGIN_NAME}_PLUGIN_CONFIG` for each defined plugin configuration object. diff --git a/.changes/plugin-config-getter.md b/.changes/plugin-config-getter.md new file mode 100644 index 000000000000..b8e831f4a66c --- /dev/null +++ b/.changes/plugin-config-getter.md @@ -0,0 +1,5 @@ +--- +"tauri-build": patch:feat +--- + +Added the `config::plugin_config` function to read the plugin configuration set from the CLI. diff --git a/core/tauri-build/src/config.rs b/core/tauri-build/src/config.rs new file mode 100644 index 000000000000..2125449e52ed --- /dev/null +++ b/core/tauri-build/src/config.rs @@ -0,0 +1,20 @@ +// Copyright 2019-2023 Tauri Programme within The Commons Conservancy +// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: MIT + +use serde::de::DeserializeOwned; + +use std::{env::var, io::Cursor}; + +pub fn plugin_config(name: &str) -> Option { + if let Ok(config_str) = var(format!( + "TAURI_{}_PLUGIN_CONFIG", + name.to_uppercase().replace('-', "_") + )) { + serde_json::from_reader(Cursor::new(config_str)) + .map(Some) + .expect("failed to parse configuration") + } else { + None + } +} diff --git a/core/tauri-build/src/lib.rs b/core/tauri-build/src/lib.rs index dffd1b60050d..8e46612f429e 100644 --- a/core/tauri-build/src/lib.rs +++ b/core/tauri-build/src/lib.rs @@ -30,6 +30,8 @@ use std::{ mod allowlist; #[cfg(feature = "codegen")] mod codegen; +/// Tauri configuration functions. +pub mod config; /// Mobile build functions. pub mod mobile; mod static_vcruntime; diff --git a/tooling/cli/src/helpers/config.rs b/tooling/cli/src/helpers/config.rs index 035cf3554746..e1a12b65e184 100644 --- a/tooling/cli/src/helpers/config.rs +++ b/tooling/cli/src/helpers/config.rs @@ -175,6 +175,16 @@ fn get_internal(merge_config: Option<&str>, reload: bool) -> crate::Result