-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new: Add
moon action-graph
command. (#1101)
* Add action. * Update app. * Update tests. * Update docs. * Polish. * Polish.
- Loading branch information
Showing
20 changed files
with
292 additions
and
244 deletions.
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
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,75 @@ | ||
use crate::commands::graph::utils::{action_graph_repr, respond_to_request, setup_server}; | ||
use clap::Args; | ||
use miette::IntoDiagnostic; | ||
use moon::{build_dep_graph, generate_project_graph}; | ||
use moon_target::TargetLocator; | ||
use moon_workspace::Workspace; | ||
use starbase::{system, SystemResult}; | ||
|
||
#[derive(Args, Clone, Debug)] | ||
pub struct ActionGraphArgs { | ||
#[arg(help = "Target to *only* graph")] | ||
target: Option<TargetLocator>, | ||
|
||
#[arg(long, help = "Print the graph in DOT format")] | ||
dot: bool, | ||
|
||
#[arg(long, help = "Print the graph in JSON format")] | ||
json: bool, | ||
} | ||
|
||
pub async fn internal_action_graph( | ||
args: &ActionGraphArgs, | ||
workspace: &mut Workspace, | ||
) -> SystemResult { | ||
let project_graph = generate_project_graph(workspace).await?; | ||
let mut action_graph_builder = build_dep_graph(&project_graph); | ||
|
||
// Focus a target and its dependencies/dependents | ||
if let Some(locator) = args.target.clone() { | ||
for target in action_graph_builder.run_targets_by_locator(&[locator], None)? { | ||
action_graph_builder.run_dependents_for_target(&target)?; | ||
} | ||
|
||
// Show all targets and actions | ||
} else { | ||
for project in project_graph.get_all_unexpanded() { | ||
for task in project.tasks.values() { | ||
action_graph_builder.run_target(&task.target, None)?; | ||
} | ||
} | ||
} | ||
|
||
let action_graph = action_graph_builder.build(); | ||
|
||
if args.dot { | ||
println!("{}", action_graph.to_dot()); | ||
|
||
return Ok(()); | ||
} | ||
|
||
let graph_info = action_graph_repr(&action_graph).await; | ||
|
||
if args.json { | ||
println!("{}", serde_json::to_string(&graph_info).into_diagnostic()?); | ||
|
||
return Ok(()); | ||
} | ||
|
||
let (server, mut tera) = setup_server().await?; | ||
let url = format!("http://{}", server.server_addr()); | ||
let _ = open::that(&url); | ||
|
||
println!("Started server on {url}"); | ||
|
||
for req in server.incoming_requests() { | ||
respond_to_request(req, &mut tera, &graph_info, "Action graph".to_owned())?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
#[system] | ||
pub async fn action_graph(args: ArgsRef<ActionGraphArgs>, workspace: ResourceMut<Workspace>) { | ||
internal_action_graph(args, workspace).await?; | ||
} |
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 |
---|---|---|
@@ -1,66 +1,15 @@ | ||
use crate::commands::graph::utils::{dep_graph_repr, respond_to_request, setup_server}; | ||
use clap::Args; | ||
use miette::IntoDiagnostic; | ||
use moon::{build_dep_graph, generate_project_graph}; | ||
use moon_target::TargetLocator; | ||
use super::action::*; | ||
use moon_common::color; | ||
use moon_workspace::Workspace; | ||
use starbase::system; | ||
|
||
#[derive(Args, Clone, Debug)] | ||
pub struct DepGraphArgs { | ||
#[arg(help = "Target to *only* graph")] | ||
target: Option<TargetLocator>, | ||
|
||
#[arg(long, help = "Print the graph in DOT format")] | ||
dot: bool, | ||
|
||
#[arg(long, help = "Print the graph in JSON format")] | ||
json: bool, | ||
} | ||
use tracing::warn; | ||
|
||
#[system] | ||
pub async fn dep_graph(args: ArgsRef<DepGraphArgs>, workspace: ResourceMut<Workspace>) { | ||
let project_graph = generate_project_graph(workspace).await?; | ||
let mut dep_builder = build_dep_graph(&project_graph); | ||
|
||
// Focus a target and its dependencies/dependents | ||
if let Some(locator) = args.target.clone() { | ||
for target in dep_builder.run_targets_by_locator(&[locator], None)? { | ||
dep_builder.run_dependents_for_target(&target)?; | ||
} | ||
|
||
// Show all targets and actions | ||
} else { | ||
for project in project_graph.get_all_unexpanded() { | ||
for task in project.tasks.values() { | ||
dep_builder.run_target(&task.target, None)?; | ||
} | ||
} | ||
} | ||
|
||
let dep_graph = dep_builder.build(); | ||
|
||
if args.dot { | ||
println!("{}", dep_graph.to_dot()); | ||
|
||
return Ok(()); | ||
} | ||
|
||
let graph_info = dep_graph_repr(&dep_graph).await; | ||
|
||
if args.json { | ||
println!("{}", serde_json::to_string(&graph_info).into_diagnostic()?); | ||
|
||
return Ok(()); | ||
} | ||
|
||
let (server, mut tera) = setup_server().await?; | ||
let url = format!("http://{}", server.server_addr()); | ||
let _ = open::that(&url); | ||
|
||
println!("Started server on {url}"); | ||
pub async fn dep_graph(args: ArgsRef<ActionGraphArgs>, workspace: ResourceMut<Workspace>) { | ||
warn!( | ||
"This command is deprecated. Use {} instead.", | ||
color::shell("moon action-graph") | ||
); | ||
|
||
for req in server.incoming_requests() { | ||
respond_to_request(req, &mut tera, &graph_info, "Dependency graph".to_owned())?; | ||
} | ||
internal_action_graph(args, workspace).await?; | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod action; | ||
pub mod dep; | ||
mod dto; | ||
pub mod project; | ||
|
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
Oops, something went wrong.