Created
September 3, 2024 23:00
-
-
Save jakeprem/8a301bd64cd27bd656b8bd84d12aea17 to your computer and use it in GitHub Desktop.
Revisions
-
jakeprem created this gist
Sep 3, 2024 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ defmodule Mix.Tasks.Concat do @shortdoc "Concatenates all Elixir code in the project to a single file" @moduledoc false use Mix.Task def run(args) do {opts, _, _} = OptionParser.parse(args, switches: [output: :string], aliases: [o: :output] ) source_dir = File.cwd!() output_file = opts[:output] || "concatenated_code" concatenate_project(source_dir, output_file) Mix.shell().info("Code concatenated to #{output_file}") end defp concatenate_project(source_dir, output_file) do paths = %{ "podke" => "lib/podke", "podke_web" => "lib/podke_web" } for {name, path} <- paths do output_filename = "#{name}_#{output_file}" # File.write!(output_filename, "", [:write]) source_dir |> Path.join(path) |> Path.join("**/*.{ex,exs}") |> Path.wildcard() |> Enum.sort() |> Enum.each(fn file -> content = File.read!(file) File.write!("#{output_filename}.txt", "# File: #{file}\n\n#{content}\n\n", [ :append ]) end) end end end