@@ -26,6 +26,7 @@ pub fn create_pkg_dir(path: &str, step: &Step) -> result::Result<(), Error> {
26
26
pub enum InitMode {
27
27
Normal ,
28
28
Nobuild ,
29
+ Noinstall ,
29
30
}
30
31
31
32
pub struct Init {
@@ -34,7 +35,7 @@ pub struct Init {
34
35
disable_dts : bool ,
35
36
target : String ,
36
37
debug : bool ,
37
- crate_name : Option < String > ,
38
+ crate_name : String ,
38
39
}
39
40
40
41
type InitStep = fn ( & mut Init , & Step , & Logger ) -> result:: Result < ( ) , Error > ;
@@ -46,15 +47,17 @@ impl Init {
46
47
disable_dts : bool ,
47
48
target : String ,
48
49
debug : bool ,
49
- ) -> Init {
50
- Init {
51
- crate_path : set_crate_path ( path) ,
50
+ ) -> Result < Init , Error > {
51
+ let crate_path = set_crate_path ( path) ;
52
+ let crate_name = manifest:: get_crate_name ( & crate_path) ?;
53
+ Ok ( Init {
54
+ crate_path,
52
55
scope,
53
56
disable_dts,
54
57
target,
55
58
debug,
56
- crate_name : None ,
57
- }
59
+ crate_name,
60
+ } )
58
61
}
59
62
60
63
fn get_process_steps ( mode : InitMode ) -> Vec < ( & ' static str , InitStep ) > {
@@ -78,9 +81,17 @@ impl Init {
78
81
step_create_json,
79
82
step_copy_readme,
80
83
step_install_wasm_bindgen,
81
- step_running_wasm_bindgen ,
84
+ step_run_wasm_bindgen ,
82
85
] ,
83
86
InitMode :: Nobuild => steps ! [ step_create_dir, step_create_json, step_copy_readme, ] ,
87
+ InitMode :: Noinstall => steps ! [
88
+ step_check_crate_config,
89
+ step_build_wasm,
90
+ step_create_dir,
91
+ step_create_json,
92
+ step_copy_readme,
93
+ step_run_wasm_bindgen
94
+ ] ,
84
95
}
85
96
}
86
97
@@ -193,33 +204,29 @@ impl Init {
193
204
info ! ( & log, "Installing wasm-bindgen-cli was successful." ) ;
194
205
195
206
info ! ( & log, "Getting the crate name from the manifest..." ) ;
196
- self . crate_name = Some ( manifest:: get_crate_name ( & self . crate_path ) ?) ;
207
+ self . crate_name = manifest:: get_crate_name ( & self . crate_path ) ?;
197
208
#[ cfg( not( target_os = "windows" ) ) ]
198
209
info ! (
199
210
& log,
200
211
"Got crate name {} from the manifest at {}/Cargo.toml." ,
201
- & self . crate_name. as_ref ( ) . unwrap ( ) ,
212
+ & self . crate_name,
202
213
& self . crate_path
203
214
) ;
204
215
#[ cfg( target_os = "windows" ) ]
205
216
info ! (
206
217
& log,
207
218
"Got crate name {} from the manifest at {}\\ Cargo.toml." ,
208
- & self . crate_name. as_ref ( ) . unwrap ( ) ,
219
+ & self . crate_name,
209
220
& self . crate_path
210
221
) ;
211
222
Ok ( ( ) )
212
223
}
213
224
214
- fn step_running_wasm_bindgen (
215
- & mut self ,
216
- step : & Step ,
217
- log : & Logger ,
218
- ) -> result:: Result < ( ) , Error > {
225
+ fn step_run_wasm_bindgen ( & mut self , step : & Step , log : & Logger ) -> result:: Result < ( ) , Error > {
219
226
info ! ( & log, "Building the wasm bindings..." ) ;
220
227
bindgen:: wasm_bindgen_build (
221
228
& self . crate_path ,
222
- & self . crate_name . as_ref ( ) . unwrap ( ) ,
229
+ & self . crate_name ,
223
230
self . disable_dts ,
224
231
& self . target ,
225
232
self . debug ,
@@ -259,7 +266,7 @@ mod test {
259
266
"step_create_json" ,
260
267
"step_copy_readme" ,
261
268
"step_install_wasm_bindgen" ,
262
- "step_running_wasm_bindgen "
269
+ "step_run_wasm_bindgen "
263
270
]
264
271
) ;
265
272
}
@@ -275,4 +282,23 @@ mod test {
275
282
[ "step_create_dir" , "step_create_json" , "step_copy_readme" ]
276
283
) ;
277
284
}
285
+
286
+ #[ test]
287
+ fn init_skip_install ( ) {
288
+ let steps: Vec < & str > = Init :: get_process_steps ( InitMode :: Noinstall )
289
+ . into_iter ( )
290
+ . map ( |( n, _) | n)
291
+ . collect ( ) ;
292
+ assert_eq ! (
293
+ steps,
294
+ [
295
+ "step_check_crate_config" ,
296
+ "step_build_wasm" ,
297
+ "step_create_dir" ,
298
+ "step_create_json" ,
299
+ "step_copy_readme" ,
300
+ "step_run_wasm_bindgen"
301
+ ]
302
+ ) ;
303
+ }
278
304
}
0 commit comments