mirror of https://github.com/tauri-apps/tauri
This commit is contained in:
parent
0fe680d90e
commit
8599313a0f
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"cli.rs": patch
|
||||
---
|
||||
|
||||
Define `PLATFORM`, `ARCH`, `FAMILY` and `PLATFORM_TYPE` environment variables for the `beforeDevCommand` and `beforeBuildCommand` scripts.
|
|
@ -27,8 +27,8 @@ In addition to the JSON defined on the `tauri.conf.json` file, Tauri reads a pla
|
|||
The target directory <em>must</em> contain an index.html file.
|
||||
</div>`},
|
||||
{property: "devPath", type: "string", description: `Can be a path to a folder (either absolute or relative to tauri.conf.json) or a URL (like a live reload server).`},
|
||||
{property: "beforeDevCommand", optional: true, type: "string", description: `A command to run before starting Tauri in dev mode.`},
|
||||
{property: "beforeBuildCommand", optional: true, type: "string", description: `A command to run before starting Tauri in build mode.`},
|
||||
{property: "beforeDevCommand", optional: true, type: "string", description: `A command to run before starting Tauri in dev mode. The PLATFORM, ARCH, FAMILY and PLATFORM_TYPE environment variables are set if you perform conditional compilation.`},
|
||||
{property: "beforeBuildCommand", optional: true, type: "string", description: `A command to run before starting Tauri's build pipeline. The PLATFORM, ARCH, FAMILY and PLATFORM_TYPE environment variables are set if you perform conditional compilation.`},
|
||||
{property: "withGlobalTauri", optional: true, type: "boolean", description: "Enables the API injection to the window.__TAURI__ object. Useful if you're using Vanilla JS instead of importing the API using Rollup or Webpack. Reduces the command security since any external code can access it, so be careful with XSS attacks."}
|
||||
]}/>
|
||||
|
||||
|
|
|
@ -815,14 +815,18 @@ pub struct BuildConfig {
|
|||
/// The path or URL to use on development.
|
||||
#[serde(default = "default_dev_path")]
|
||||
pub dev_path: AppUrl,
|
||||
/// the path to the app's dist dir. This path must contain your index.html file.
|
||||
/// The path to the app's dist dir. This path must contain your index.html file.
|
||||
#[serde(default = "default_dist_dir")]
|
||||
pub dist_dir: AppUrl,
|
||||
/// a shell command to run before `tauri dev` kicks in
|
||||
/// A shell command to run before `tauri dev` kicks in.
|
||||
///
|
||||
/// The PLATFORM, ARCH, FAMILY and PLATFORM_TYPE environment variables are set if you perform conditional compilation.
|
||||
pub before_dev_command: Option<String>,
|
||||
/// a shell command to run before `tauri build` kicks in
|
||||
/// A shell command to run before `tauri build` kicks in.
|
||||
///
|
||||
/// The PLATFORM, ARCH, FAMILY and PLATFORM_TYPE environment variables are set if you perform conditional compilation.
|
||||
pub before_build_command: Option<String>,
|
||||
/// features passed to `cargo` commands
|
||||
/// Features passed to `cargo` commands.
|
||||
pub features: Option<Vec<String>>,
|
||||
/// Whether we should inject the Tauri API on `window.__TAURI__` or not.
|
||||
#[serde(default)]
|
||||
|
|
|
@ -261,14 +261,14 @@
|
|||
"type": "object",
|
||||
"properties": {
|
||||
"beforeBuildCommand": {
|
||||
"description": "a shell command to run before `tauri build` kicks in",
|
||||
"description": "A shell command to run before `tauri build` kicks in.\n\nThe PLATFORM, ARCH, FAMILY and PLATFORM_TYPE environment variables are set if you perform conditional compilation.",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"beforeDevCommand": {
|
||||
"description": "a shell command to run before `tauri dev` kicks in",
|
||||
"description": "A shell command to run before `tauri dev` kicks in.\n\nThe PLATFORM, ARCH, FAMILY and PLATFORM_TYPE environment variables are set if you perform conditional compilation.",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
|
@ -284,7 +284,7 @@
|
|||
]
|
||||
},
|
||||
"distDir": {
|
||||
"description": "the path to the app's dist dir. This path must contain your index.html file.",
|
||||
"description": "The path to the app's dist dir. This path must contain your index.html file.",
|
||||
"default": "../dist",
|
||||
"allOf": [
|
||||
{
|
||||
|
@ -293,7 +293,7 @@
|
|||
]
|
||||
},
|
||||
"features": {
|
||||
"description": "features passed to `cargo` commands",
|
||||
"description": "Features passed to `cargo` commands.",
|
||||
"type": [
|
||||
"array",
|
||||
"null"
|
||||
|
|
|
@ -9,6 +9,7 @@ use tauri_bundler::bundle::{bundle_project, PackageType};
|
|||
|
||||
use crate::helpers::{
|
||||
app_paths::{app_dir, tauri_dir},
|
||||
command_env,
|
||||
config::{get as get_config, AppUrl},
|
||||
execute_with_output,
|
||||
manifest::rewrite_manifest,
|
||||
|
@ -89,7 +90,8 @@ impl Build {
|
|||
&mut Command::new("cmd")
|
||||
.arg("/C")
|
||||
.arg(before_build)
|
||||
.current_dir(app_dir()),
|
||||
.current_dir(app_dir())
|
||||
.envs(command_env()),
|
||||
)
|
||||
.with_context(|| format!("failed to run `{}` with `cmd /C`", before_build))?;
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
|
@ -97,7 +99,8 @@ impl Build {
|
|||
&mut Command::new("sh")
|
||||
.arg("-c")
|
||||
.arg(before_build)
|
||||
.current_dir(app_dir()),
|
||||
.current_dir(app_dir())
|
||||
.envs(command_env()),
|
||||
)
|
||||
.with_context(|| format!("failed to run `{}` with `sh -c`", before_build))?;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
use crate::helpers::{
|
||||
app_paths::{app_dir, tauri_dir},
|
||||
command_env,
|
||||
config::{get as get_config, reload as reload_config},
|
||||
manifest::{get_workspace_members, rewrite_manifest},
|
||||
Logger,
|
||||
|
@ -141,6 +142,7 @@ impl Dev {
|
|||
.arg("/C")
|
||||
.arg(before_dev)
|
||||
.current_dir(app_dir())
|
||||
.envs(command_env())
|
||||
.spawn()
|
||||
.with_context(|| format!("failed to run `{}` with `cmd /C`", before_dev))?;
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
|
@ -148,6 +150,7 @@ impl Dev {
|
|||
.arg("-c")
|
||||
.arg(before_dev)
|
||||
.current_dir(app_dir())
|
||||
.envs(command_env())
|
||||
.spawn()
|
||||
.with_context(|| format!("failed to run `{}` with `sh -c`", before_dev))?;
|
||||
BEFORE_DEV.set(Mutex::new(child)).unwrap();
|
||||
|
|
|
@ -12,6 +12,7 @@ pub mod updater_signature;
|
|||
pub use logger::Logger;
|
||||
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
io::{BufRead, BufReader},
|
||||
process::{Command, Stdio},
|
||||
};
|
||||
|
@ -37,3 +38,20 @@ pub fn execute_with_output(cmd: &mut Command) -> crate::Result<()> {
|
|||
Err(anyhow::anyhow!("command failed"))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn command_env() -> HashMap<String, String> {
|
||||
let mut map = HashMap::new();
|
||||
map.insert("PLATFORM".into(), std::env::consts::OS.into());
|
||||
map.insert("ARCH".into(), std::env::consts::ARCH.into());
|
||||
map.insert("FAMILY".into(), std::env::consts::FAMILY.into());
|
||||
map.insert("VERSION".into(), os_info::get().version().to_string());
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
map.insert("PLATFORM_TYPE".into(), "Linux".into());
|
||||
#[cfg(target_os = "windows")]
|
||||
map.insert("PLATFORM_TYPE".into(), "Windows_NT".into());
|
||||
#[cfg(target_os = "macos")]
|
||||
map.insert("PLATFORM_TYPE".into(), "Darwing".into());
|
||||
|
||||
map
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue