mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-22 15:18:12 +08:00
Add the build link bisect tool to the website (#3902)
* Add the bisect tool * Add `cargo run explore` to open bisect tool * Website cleanup * Bug fixes * Fix again
This commit is contained in:
@@ -6,6 +6,7 @@ pub mod requirements;
|
||||
pub enum Action {
|
||||
Run,
|
||||
Build,
|
||||
Explore(Option<String>),
|
||||
}
|
||||
|
||||
pub enum Target {
|
||||
@@ -36,6 +37,7 @@ impl Task {
|
||||
let (action, args) = match args.first() {
|
||||
Some(&"build") => (Action::Build, &args[1..]),
|
||||
Some(&"run") => (Action::Run, &args[1..]),
|
||||
Some(&"explore") => (Action::Explore(args.get(1).map(|s| s.to_string())), &[] as &[&str]),
|
||||
Some(&"help") => return None,
|
||||
_ => (Action::Run, args),
|
||||
};
|
||||
@@ -74,6 +76,34 @@ pub fn npm_run_in_frontend_dir(args: &str) -> Result<(), Error> {
|
||||
run_from(&format!("{npm} run {args}"), Some(&frontend_dir))
|
||||
}
|
||||
|
||||
pub fn open_url(url: &str) -> Result<(), Error> {
|
||||
#[cfg(target_os = "windows")]
|
||||
let mut cmd = process::Command::new("cmd");
|
||||
#[cfg(target_os = "windows")]
|
||||
cmd.args(["/c", "start", url]);
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
let mut cmd = process::Command::new("open");
|
||||
#[cfg(target_os = "macos")]
|
||||
cmd.arg(url);
|
||||
|
||||
#[cfg(not(any(target_os = "windows", target_os = "macos")))]
|
||||
let mut cmd = process::Command::new("xdg-open");
|
||||
#[cfg(not(any(target_os = "windows", target_os = "macos")))]
|
||||
cmd.arg(url);
|
||||
|
||||
let command_str = format!("{:?}", cmd);
|
||||
let exit_code = cmd
|
||||
.spawn()
|
||||
.map_err(|e| Error::Io(e, format!("Failed to spawn command '{command_str}'")))?
|
||||
.wait()
|
||||
.map_err(|e| Error::Io(e, format!("Failed to wait for command '{command_str}'")))?;
|
||||
if !exit_code.success() {
|
||||
return Err(Error::Command(command_str, exit_code));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn run_from(command: &str, dir: Option<&PathBuf>) -> Result<(), Error> {
|
||||
let command = command.split_whitespace().collect::<Vec<_>>();
|
||||
let mut cmd = process::Command::new(command[0]);
|
||||
|
||||
@@ -15,6 +15,7 @@ fn usage() {
|
||||
println!("<command>:");
|
||||
println!(" [run] Run the selected target (default)");
|
||||
println!(" build Build the selected target");
|
||||
println!(" explore Open an assortment of tools for exploring the codebase");
|
||||
println!(" help Show this message");
|
||||
println!("<target>:");
|
||||
println!(" [web] Web app (default)");
|
||||
@@ -50,7 +51,35 @@ fn main() -> ExitCode {
|
||||
ExitCode::SUCCESS
|
||||
}
|
||||
|
||||
fn explore_usage() {
|
||||
println!();
|
||||
println!("USAGE:");
|
||||
println!(" cargo run explore <tool>");
|
||||
println!();
|
||||
println!("OPTIONS:");
|
||||
println!("<tool>:");
|
||||
println!(" bisect Binary search through recent commits to find which introduced a bug or feature");
|
||||
println!(" editor View an interactive outline of the editor's message system architecture");
|
||||
println!();
|
||||
}
|
||||
|
||||
fn run_task(task: &Task) -> Result<(), Error> {
|
||||
if let Action::Explore(tool) = &task.action {
|
||||
match tool.as_deref() {
|
||||
Some("bisect") => return open_url("https://graphite.art/volunteer/guide/codebase-overview/debugging-tips/#build-bisect-tool"),
|
||||
Some("editor") => return open_url("https://graphite.art/volunteer/guide/codebase-overview/editor-structure/#editor-outline"),
|
||||
None | Some("--help") => {
|
||||
explore_usage();
|
||||
return Ok(());
|
||||
}
|
||||
Some(other) => {
|
||||
eprintln!("Unknown explore tool: '{other}'");
|
||||
explore_usage();
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
requirements::check(task)?;
|
||||
|
||||
match (&task.action, &task.target, &task.profile) {
|
||||
@@ -65,6 +94,7 @@ fn run_task(task: &Task) -> Result<(), Error> {
|
||||
profile = match action {
|
||||
Action::Run => &Profile::Debug,
|
||||
Action::Build => &Profile::Release,
|
||||
Action::Explore(_) => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,6 +124,8 @@ fn run_task(task: &Task) -> Result<(), Error> {
|
||||
|
||||
(Action::Build, Target::Cli, Profile::Debug) => run("cargo build -p graphene-cli")?,
|
||||
(Action::Build, Target::Cli, Profile::Release | Profile::Default) => run("cargo build -r -p graphene-cli")?,
|
||||
|
||||
(Action::Explore(_), _, _) => unreachable!(),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user