Skip to content

Commit

Permalink
Create paths at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
amclain committed Oct 22, 2023
1 parent 899f22f commit 16bda7e
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/mix/tasks/compiler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ defmodule Mix.Tasks.Compile.Speck do

use Mix.Task.Compiler

@schema_path Application.compile_env(:speck, :schema_path, "protocol")
@manifest_path Path.join(Mix.Project.app_path, "speck.manifest")

@impl Mix.Task.Compiler
def run(_args) do
schema_files = Path.wildcard("#{@schema_path}/**/*.ex")
schema_path = Application.get_env(:speck, :schema_path, "protocol")
schema_files = Path.wildcard("#{schema_path}/**/*.ex")
hashes = hashes(schema_files)
manifest = load_manifest()

Expand Down Expand Up @@ -90,12 +88,16 @@ defmodule Mix.Tasks.Compile.Speck do

@impl Mix.Task.Compiler
def manifests do
[@manifest_path]
[manifest_path()]
end

@impl Mix.Task.Compiler
def clean do
File.rm_rf(@manifest_path)
File.rm_rf(manifest_path())
end

defp manifest_path do
Path.join(Mix.Project.app_path, "speck.manifest")
end

defp module_path(module) do
Expand Down Expand Up @@ -206,15 +208,15 @@ defmodule Mix.Tasks.Compile.Speck do
end

defp load_manifest do
case File.read(@manifest_path) do
case File.read(manifest_path()) do
{:ok, contents} -> :erlang.binary_to_term(contents)
{:error, :enoent} -> []
{:error, reason} -> raise "Failed to load manifest: #{reason}"
end
end

defp save_manifest(manifest) do
File.write!(@manifest_path, :erlang.term_to_binary(manifest))
File.write!(manifest_path(), :erlang.term_to_binary(manifest))
end

defp coerce(:date, value) when is_binary(value) do
Expand Down

0 comments on commit 16bda7e

Please sign in to comment.