-
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.
Co-authored-by: Nicholas Yang <nicholas.yang@vercel.com>
- Loading branch information
1 parent
5959a11
commit 3e1c136
Showing
5 changed files
with
131 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,54 @@ | ||
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(); | ||
|
||
match output { | ||
Ok(result) if result.success() => Ok(()), | ||
_ => Err(anyhow::anyhow!( | ||
"Unable to run generate - missing requirements (npx)" | ||
)), | ||
} | ||
} | ||
|
||
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::Custom(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
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
3e1c136
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
turbo-site – ./docs
www.turbopack.org
turbo.vercel.sh
turborepo.org
turbo.build
www.turborepo.com
www.turbo.build
turbopack.org
turbo-site.vercel.sh
www.turborepo.org
turbo-site-git-main.vercel.sh
turbo.vercel.app