@@ -28,6 +28,18 @@ pub async fn watch(cfg: &Config, filter: Option<Vec<String>>) {
2828 . flat_map ( |( _, action) | & action. targets )
2929 . for_each ( |target| watcher. add_target ( BasicTarget :: new ( target. path ( ) ) ) ) ;
3030
31+ let startup_actions = actions. iter ( ) . filter ( |a| {
32+ a. 1 . run_commands_on_startup . is_some_and ( |v| v) || matches ! ( a. 1 . startup_commands, Some ( _) )
33+ } ) ;
34+ for ( name, action) in startup_actions {
35+ info ! ( "Executing startup commands for {} ..." , name) ;
36+ if let Some ( cmds) = action. startup_commands . as_ref ( ) {
37+ execute_commands :: < Vec < ( & str , & str ) > , & str , & str > ( cmds, None ) . await ;
38+ } else {
39+ execute_commands :: < Vec < ( & str , & str ) > , & str , & str > ( & action. commands , None ) . await ;
40+ }
41+ }
42+
3143 info ! ( "Watching targets ..." ) ;
3244 loop {
3345 for ( index, transition) in watcher
@@ -61,7 +73,7 @@ pub async fn watch(cfg: &Config, filter: Option<Vec<String>>) {
6173 ) ,
6274 ] ;
6375 tokio:: spawn ( async move {
64- execute_commands ( & cmds, envmap) . await ;
76+ execute_commands ( & cmds, Some ( envmap) ) . await ;
6577 } ) ;
6678 }
6779 }
@@ -71,7 +83,7 @@ pub async fn watch(cfg: &Config, filter: Option<Vec<String>>) {
7183 }
7284}
7385
74- async fn execute_commands < E , K , V > ( cmds : & [ Command ] , env : E )
86+ async fn execute_commands < E , K , V > ( cmds : & [ Command ] , env : Option < E > )
7587where
7688 E : IntoIterator < Item = ( K , V ) > + Clone ,
7789 K : AsRef < OsStr > ,
8799 let args = & args[ 1 ..] ;
88100
89101 let mut exec = process:: Command :: new ( ex) ;
90- exec. args ( args) . current_dir ( cmd. cwd ( ) ) . envs ( env. clone ( ) ) ;
102+ exec. args ( args) . current_dir ( cmd. cwd ( ) ) ;
103+ if let Some ( env) = env. as_ref ( ) {
104+ exec. envs ( env. clone ( ) ) ;
105+ }
91106
92107 if cmd. is_async ( ) {
93108 match exec. spawn ( ) {
0 commit comments