mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-10-26 09:58:16 +03:00
feat(core): allow a plugin build script to read the plugin config object (#7447)
This commit is contained in:
parent
aba04fa823
commit
522de0e788
6
.changes/cli-expose-plugin-config.md
Normal file
6
.changes/cli-expose-plugin-config.md
Normal file
@ -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.
|
5
.changes/plugin-config-getter.md
Normal file
5
.changes/plugin-config-getter.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri-build": patch:feat
|
||||
---
|
||||
|
||||
Added the `config::plugin_config` function to read the plugin configuration set from the CLI.
|
20
core/tauri-build/src/config.rs
Normal file
20
core/tauri-build/src/config.rs
Normal file
@ -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<T: DeserializeOwned>(name: &str) -> Option<T> {
|
||||
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
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -175,6 +175,16 @@ fn get_internal(merge_config: Option<&str>, reload: bool) -> crate::Result<Confi
|
||||
// revert to previous working directory
|
||||
set_current_dir(current_dir)?;
|
||||
|
||||
for (plugin, conf) in &config.plugins.0 {
|
||||
set_var(
|
||||
format!(
|
||||
"TAURI_{}_PLUGIN_CONFIG",
|
||||
plugin.to_uppercase().replace('-', "_")
|
||||
),
|
||||
serde_json::to_string(&conf)?,
|
||||
);
|
||||
}
|
||||
|
||||
*config_handle().lock().unwrap() = Some(ConfigMetadata {
|
||||
inner: config,
|
||||
extensions,
|
||||
|
Loading…
Reference in New Issue
Block a user