Class: Teapot::Command::Visualize::Files

Inherits:
Selection
  • Object
show all
Defined in:
lib/teapot/command/visualize.rb

Overview

Visualize file-level dependencies from the build graph.

Instance Method Summary collapse

Methods inherited from Selection

#call, #selection, #targets

Instance Method Details

#process(selection) ⇒ Object

Process and generate the file dependency visualization.



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/teapot/command/visualize.rb', line 117

def process(selection)
	require "build/graph/walker"
	require "build/graph/visualization"
	
	context = selection.context
	chain = selection.chain
	environment = context.configuration.environment
	
	# Build the controller to get the root nodes
	controller = ::Build::Controller.build(limit: 1) do |builder|
		builder.add_chain(chain, [], environment)
	end
	
	# Create a process group for task execution
	group = ::Process::Group.new
	
	# Create a walker that traverses without building
	walker = ::Build::Graph::Walker.new do |walker, node, parent_task = nil|
		task_class = node.task_class(parent_task) || ::Build::Graph::Task
		task = task_class.new(walker, node, group)
		
		# Use traverse instead of visit to skip building:
		task.traverse
	end
	
	# Populate the walker by traversing from the root nodes
	walker.update(controller.nodes)
	
	# Generate the Mermaid diagram
	visualization = ::Build::Graph::Visualization.new
	diagram = visualization.generate(walker)
	
	if output_path = @options[:output_path]
		File.write(output_path, diagram)
	else
		$stdout.puts diagram
	end
	
	return diagram
end