Packages
scaffolder
0.1.0
Scaffolder allows you to easily scaffold folder structure using an elixir map. It also allows you to generate a file. By default all folders or files generated by Scaffolder will be created under lib folder. Behind the scene, Scaffolder implement DFS to scaffold the folders and files.
Current section
Files
Jump to
Current section
Files
lib/scaffolder.ex
defmodule Scaffolder do
@moduledoc """
Scaffolder allows you to easily scaffold folder structure using an elixir map. It also allows
you to generate a file. By default all folders or files generated by Scaffolder will be created
under lib folder. Behind the scene, Scaffolder implement DFS to scaffold the folders and files.
"""
require Logger
@doc """
scaffolds folders and files using an elixir map
"""
def scaffold(structure, dir \\ "./lib") do
structure
|> Map.keys()
|> Enum.each(fn key ->
cond do
is_map(structure[key]) == true ->
Logger.info("Scaffolding " <> dir <> "/#{Atom.to_string(key)}")
File.mkdir(dir <> "/#{Atom.to_string(key)}")
scaffold(structure[key], dir <> "/#{Atom.to_string(key)}")
is_tuple(structure[key]) == true ->
{file_ext, file_content} = structure[key]
case File.regular?(dir <> "/#{Atom.to_string(key)}.#{file_ext}") do
true ->
Logger.info(dir <> "/#{Atom.to_string(key)}.#{file_ext}" <> " already exist")
false ->
Logger.info("Scaffolding " <> dir <> "/#{Atom.to_string(key)}.#{file_ext}")
File.write(dir <> "/#{Atom.to_string(key)}.#{file_ext}", file_content)
end
true ->
case File.regular?(dir <> "/#{Atom.to_string(key)}.#{structure[key]}") do
true ->
Logger.info(dir <> "/#{Atom.to_string(key)}.#{structure[key]}" <> " already exist")
false ->
Logger.info("Scaffolding " <> dir <> "/#{Atom.to_string(key)}.#{structure[key]}")
File.write(dir <> "/#{Atom.to_string(key)}.#{structure[key]}", "")
end
end
end)
end
end