From 522de0e78891d0bdf6387a5118985fc41a11baeb Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Tue, 18 Jul 2023 07:04:15 -0700 Subject: [PATCH] feat(core): allow a plugin build script to read the plugin config object (#7447) --- .changes/cli-expose-plugin-config.md | 6 ++++++ .changes/plugin-config-getter.md | 5 +++++ core/tauri-build/src/config.rs | 20 ++++++++++++++++++++ core/tauri-build/src/lib.rs | 2 ++ tooling/cli/src/helpers/config.rs | 10 ++++++++++ 5 files changed, 43 insertions(+) create mode 100644 .changes/cli-expose-plugin-config.md create mode 100644 .changes/plugin-config-getter.md create mode 100644 core/tauri-build/src/config.rs 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