cli: fix windows yarn error (#1965)
* fix windows yarn error * add install_node_modules function
This commit is contained in:
parent
57434279fd
commit
04b988299a
|
@ -589,21 +589,10 @@ fn init(
|
||||||
mocha.write_all(template::ts_mocha(&project_name).as_bytes())?;
|
mocha.write_all(template::ts_mocha(&project_name).as_bytes())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Install node modules.
|
let yarn_result = install_node_modules("yarn")?;
|
||||||
let yarn_result = std::process::Command::new("yarn")
|
|
||||||
.stdout(Stdio::inherit())
|
|
||||||
.stderr(Stdio::inherit())
|
|
||||||
.output()
|
|
||||||
.map_err(|e| anyhow::format_err!("yarn install failed: {}", e.to_string()))?;
|
|
||||||
if !yarn_result.status.success() {
|
if !yarn_result.status.success() {
|
||||||
println!("Failed yarn install will attempt to npm install");
|
println!("Failed yarn install will attempt to npm install");
|
||||||
std::process::Command::new("npm")
|
install_node_modules("npm")?;
|
||||||
.arg("install")
|
|
||||||
.stdout(Stdio::inherit())
|
|
||||||
.stderr(Stdio::inherit())
|
|
||||||
.output()
|
|
||||||
.map_err(|e| anyhow::format_err!("npm install failed: {}", e.to_string()))?;
|
|
||||||
println!("Failed to install node dependencies")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !no_git {
|
if !no_git {
|
||||||
|
@ -623,6 +612,24 @@ fn init(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn install_node_modules(cmd: &str) -> Result<std::process::Output> {
|
||||||
|
if cfg!(target_os = "windows") {
|
||||||
|
std::process::Command::new("cmd")
|
||||||
|
.arg(format!("/C {} install", cmd))
|
||||||
|
.stdout(Stdio::inherit())
|
||||||
|
.stderr(Stdio::inherit())
|
||||||
|
.output()
|
||||||
|
.map_err(|e| anyhow::format_err!("{} install failed: {}", cmd, e.to_string()))
|
||||||
|
} else {
|
||||||
|
std::process::Command::new(cmd)
|
||||||
|
.arg("install")
|
||||||
|
.stdout(Stdio::inherit())
|
||||||
|
.stderr(Stdio::inherit())
|
||||||
|
.output()
|
||||||
|
.map_err(|e| anyhow::format_err!("{} install failed: {}", cmd, e.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Creates a new program crate in the `programs/<name>` directory.
|
// Creates a new program crate in the `programs/<name>` directory.
|
||||||
fn new(cfg_override: &ConfigOverride, name: String) -> Result<()> {
|
fn new(cfg_override: &ConfigOverride, name: String) -> Result<()> {
|
||||||
with_workspace(cfg_override, |cfg| {
|
with_workspace(cfg_override, |cfg| {
|
||||||
|
|
Loading…
Reference in New Issue