@@ -60,6 +60,12 @@ pub struct Options {
6060 /// Url of your dev server
6161 #[ clap( short = 'P' , long) ]
6262 dev_path : Option < String > ,
63+ /// A shell command to run before `tauri dev` kicks in.
64+ #[ clap( long) ]
65+ before_dev_command : Option < String > ,
66+ /// A shell command to run before `tauri build` kicks in.
67+ #[ clap( long) ]
68+ before_build_command : Option < String > ,
6369}
6470
6571#[ derive( Default ) ]
@@ -90,6 +96,7 @@ impl Options {
9096 "What is your app name?" ,
9197 init_defaults. app_name . clone ( ) ,
9298 self . ci ,
99+ false ,
93100 )
94101 } ) ?;
95102
@@ -98,23 +105,49 @@ impl Options {
98105 "What should the window title be?" ,
99106 init_defaults. app_name . clone ( ) ,
100107 self . ci ,
108+ false ,
101109 )
102110 } ) ?;
103111
104112 self . dist_dir = self . dist_dir . map ( |s| Ok ( Some ( s) ) ) . unwrap_or_else ( || request_input (
105113 r#"Where are your web assets (HTML/CSS/JS) located, relative to the "<current dir>/src-tauri/tauri.conf.json" file that will be created?"# ,
106114 init_defaults. framework . as_ref ( ) . map ( |f| f. dist_dir ( ) ) ,
107- self . ci
115+ self . ci ,
116+ false ,
108117 ) ) ?;
109118
110119 self . dev_path = self . dev_path . map ( |s| Ok ( Some ( s) ) ) . unwrap_or_else ( || {
111120 request_input (
112121 "What is the url of your dev server?" ,
113122 init_defaults. framework . map ( |f| f. dev_path ( ) ) ,
114123 self . ci ,
124+ false ,
115125 )
116126 } ) ?;
117127
128+ self . before_dev_command = self
129+ . before_dev_command
130+ . map ( |s| Ok ( Some ( s) ) )
131+ . unwrap_or_else ( || {
132+ request_input (
133+ "What is your frontend dev command?" ,
134+ Some ( "npm run dev" . to_string ( ) ) ,
135+ self . ci ,
136+ true ,
137+ )
138+ } ) ?;
139+ self . before_build_command = self
140+ . before_build_command
141+ . map ( |s| Ok ( Some ( s) ) )
142+ . unwrap_or_else ( || {
143+ request_input (
144+ "What is your frontend build command?" ,
145+ Some ( "npm run build" . to_string ( ) ) ,
146+ self . ci ,
147+ true ,
148+ )
149+ } ) ?;
150+
118151 Ok ( self )
119152 }
120153}
@@ -178,6 +211,14 @@ pub fn command(mut options: Options) -> Result<()> {
178211 "window_title" ,
179212 to_json ( options. window_title . unwrap_or_else ( || "Tauri" . to_string ( ) ) ) ,
180213 ) ;
214+ data. insert (
215+ "before_dev_command" ,
216+ to_json ( options. before_dev_command . unwrap_or_default ( ) ) ,
217+ ) ;
218+ data. insert (
219+ "before_build_command" ,
220+ to_json ( options. before_build_command . unwrap_or_default ( ) ) ,
221+ ) ;
181222
182223 let mut config = serde_json:: from_str (
183224 & handlebars
@@ -241,20 +282,25 @@ pub fn command(mut options: Options) -> Result<()> {
241282 Ok ( ( ) )
242283}
243284
244- fn request_input < T > ( prompt : & str , default : Option < T > , skip : bool ) -> Result < Option < T > >
285+ fn request_input < T > (
286+ prompt : & str ,
287+ initial : Option < T > ,
288+ skip : bool ,
289+ allow_empty : bool ,
290+ ) -> Result < Option < T > >
245291where
246292 T : Clone + FromStr + Display + ToString ,
247293 T :: Err : Display + std:: fmt:: Debug ,
248294{
249295 if skip {
250- Ok ( default )
296+ Ok ( initial )
251297 } else {
252298 let theme = dialoguer:: theme:: ColorfulTheme :: default ( ) ;
253299 let mut builder = Input :: with_theme ( & theme) ;
254300 builder. with_prompt ( prompt) ;
301+ builder. allow_empty ( allow_empty) ;
255302
256- if let Some ( v) = default {
257- builder. default ( v. clone ( ) ) ;
303+ if let Some ( v) = initial {
258304 builder. with_initial_text ( v. to_string ( ) ) ;
259305 }
260306
0 commit comments