4
4
5
5
use super :: { get_app, Target } ;
6
6
use crate :: {
7
- helpers:: { app_paths :: tauri_dir , config:: get as get_tauri_config, template:: JsonMap } ,
7
+ helpers:: { config:: get as get_tauri_config, template:: JsonMap } ,
8
8
interface:: { AppInterface , Interface } ,
9
9
Result ,
10
10
} ;
@@ -18,17 +18,13 @@ use cargo_mobile2::{
18
18
util:: {
19
19
self ,
20
20
cli:: { Report , TextWrapper } ,
21
- relativize_path,
22
21
} ,
23
22
} ;
24
23
use handlebars:: {
25
24
Context , Handlebars , Helper , HelperResult , Output , RenderContext , RenderError , RenderErrorReason ,
26
25
} ;
27
26
28
- use std:: {
29
- env:: { current_dir, var, var_os} ,
30
- path:: PathBuf ,
31
- } ;
27
+ use std:: { env:: var_os, path:: PathBuf } ;
32
28
33
29
pub fn command (
34
30
target : Target ,
@@ -87,7 +83,6 @@ pub fn exec(
87
83
#[ allow( unused_variables) ] reinstall_deps : bool ,
88
84
skip_targets_install : bool ,
89
85
) -> Result < App > {
90
- let current_dir = current_dir ( ) ?;
91
86
let tauri_config = get_tauri_config ( target. platform_target ( ) , None ) ?;
92
87
93
88
let tauri_config_guard = tauri_config. lock ( ) . unwrap ( ) ;
@@ -97,75 +92,49 @@ pub fn exec(
97
92
98
93
let ( handlebars, mut map) = handlebars ( & app) ;
99
94
100
- // the CWD used when the the IDE runs the android-studio-script or the xcode-script
101
- let ide_run_cwd = if target == Target :: Android {
102
- tauri_dir ( )
103
- } else {
104
- tauri_dir ( ) . join ( "gen/apple" )
105
- } ;
106
-
107
95
let mut args = std:: env:: args_os ( ) ;
108
- let mut binary = args
96
+
97
+ let ( binary, mut build_args) = args
109
98
. next ( )
110
99
. map ( |bin| {
111
- let path = PathBuf :: from ( & bin) ;
112
- if path. exists ( ) {
113
- let absolute_path = util:: prefix_path ( & current_dir, path) ;
114
- return relativize_path ( absolute_path, & ide_run_cwd) . into_os_string ( ) ;
100
+ let bin_path = PathBuf :: from ( & bin) ;
101
+ let mut build_args = vec ! [ "tauri" ] ;
102
+
103
+ if let Some ( bin_stem) = bin_path. file_stem ( ) {
104
+ let r = regex:: Regex :: new ( "(nodejs|node)\\ -?([1-9]*)*$" ) . unwrap ( ) ;
105
+ if r. is_match ( & bin_stem. to_string_lossy ( ) ) {
106
+ if let Some ( npm_execpath) = var_os ( "npm_execpath" ) {
107
+ let manager_stem = PathBuf :: from ( & npm_execpath)
108
+ . file_stem ( )
109
+ . unwrap ( )
110
+ . to_os_string ( ) ;
111
+ let is_npm = manager_stem == "npm-cli" ;
112
+ let binary = if is_npm {
113
+ "npm" . into ( )
114
+ } else if manager_stem == "npx-cli" {
115
+ "npx" . into ( )
116
+ } else {
117
+ manager_stem
118
+ } ;
119
+
120
+ if is_npm {
121
+ build_args. insert ( 0 , "run" ) ;
122
+ build_args. insert ( 1 , "--" ) ;
123
+ }
124
+
125
+ return ( binary, build_args) ;
126
+ }
127
+ } else if !cfg ! ( debug_assertions) && bin_stem == "cargo-tauri" {
128
+ return ( std:: ffi:: OsString :: from ( "cargo" ) , build_args) ;
129
+ }
115
130
}
116
- bin
131
+
132
+ ( bin, build_args)
117
133
} )
118
- . unwrap_or_else ( || std:: ffi:: OsString :: from ( "cargo" ) ) ;
119
- let mut build_args = Vec :: new ( ) ;
120
- for arg in args {
121
- let path = PathBuf :: from ( & arg) ;
122
- if path. exists ( ) {
123
- let absolute_path = util:: prefix_path ( & current_dir, path) ;
124
- build_args. push (
125
- relativize_path ( absolute_path, & ide_run_cwd)
126
- . to_string_lossy ( )
127
- . into_owned ( ) ,
128
- ) ;
129
- continue ;
130
- }
131
- let is_mobile_cmd_arg = arg == "android" || arg == "ios" ;
132
- build_args. push ( arg. to_string_lossy ( ) . into_owned ( ) ) ;
133
- if is_mobile_cmd_arg {
134
- break ;
135
- }
136
- }
137
- build_args. push ( target. ide_build_script_name ( ) . into ( ) ) ;
138
-
139
- let binary_path = PathBuf :: from ( & binary) ;
140
- let bin_stem = binary_path. file_stem ( ) . unwrap ( ) . to_string_lossy ( ) ;
141
- let r = regex:: Regex :: new ( "(nodejs|node)\\ -?([1-9]*)*$" ) . unwrap ( ) ;
142
- if r. is_match ( & bin_stem) {
143
- if let Some ( npm_execpath) = var_os ( "npm_execpath" ) . map ( PathBuf :: from) {
144
- let manager_stem = npm_execpath. file_stem ( ) . unwrap ( ) . to_os_string ( ) ;
145
- let is_npm = manager_stem == "npm-cli" ;
146
- let is_npx = manager_stem == "npx-cli" ;
147
- binary = if is_npm {
148
- "npm" . into ( )
149
- } else if is_npx {
150
- "npx" . into ( )
151
- } else {
152
- manager_stem
153
- } ;
154
- if !( build_args. is_empty ( ) || is_npx) {
155
- // remove script path, we'll use `npm_lifecycle_event` instead
156
- build_args. remove ( 0 ) ;
157
- }
158
- if is_npm {
159
- build_args. insert ( 0 , "--" . into ( ) ) ;
160
- }
161
- if !is_npx {
162
- build_args. insert ( 0 , var ( "npm_lifecycle_event" ) . unwrap ( ) ) ;
163
- }
164
- if is_npm {
165
- build_args. insert ( 0 , "run" . into ( ) ) ;
166
- }
167
- }
168
- }
134
+ . unwrap_or_else ( || ( std:: ffi:: OsString :: from ( "cargo" ) , vec ! [ "tauri" ] ) ) ;
135
+
136
+ build_args. push ( target. command_name ( ) ) ;
137
+ build_args. push ( target. ide_build_script_name ( ) ) ;
169
138
170
139
map. insert ( "tauri-binary" , binary. to_string_lossy ( ) ) ;
171
140
map. insert ( "tauri-binary-args" , & build_args) ;
0 commit comments