Skip to content

Commit 48410ba

Browse files
Merge pull request #186 from ashleygwilliams/no-install-no-cry
feat(init): no install flag
2 parents 1c50b12 + 78527b7 commit 48410ba

File tree

2 files changed

+54
-27
lines changed

2 files changed

+54
-27
lines changed

src/command/init.rs

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub fn create_pkg_dir(path: &str, step: &Step) -> result::Result<(), Error> {
2626
pub enum InitMode {
2727
Normal,
2828
Nobuild,
29+
Noinstall,
2930
}
3031

3132
pub struct Init {
@@ -34,7 +35,7 @@ pub struct Init {
3435
disable_dts: bool,
3536
target: String,
3637
debug: bool,
37-
crate_name: Option<String>,
38+
crate_name: String,
3839
}
3940

4041
type InitStep = fn(&mut Init, &Step, &Logger) -> result::Result<(), Error>;
@@ -46,15 +47,17 @@ impl Init {
4647
disable_dts: bool,
4748
target: String,
4849
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,
5255
scope,
5356
disable_dts,
5457
target,
5558
debug,
56-
crate_name: None,
57-
}
59+
crate_name,
60+
})
5861
}
5962

6063
fn get_process_steps(mode: InitMode) -> Vec<(&'static str, InitStep)> {
@@ -78,9 +81,17 @@ impl Init {
7881
step_create_json,
7982
step_copy_readme,
8083
step_install_wasm_bindgen,
81-
step_running_wasm_bindgen,
84+
step_run_wasm_bindgen,
8285
],
8386
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+
],
8495
}
8596
}
8697

@@ -193,33 +204,29 @@ impl Init {
193204
info!(&log, "Installing wasm-bindgen-cli was successful.");
194205

195206
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)?;
197208
#[cfg(not(target_os = "windows"))]
198209
info!(
199210
&log,
200211
"Got crate name {} from the manifest at {}/Cargo.toml.",
201-
&self.crate_name.as_ref().unwrap(),
212+
&self.crate_name,
202213
&self.crate_path
203214
);
204215
#[cfg(target_os = "windows")]
205216
info!(
206217
&log,
207218
"Got crate name {} from the manifest at {}\\Cargo.toml.",
208-
&self.crate_name.as_ref().unwrap(),
219+
&self.crate_name,
209220
&self.crate_path
210221
);
211222
Ok(())
212223
}
213224

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> {
219226
info!(&log, "Building the wasm bindings...");
220227
bindgen::wasm_bindgen_build(
221228
&self.crate_path,
222-
&self.crate_name.as_ref().unwrap(),
229+
&self.crate_name,
223230
self.disable_dts,
224231
&self.target,
225232
self.debug,
@@ -259,7 +266,7 @@ mod test {
259266
"step_create_json",
260267
"step_copy_readme",
261268
"step_install_wasm_bindgen",
262-
"step_running_wasm_bindgen"
269+
"step_run_wasm_bindgen"
263270
]
264271
);
265272
}
@@ -275,4 +282,23 @@ mod test {
275282
["step_create_dir", "step_create_json", "step_copy_readme"]
276283
);
277284
}
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+
}
278304
}

src/command/mod.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ pub enum Command {
2323
#[structopt(long = "scope", short = "s")]
2424
scope: Option<String>,
2525

26-
#[structopt(long = "--skip-build")]
27-
/// Do not build, only update metadata
28-
skip_build: bool,
26+
#[structopt(long = "mode", short = "m", default_value = "normal")]
27+
/// Sets steps to be run. [possible values: no-build, no-install, normal]
28+
mode: String,
2929

3030
#[structopt(long = "no-typescript")]
3131
/// By default a *.d.ts file is generated for the generated JS file, but
@@ -89,7 +89,7 @@ pub fn run_wasm_pack(command: Command, log: &Logger) -> result::Result<(), Error
8989
Command::Init {
9090
path,
9191
scope,
92-
skip_build,
92+
mode,
9393
disable_dts,
9494
target,
9595
debug,
@@ -100,17 +100,18 @@ pub fn run_wasm_pack(command: Command, log: &Logger) -> result::Result<(), Error
100100
"Path: {:?}, Scope: {:?}, Skip build: {}, Disable Dts: {}, Target: {}, Debug: {}",
101101
&path,
102102
&scope,
103-
&skip_build,
103+
&mode,
104104
&disable_dts,
105105
&target,
106106
debug
107107
);
108-
let mode = if skip_build {
109-
InitMode::Nobuild
110-
} else {
111-
InitMode::Normal
108+
let modetype = match &*mode {
109+
"no-build" => InitMode::Nobuild,
110+
"no-install" => InitMode::Noinstall,
111+
"normal" => InitMode::Normal,
112+
_ => InitMode::Normal,
112113
};
113-
Init::new(path, scope, disable_dts, target, debug).process(&log, mode)
114+
Init::new(path, scope, disable_dts, target, debug)?.process(&log, modetype)
114115
}
115116
Command::Pack { path } => {
116117
info!(&log, "Running pack command...");

0 commit comments

Comments
 (0)