Skip to content

Commit

Permalink
ensure blend dir present
Browse files Browse the repository at this point in the history
  • Loading branch information
grzuy committed Feb 28, 2024
1 parent b69f9f7 commit 3b5b818
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions lib/blend.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,29 @@ defmodule Blend do
"""

@blend_dir "blend"
@blendfile_path "blend.exs"
@blendfile_name "blend.exs"
@blendfile_template File.read!(Path.join(__DIR__, "blend/templates/blend.exs"))
@premix_file_path Path.join(@blend_dir, "premix.exs")
@premix_file_name "premix.exs"
@premix_file_template File.read!(Path.join(__DIR__, "blend/templates/premix.exs"))

def init do
case File.read(@blendfile_path) do
case File.read(@blendfile_name) do
{:ok, _} ->
IO.puts("#{@blendfile_path} file already exists, doing nothing")
IO.puts("#{@blendfile_name} file already exists, doing nothing")

{:error, :enoent} ->
File.write!(@blendfile_path, @blendfile_template)
IO.puts("Successfully created #{@blendfile_path} file")
File.write!(@blendfile_name, @blendfile_template)
IO.puts("Successfully created #{@blendfile_name} file")
end
end

def premix do
File.write!(@premix_file_path, @premix_file_template)
IO.puts("Written #{@premix_file_path} file")
path = Path.join(@blend_dir, @premix_file_name)

File.mkdir_p!(@blend_dir)
File.write!(path, @premix_file_template)

IO.puts("Written #{path} file")
end

def within(blend_id, fun) do
Expand Down Expand Up @@ -56,18 +60,18 @@ defmodule Blend do
end

def blends do
case File.read(@blendfile_path) do
case File.read(@blendfile_name) do
{:ok, contents} ->
case Code.eval_string(contents) do
{%{} = map, _} ->
map

_ ->
raise "Couldn't find a map defining your blends in #{@blendfile_path} file"
raise "Couldn't find a map defining your blends in #{@blendfile_name} file"
end

{:error, :enoent} ->
raise "Couldn't find a #{@blendfile_path} file"
raise "Couldn't find a #{@blendfile_name} file"
end
end
end

0 comments on commit 3b5b818

Please sign in to comment.