|
@@ -4,7 +4,7 @@
|
|
|
|
|
|
use super::{get_app, Target};
|
|
|
use crate::{
|
|
|
- helpers::{app_paths::tauri_dir, config::get as get_tauri_config, template::JsonMap},
|
|
|
+ helpers::{config::get as get_tauri_config, template::JsonMap},
|
|
|
interface::{AppInterface, Interface},
|
|
|
Result,
|
|
|
};
|
|
@@ -18,17 +18,13 @@ use cargo_mobile2::{
|
|
|
util::{
|
|
|
self,
|
|
|
cli::{Report, TextWrapper},
|
|
|
- relativize_path,
|
|
|
},
|
|
|
};
|
|
|
use handlebars::{
|
|
|
Context, Handlebars, Helper, HelperResult, Output, RenderContext, RenderError, RenderErrorReason,
|
|
|
};
|
|
|
|
|
|
-use std::{
|
|
|
- env::{current_dir, var, var_os},
|
|
|
- path::PathBuf,
|
|
|
-};
|
|
|
+use std::{env::var_os, path::PathBuf};
|
|
|
|
|
|
pub fn command(
|
|
|
target: Target,
|
|
@@ -87,7 +83,6 @@ pub fn exec(
|
|
|
#[allow(unused_variables)] reinstall_deps: bool,
|
|
|
skip_targets_install: bool,
|
|
|
) -> Result<App> {
|
|
|
- let current_dir = current_dir()?;
|
|
|
let tauri_config = get_tauri_config(target.platform_target(), None)?;
|
|
|
|
|
|
let tauri_config_guard = tauri_config.lock().unwrap();
|
|
@@ -97,75 +92,49 @@ pub fn exec(
|
|
|
|
|
|
let (handlebars, mut map) = handlebars(&app);
|
|
|
|
|
|
- // the CWD used when the the IDE runs the android-studio-script or the xcode-script
|
|
|
- let ide_run_cwd = if target == Target::Android {
|
|
|
- tauri_dir()
|
|
|
- } else {
|
|
|
- tauri_dir().join("gen/apple")
|
|
|
- };
|
|
|
-
|
|
|
let mut args = std::env::args_os();
|
|
|
- let mut binary = args
|
|
|
+
|
|
|
+ let (binary, mut build_args) = args
|
|
|
.next()
|
|
|
.map(|bin| {
|
|
|
- let path = PathBuf::from(&bin);
|
|
|
- if path.exists() {
|
|
|
- let absolute_path = util::prefix_path(¤t_dir, path);
|
|
|
- return relativize_path(absolute_path, &ide_run_cwd).into_os_string();
|
|
|
+ let bin_path = PathBuf::from(&bin);
|
|
|
+ let mut build_args = vec!["tauri"];
|
|
|
+
|
|
|
+ if let Some(bin_stem) = bin_path.file_stem() {
|
|
|
+ let r = regex::Regex::new("(nodejs|node)\\-?([1-9]*)*$").unwrap();
|
|
|
+ if r.is_match(&bin_stem.to_string_lossy()) {
|
|
|
+ if let Some(npm_execpath) = var_os("npm_execpath") {
|
|
|
+ let manager_stem = PathBuf::from(&npm_execpath)
|
|
|
+ .file_stem()
|
|
|
+ .unwrap()
|
|
|
+ .to_os_string();
|
|
|
+ let is_npm = manager_stem == "npm-cli";
|
|
|
+ let binary = if is_npm {
|
|
|
+ "npm".into()
|
|
|
+ } else if manager_stem == "npx-cli" {
|
|
|
+ "npx".into()
|
|
|
+ } else {
|
|
|
+ manager_stem
|
|
|
+ };
|
|
|
+
|
|
|
+ if is_npm {
|
|
|
+ build_args.insert(0, "run");
|
|
|
+ build_args.insert(1, "--");
|
|
|
+ }
|
|
|
+
|
|
|
+ return (binary, build_args);
|
|
|
+ }
|
|
|
+ } else if !cfg!(debug_assertions) && bin_stem == "cargo-tauri" {
|
|
|
+ return (std::ffi::OsString::from("cargo"), build_args);
|
|
|
+ }
|
|
|
}
|
|
|
- bin
|
|
|
+
|
|
|
+ (bin, build_args)
|
|
|
})
|
|
|
- .unwrap_or_else(|| std::ffi::OsString::from("cargo"));
|
|
|
- let mut build_args = Vec::new();
|
|
|
- for arg in args {
|
|
|
- let path = PathBuf::from(&arg);
|
|
|
- if path.exists() {
|
|
|
- let absolute_path = util::prefix_path(¤t_dir, path);
|
|
|
- build_args.push(
|
|
|
- relativize_path(absolute_path, &ide_run_cwd)
|
|
|
- .to_string_lossy()
|
|
|
- .into_owned(),
|
|
|
- );
|
|
|
- continue;
|
|
|
- }
|
|
|
- let is_mobile_cmd_arg = arg == "android" || arg == "ios";
|
|
|
- build_args.push(arg.to_string_lossy().into_owned());
|
|
|
- if is_mobile_cmd_arg {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- build_args.push(target.ide_build_script_name().into());
|
|
|
-
|
|
|
- let binary_path = PathBuf::from(&binary);
|
|
|
- let bin_stem = binary_path.file_stem().unwrap().to_string_lossy();
|
|
|
- let r = regex::Regex::new("(nodejs|node)\\-?([1-9]*)*$").unwrap();
|
|
|
- if r.is_match(&bin_stem) {
|
|
|
- if let Some(npm_execpath) = var_os("npm_execpath").map(PathBuf::from) {
|
|
|
- let manager_stem = npm_execpath.file_stem().unwrap().to_os_string();
|
|
|
- let is_npm = manager_stem == "npm-cli";
|
|
|
- let is_npx = manager_stem == "npx-cli";
|
|
|
- binary = if is_npm {
|
|
|
- "npm".into()
|
|
|
- } else if is_npx {
|
|
|
- "npx".into()
|
|
|
- } else {
|
|
|
- manager_stem
|
|
|
- };
|
|
|
- if !(build_args.is_empty() || is_npx) {
|
|
|
- // remove script path, we'll use `npm_lifecycle_event` instead
|
|
|
- build_args.remove(0);
|
|
|
- }
|
|
|
- if is_npm {
|
|
|
- build_args.insert(0, "--".into());
|
|
|
- }
|
|
|
- if !is_npx {
|
|
|
- build_args.insert(0, var("npm_lifecycle_event").unwrap());
|
|
|
- }
|
|
|
- if is_npm {
|
|
|
- build_args.insert(0, "run".into());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ .unwrap_or_else(|| (std::ffi::OsString::from("cargo"), vec!["tauri"]));
|
|
|
+
|
|
|
+ build_args.push(target.command_name());
|
|
|
+ build_args.push(target.ide_build_script_name());
|
|
|
|
|
|
map.insert("tauri-binary", binary.to_string_lossy());
|
|
|
map.insert("tauri-binary-args", &build_args);
|