fix cli configuration environment variable

This commit is contained in:
Evan Almloff 2023-11-14 15:50:04 -06:00
parent 06be18a591
commit 1ed66a54cc
6 changed files with 13 additions and 81 deletions

View file

@ -19,6 +19,7 @@ cargo_toml = "0.16.0"
tauri-bundler = { version = "=1.3.0", features = ["native-tls-vendored"], optional = true }
tauri-utils = { version = "=1.4.*", optional = true }
once_cell = "1.18.0"
tracing.workspace = true
[features]
default = []

View file

@ -1,74 +0,0 @@
[application]
# dioxus project name
name = "{{project-name}}"
# default platfrom
# you can also use `dx serve/build --platform XXX` to use other platform
# value: web | desktop
default_platform = "{{default-platform}}"
# Web `build` & `serve` dist path
out_dir = "dist"
# resource (static) file folder
asset_dir = "public"
[web.app]
# HTML title tag content
title = "Dioxus | An elegant GUI library for Rust"
[web.watcher]
index_on_404 = true
watch_path = ["src", "examples"]
# include `assets` in web platform
[web.resource]
# CSS style file
style = []
# Javascript code file
script = []
[web.resource.dev]
# Javascript code file
# serve: [dev-server] only
script = []
[application.plugins]
available = true
required = []
[bundler]
# Bundle identifier
identifier = "io.github.{{project-name}}"
# Bundle publisher
publisher = "{{project-name}}"
# Bundle icon
icon = ["icons/icon.png"]
# Bundle resources
resources = ["public/*"]
# Bundle copyright
copyright = ""
# Bundle category
category = "Utility"
# Bundle short description
short_description = "An amazing dioxus application."
# Bundle long description
long_description = """
An amazing dioxus application.
"""

View file

@ -231,6 +231,7 @@ pub enum WebviewInstallMode {
FixedRuntime { path: PathBuf },
}
#[cfg(feature = "cli")]
impl WebviewInstallMode {
fn into(self) -> tauri_utils::config::WebviewInstallMode {
match self {

View file

@ -46,8 +46,13 @@ impl std::error::Error for DioxusCLINotUsed {}
pub static CURRENT_CONFIG: once_cell::sync::Lazy<
Result<crate::config::CrateConfig, DioxusCLINotUsed>,
> = once_cell::sync::Lazy::new(|| {
std::env::var(crate::__private::CONFIG_ENV)
.ok()
CURRENT_CONFIG_JSON
.and_then(|config| serde_json::from_str(&config).ok())
.ok_or(DioxusCLINotUsed)
.ok_or_else(|| {
tracing::error!("A library is trying to access the crate's configuration, but the dioxus CLI was not used to build the application.");
DioxusCLINotUsed
})
});
/// The current crate's configuration.
pub const CURRENT_CONFIG_JSON: Option<&str> = std::option_env!("DIOXUS_CONFIG");

View file

@ -47,6 +47,7 @@ pub fn build(config: &CrateConfig, quiet: bool) -> Result<BuildResult> {
let ignore_files = build_assets(config)?;
let t_start = std::time::Instant::now();
let _guard = dioxus_cli_config::__private::save_config(config);
// [1] Build the .wasm module
log::info!("🚅 Running build command...");
@ -90,8 +91,6 @@ pub fn build(config: &CrateConfig, quiet: bool) -> Result<BuildResult> {
ExecutableType::Example(name) => cmd.arg("--example").arg(name),
};
let _ = dioxus_cli_config::__private::save_config(config);
let warning_messages = prettier_build(cmd)?;
// [2] Establish the output directory structure
@ -254,6 +253,7 @@ pub fn build_desktop(config: &CrateConfig, _is_serve: bool) -> Result<BuildResul
let t_start = std::time::Instant::now();
let ignore_files = build_assets(config)?;
let _guard = dioxus_cli_config::__private::save_config(config);
let mut cmd = subprocess::Exec::cmd("cargo")
.cwd(&config.crate_dir)
@ -284,8 +284,6 @@ pub fn build_desktop(config: &CrateConfig, _is_serve: bool) -> Result<BuildResul
ExecutableType::Example(name) => cmd.arg("--example").arg(name),
};
let _ = dioxus_cli_config::__private::save_config(config);
let warning_messages = prettier_build(cmd)?;
let release_type = match config.release {

View file

@ -1,3 +1,4 @@
use dioxus_cli_config::DioxusConfig;
use std::path::PathBuf;
use anyhow::anyhow;