rust_to_npm/generators/
pre_install.rs

1pub use super::generate_installs;
2
3/// create the pre-install script for the repo
4pub fn generate_pre_install(name: &String, version: &String, source: &bool) -> String {
5    let install_cmd = if source == &true {
6        format!(r#"`cargo install --path ./node_modules/{name} ${{features}}`"#)
7    } else {
8        format!(r#"`cargo install {name} --vers {version} ${{features}}`"#)
9    };
10
11    format!(
12        r#"{}
13const features = process.env.npm_config_features ? `--features ${{process.env.npm_config_features.replace(",", " ")}}` : ""; 
14
15console.log(`Installing and compiling {name} {version} ${{features}} ...`);
16exec({install_cmd}, (error, stdout, stderr) => {{
17  console.log(stdout);
18  if (error || stderr) {{
19    console.log(error || stderr);
20  }} else {{
21    console.log("install finished!");
22  }}
23}});
24
25    "#,
26        generate_installs()
27    )
28}