-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update args fix debug update defaults
- Loading branch information
Showing
3 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use std::process::{Command, Stdio}; | ||
|
||
use anyhow::Result; | ||
|
||
use crate::{child::spawn_child, cli::GenerateCommand}; | ||
|
||
fn verify_requirements() -> Result<()> { | ||
let output = Command::new("npx") | ||
.arg("--version") | ||
.stdout(Stdio::null()) | ||
.stderr(Stdio::null()) | ||
.status(); | ||
|
||
const ERROR_MSG: &str = "Unable to run generate - missing requirements (npx)"; | ||
match output { | ||
Ok(result) => { | ||
if result.success() { | ||
return Ok(()); | ||
} | ||
return Err(anyhow::anyhow!(ERROR_MSG)); | ||
} | ||
Err(_) => { | ||
return Err(anyhow::anyhow!(ERROR_MSG)); | ||
} | ||
} | ||
} | ||
|
||
fn call_turbo_gen(command: &str, tag: &String, raw_args: &str) -> Result<i32> { | ||
let mut npx = Command::new("npx"); | ||
npx.arg("--yes") | ||
.arg(format!("@turbo/gen@{}", tag)) | ||
.arg("raw") | ||
.arg(command) | ||
.args(["--json", raw_args]) | ||
.stdout(Stdio::inherit()) | ||
.stderr(Stdio::inherit()); | ||
|
||
let child = spawn_child(npx)?; | ||
let exit_code = child.wait()?.code().unwrap_or(2); | ||
Ok(exit_code) | ||
} | ||
|
||
pub fn run(command: &GenerateCommand, tag: &String) -> Result<()> { | ||
// ensure npx is available | ||
verify_requirements()?; | ||
|
||
match command { | ||
GenerateCommand::Add(args) => { | ||
// convert args to json | ||
let raw_args = serde_json::to_string(args)?; | ||
call_turbo_gen("add", tag, &raw_args)?; | ||
} | ||
GenerateCommand::Gen(args) => { | ||
let raw_args = serde_json::to_string(args)?; | ||
call_turbo_gen("generate", tag, &raw_args)?; | ||
} | ||
}; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters