@@ -14,10 +14,10 @@ pub struct Config {
14
14
pub ( crate ) initial_endowment : String ,
15
15
}
16
16
17
+ /// Creates a new template at `target` dir
17
18
pub fn instantiate_template_dir ( template : & Template , target : & Path , config : Config ) -> Result < ( ) > {
18
- use Template :: * ;
19
- // TODO : if target folder exists, prompt user to clean dir or abort
20
19
sanitize ( target) ?;
20
+ use Template :: * ;
21
21
let url = match template {
22
22
EPT => "https://github.com/paritytech/extended-parachain-template.git" ,
23
23
FPT => "https://github.com/paritytech/frontier-parachain-template.git" ,
@@ -26,17 +26,16 @@ pub fn instantiate_template_dir(template: &Template, target: &Path, config: Conf
26
26
return instantiate_vanilla_template ( target, config) ;
27
27
}
28
28
} ;
29
- Repository :: clone ( url, target) ?;
29
+ clone_and_degit ( url, target) ?;
30
+ Repository :: init ( target) ?;
30
31
Ok ( ( ) )
31
32
}
32
33
// TODO: The config will shape the emitted template
33
34
pub fn instantiate_vanilla_template ( target : & Path , config : Config ) -> Result < ( ) > {
34
35
let temp_dir = :: tempfile:: TempDir :: new_in ( std:: env:: temp_dir ( ) ) ?;
35
- let temp_path = temp_dir. path ( ) ;
36
+ let source = temp_dir. path ( ) ;
36
37
// println!("Temporary directory created at {:?}", temp_path);
37
-
38
- Repository :: clone ( "https://github.com/weezy20/DoTemplate.git" , temp_path) ?;
39
- let source = temp_path. join ( "templates/vanilla-parachain" ) ;
38
+ clone_and_degit ( "https://github.com/r0guelabs/vanilla-parachain.git" , source) ?;
40
39
41
40
for entry in WalkDir :: new ( & source) {
42
41
let entry = entry?;
@@ -60,7 +59,7 @@ pub fn instantiate_vanilla_template(target: &Path, config: Config) -> Result<()>
60
59
& target. join ( "node/src/chain_spec.rs" ) ,
61
60
chainspec. render ( ) . expect ( "infallible" ) . as_ref ( ) ,
62
61
) ;
63
-
62
+ Repository :: init ( target ) ? ;
64
63
Ok ( ( ) )
65
64
}
66
65
@@ -86,3 +85,11 @@ fn sanitize(target: &Path) -> Result<()> {
86
85
}
87
86
Ok ( ( ) )
88
87
}
88
+
89
+ /// Clone `url` into `target` and degit it
90
+ fn clone_and_degit ( url : & str , target : & Path ) -> Result < ( ) > {
91
+ let repo = Repository :: clone ( url, target) ?;
92
+ let git_dir = repo. path ( ) ;
93
+ fs:: remove_dir_all ( & git_dir) ?;
94
+ Ok ( ( ) )
95
+ }
0 commit comments