This is my naive attempt (you can mock, laugh, or help guide me, but i’m good with any of them :
debug_rewrite = fn ->
# Create igniter instance with the install task
igniter = Igniter.new()
|> Igniter.compose_task(Mix.Task.get("igniter.install"), [
"ash_phoenix",
"ash_json_api",
"ash_postgres",
"ash_authentication",
"ash_authentication_phoenix",
"ash_csv",
"ash_state_machine",
"ash_paper_trail",
"cloak",
"ash_cloak"
])
# Get current directory
current_dir = File.cwd!()
IO.puts("\n=== Current Directory ===")
IO.puts(current_dir)
# Inspect the initial igniter state
IO.puts("\n=== Initial Igniter State ===")
IO.inspect(igniter, label: "Initial igniter", pretty: true)
# Check Rewrite state before any operations
IO.puts("\n=== Initial Rewrite State ===")
IO.inspect(igniter.rewrite, label: "Initial rewrite state", pretty: true)
# Try to get source for application.ex
app_path = Path.join([current_dir, "lib", "hillbilly_millionaire", "application.ex"])
IO.puts("\n=== Attempting to get source for application.ex ===")
try do
source = Rewrite.source!(igniter.rewrite, app_path)
IO.inspect(source, label: "Source for application.ex", pretty: true)
# Get file contents
file = File.read!(app_path)
igniter_original_contents = Rewrite.Source.get(source, :content, 1)
IO.puts("\n=== Path Comparison ===")
IO.inspect(Rewrite.Source.get(source, :path, 1), label: "Source path v1")
IO.inspect(Rewrite.Source.get(source, :path), label: "Source path current")
IO.puts("\n=== Hash Comparison ===")
IO.inspect(source.hash, label: "Source hash")
IO.inspect(:erlang.phash2({app_path, file}), label: "Current file hash")
IO.inspect(:erlang.phash2({app_path, igniter_original_contents}), label: "Original content hash")
IO.puts("\n=== Content Comparison ===")
IO.puts("Original content:")
IO.puts(igniter_original_contents)
IO.puts("\nCurrent file content:")
IO.puts(file)
rescue
e ->
IO.puts("Error getting source: #{inspect(e)}")
IO.inspect(igniter.rewrite.sources, label: "All sources in rewrite state", pretty: true)
end
# Return the final igniter state
IO.puts("\n=== Final Igniter State ===")
IO.inspect(igniter, limit: :infinity, pretty: true)
# Return the igniter for further inspection
igniter
end
and get the following:
iex(2)> debug_rewrite.()
=== Current Directory ===
/home/hunsazk/Documents/Github/hillbilly_millionaire
=== Initial Igniter State ===
Initial igniter: #Igniter<rewrite: #Rewrite<1 source(s)>>
=== Initial Rewrite State ===
Initial rewrite state: #Rewrite<1 source(s)>
=== Attempting to get source for application.ex ===
Error getting source: %Rewrite.Error{reason: :nosource, path: “/home/hunsazk/Documents/Github/hillbilly_millionaire/lib/hillbilly_millionaire/application.ex”, missing_paths: nil, duplicated_paths: nil, message: nil}
All sources in rewrite state: %{“.igniter.exs” => #Rewrite.Source<.igniter.exs>}
=== Final Igniter State ===
#Igniter<rewrite: #Rewrite<1 source(s)>>
#Igniter<rewrite: #Rewrite<1 source(s)>>
iex(3)> result = debug_rewrite.()
=== Current Directory ===
/home/hunsazk/Documents/Github/hillbilly_millionaire
=== Initial Igniter State ===
Initial igniter: #Igniter<rewrite: #Rewrite<1 source(s)>>
=== Initial Rewrite State ===
Initial rewrite state: #Rewrite<1 source(s)>
=== Attempting to get source for application.ex ===
Error getting source: %Rewrite.Error{reason: :nosource, path: “/home/hunsazk/Documents/Github/hillbilly_millionaire/lib/hillbilly_millionaire/application.ex”, missing_paths: nil, duplicated_paths: nil, message: nil}
All sources in rewrite state: %{“.igniter.exs” => #Rewrite.Source<.igniter.exs>}
=== Final Igniter State ===
#Igniter<rewrite: #Rewrite<1 source(s)>>
#Igniter<rewrite: #Rewrite<1 source(s)>>
iex(4)> IO.inspect(result.rewrite.sources, label: “All sources”, limit: :infinity, pretty: true)
All sources: %{“.igniter.exs” => #Rewrite.Source<.igniter.exs>}
%{“.igniter.exs” => #Rewrite.Source<.igniter.exs>}