@@ -76,21 +76,44 @@ pub fn initialize(target: impl AsRef<Path>) {
7676 }
7777}
7878
79- /// Clones a remote repository into the specified directory.
80- pub fn clone_remote (
81- repo_url : & str ,
82- target_dir : impl AsRef < Path > ,
83- ) -> std:: io:: Result < process:: Output > {
84- Command :: new ( "git" )
85- . args ( [
86- "clone" ,
87- "--depth" ,
88- "1" ,
89- "--recursive" ,
90- repo_url,
91- target_dir. as_ref ( ) . to_str ( ) . expect ( "Target path for git clone does not exist" ) ,
92- ] )
93- . output ( )
79+ /// Clones a remote repository into the specified directory. Panics if the command fails.
80+ pub fn clone_remote ( repo_url : & str , target_dir : & str ) {
81+ let mut cmd = Command :: new ( "git" ) ;
82+ let status = cmd
83+ . args ( [ "clone" , "--depth=1" , "--recursive" , "--shallow-submodules" , repo_url, target_dir] )
84+ . status ( )
85+ . unwrap ( ) ;
86+ if !status. success ( ) {
87+ panic ! ( "{cmd:?}" ) ;
88+ }
89+ eprintln ! ( ) ;
90+ }
91+
92+ /// Runs common installation commands, such as `make` and `npm`. Continues if any command fails.
93+ pub fn run_install_commands ( root : & Path ) {
94+ let root_files =
95+ std:: fs:: read_dir ( root) . unwrap ( ) . flatten ( ) . map ( |x| x. path ( ) ) . collect :: < Vec < _ > > ( ) ;
96+ let contains = |path : & str | root_files. iter ( ) . any ( |p| p. to_str ( ) . unwrap ( ) . contains ( path) ) ;
97+ let run = |args : & [ & str ] | {
98+ let mut cmd = Command :: new ( args[ 0 ] ) ;
99+ cmd. args ( & args[ 1 ..] ) . current_dir ( root) . stdout ( Stdio :: null ( ) ) . stderr ( Stdio :: null ( ) ) ;
100+ let st = cmd. status ( ) ;
101+ eprintln ! ( "\n \n {cmd:?} -> {st:?}" ) ;
102+ } ;
103+ let maybe_run = |path : & str , args : & [ & str ] | {
104+ let c = contains ( path) ;
105+ if c {
106+ run ( args) ;
107+ }
108+ c
109+ } ;
110+
111+ maybe_run ( "Makefile" , & [ "make" , "install" ] ) ;
112+ let pnpm = maybe_run ( "pnpm-lock.yaml" , & [ "pnpm" , "install" , "--prefer-offline" ] ) ;
113+ let yarn = maybe_run ( "yarn.lock" , & [ "yarn" , "install" , "--prefer-offline" ] ) ;
114+ if !pnpm && !yarn && contains ( "package.json" ) {
115+ run ( & [ "npm" , "install" ] ) ;
116+ }
94117}
95118
96119/// Setup an empty test project and return a command pointing to the forge
0 commit comments