Skip to content

Update projections #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 131 additions & 1 deletion .projections.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,140 @@
{
"*_live.ex": {
"alternate": "test/{dirname}/live/{basename}_live_test.exs",
"related": [
"{dirname|dirname|dirname}/live/{dirname|basename}_live.html.leex"
],
"template": [
"defmodule Web.{basename|camelcase|capitalize}Live do",
" use Phoenix.LiveView",
"",
" def render(assigns) do",
" ~L\"\"\"",
" <div class=\"\">",
" Hello from {basename}",
" </div>",
" \"\"\"",
" end",
"",
" def mount(_params, _session, socket) do",
" {open}:ok, socket{close}",
" end",
"end"
],
"type": "live"
},
"*_view.ex": {
"alternate": "test/{dirname}/views/{basename}_view_test.exs",
"template": [
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}View do",
" use {dirname|camelcase|capitalize}, :view",
"end"
],
"type": "view"
},
"*eex": {
"related": [
"{dirname|dirname|dirname}/controllers/{dirname|basename}_controller.ex",
"{dirname|dirname|dirname}/views/{dirname|basename}_view.ex"
],
"template": [
"<%# {basename} eex template %>"
],
"type": "template"
},
"*leex": {
"related": [
"{dirname|dirname|dirname}/controllers/{dirname|basename}_controller.ex",
"{dirname|dirname|dirname}/live/{dirname|basename}_live.ex"
],
"template": [
"<%# {basename} leex template %>"
],
"type": "template"
},
"lib/**/channels/*_channel.ex": {
"alternate": "test/{dirname}/channels/{basename}_channel_test.exs",
"template": [
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}Channel do",
" use {dirname|camelcase|capitalize}, :channel",
"end"
],
"type": "channel"
},
"lib/**/controllers/*_controller.ex": {
"alternate": "test/{dirname}/controllers/{basename}_controller_test.exs",
"template": [
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}Controller do",
" use {dirname|camelcase|capitalize}, :controller",
"end"
],
"type": "controller"
},
"lib/**/views/*_view.ex": {
"alternate": "test/{dirname}/views/{basename}_view_test.exs",
"template": [
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}View do",
" use {dirname|camelcase|capitalize}, :view",
"end"
],
"type": "view"
},
"lib/*.ex": {
"alternate": "test/{}_test.exs",
"type": "src"
"template": [
"defmodule {camelcase|capitalize|dot} do",
"end"
],
"type": "source"
},
"test/**/channels/*_channel_test.exs": {
"alternate": "lib/{dirname}/channels/{basename}_channel.ex",
"template": [
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}ChannelTest do",
" use {dirname|camelcase|capitalize}.ChannelCase, async: true",
"",
" alias {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}Channel",
"end"
],
"type": "test"
},
"test/**/controllers/*_controller_test.exs": {
"alternate": "lib/{dirname}/controllers/{basename}_controller.ex",
"template": [
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}ControllerTest do",
" use {dirname|camelcase|capitalize}.ConnCase, async: true",
"end"
],
"type": "test"
},
"test/**/features/*_test.exs": {
"template": [
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}Test do",
" use {dirname|camelcase|capitalize}.FeatureCase, async: true",
"end"
],
"type": "feature"
},
"test/**/views/*_view_test.exs": {
"alternate": "lib/{dirname}/views/{basename}_view.ex",
"template": [
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}ViewTest do",
" use ExUnit.Case, async: true",
"",
" alias {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}View",
"end"
],
"type": "test"
},
"test/*_test.exs": {
"alternate": "lib/{}.ex",
"template": [
"defmodule {camelcase|capitalize|dot}Test do",
" use ExUnit.Case, async: true",
"",
" alias {camelcase|capitalize|dot}",
"end"
],
"type": "test"
}
}
52 changes: 23 additions & 29 deletions lib/ex_projections/gen_data.ex
Original file line number Diff line number Diff line change
@@ -1,43 +1,37 @@
defmodule ExProjections.GenData do
@projections_path Path.join(:code.priv_dir(:ex_projections), "projections.json")

def mix_project do
%{
"lib/*.ex" => %{
"alternate" => "test/{}_test.exs",
"type" => "src"
},
"test/*_test.exs" => %{
"alternate" => "lib/{}.ex",
"type" => "test"
}
}
read_projections(@projections_path)
end

def umbrella_project(list) do
list
|> Enum.reduce(%{}, &all_map/2)
|> Enum.flat_map(fn app_path ->
read_projections(@projections_path)
|> Enum.map(&generate_umbrella_entry(app_path, &1))
end)
|> Map.new()
end

def generate_umbrella_entry(app_path, {k, v}) do
{get_new_path(app_path, k), maybe_update_alternate(app_path, v)}
end

defp all_map(dir, acc) do
acc
|> Map.merge(src_map(dir))
|> Map.merge(test_map(dir))
def get_new_path(app_path, template) do
app_path <> "/" <> template
end

defp src_map(dir) do
%{
"apps/#{dir}/lib/*.ex" => %{
"type" => "src",
"alternate" => "apps/#{dir}/test/{}_test.exs"
}
}
def maybe_update_alternate(app_path, template) do
if Map.has_key?(template, "alternate") do
Map.update!(template, "alternate", &get_new_path(app_path, &1))
else
template
end
end

defp test_map(dir) do
%{
"apps/#{dir}/test/*_test.exs" => %{
"type" => "src",
"alternate" => "apps/#{dir}/lib/{}.ex"
}
}
def read_projections(path) do
File.read!(path)
|> Jason.decode!()
end
end
1 change: 0 additions & 1 deletion lib/ex_projections/write.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ defmodule ExProjections.Write do
IO.write("Umbrella project - ")

Path.wildcard("apps/*")
|> Enum.map(&(String.split(&1, "/") |> List.last()))
|> ExProjections.GenData.umbrella_project()
end

Expand Down
14 changes: 8 additions & 6 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
%{
"earmark": {:hex, :earmark, "1.3.2", "b840562ea3d67795ffbb5bd88940b1bed0ed9fa32834915125ea7d02e35888a5", [:mix], [], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.20.2", "1bd0dfb0304bade58beb77f20f21ee3558cc3c753743ae0ddbb0fd7ba2912331", [:mix], [{:earmark, "~> 1.3", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"},
"jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"},
"earmark": {:hex, :earmark, "1.3.2", "b840562ea3d67795ffbb5bd88940b1bed0ed9fa32834915125ea7d02e35888a5", [:mix], [], "hexpm", "e3be2bc3ae67781db529b80aa7e7c49904a988596e2dbff897425b48b3581161"},
"earmark_parser": {:hex, :earmark_parser, "1.4.12", "b245e875ec0a311a342320da0551da407d9d2b65d98f7a9597ae078615af3449", [:mix], [], "hexpm", "711e2cc4d64abb7d566d43f54b78f7dc129308a63bc103fbd88550d2174b3160"},
"ex_doc": {:hex, :ex_doc, "0.24.0", "2df14354835afaabdf87cb2971ea9485d8a36ff590e4b6c250b4f60c8fdf9143", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "a0f4bcff21ceebea48414e49885d2a3e542200f76a2facf3f8faa54935eeb721"},
"jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"},
"json": {:hex, :json, "1.3.0", "2c6bac5303713d1b43ca6f3c881767f57b2adf668cde3013bd7157dc65ef299c", [:mix], [], "hexpm"},
"makeup": {:hex, :makeup, "0.8.0", "9cf32aea71c7fe0a4b2e9246c2c4978f9070257e5c9ce6d4a28ec450a839b55f", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"},
"makeup_elixir": {:hex, :makeup_elixir, "0.13.0", "be7a477997dcac2e48a9d695ec730b2d22418292675c75aa2d34ba0909dcdeda", [:mix], [{:makeup, "~> 0.8", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"},
"nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm"},
"makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"},
"makeup_elixir": {:hex, :makeup_elixir, "0.15.1", "b5888c880d17d1cc3e598f05cdb5b5a91b7b17ac4eaf5f297cb697663a1094dd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "db68c173234b07ab2a07f645a5acdc117b9f99d69ebf521821d89690ae6c6ec8"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
"nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"},
"poison": {:hex, :poison, "4.0.1", "bcb755a16fac91cad79bfe9fc3585bb07b9331e50cfe3420a24bcc2d735709ae", [:mix], [], "hexpm"},
}
140 changes: 140 additions & 0 deletions priv/projections.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
{
"lib/**/views/*_view.ex": {
"type": "view",
"alternate": "test/{dirname}/views/{basename}_view_test.exs",
"template": [
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}View do",
" use {dirname|camelcase|capitalize}, :view",
"end"
]
},
"test/**/views/*_view_test.exs": {
"alternate": "lib/{dirname}/views/{basename}_view.ex",
"type": "test",
"template": [
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}ViewTest do",
" use ExUnit.Case, async: true",
"",
" alias {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}View",
"end"
]
},
"lib/**/controllers/*_controller.ex": {
"type": "controller",
"alternate": "test/{dirname}/controllers/{basename}_controller_test.exs",
"template": [
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}Controller do",
" use {dirname|camelcase|capitalize}, :controller",
"end"
]
},
"test/**/controllers/*_controller_test.exs": {
"alternate": "lib/{dirname}/controllers/{basename}_controller.ex",
"type": "test",
"template": [
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}ControllerTest do",
" use {dirname|camelcase|capitalize}.ConnCase, async: true",
"end"
]
},
"lib/**/channels/*_channel.ex": {
"type": "channel",
"alternate": "test/{dirname}/channels/{basename}_channel_test.exs",
"template": [
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}Channel do",
" use {dirname|camelcase|capitalize}, :channel",
"end"
]
},
"test/**/channels/*_channel_test.exs": {
"alternate": "lib/{dirname}/channels/{basename}_channel.ex",
"type": "test",
"template": [
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}ChannelTest do",
" use {dirname|camelcase|capitalize}.ChannelCase, async: true",
"",
" alias {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}Channel",
"end"
]
},
"test/**/features/*_test.exs": {
"type": "feature",
"template": [
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}Test do",
" use {dirname|camelcase|capitalize}.FeatureCase, async: true",
"end"
]
},
"lib/*.ex": {
"alternate": "test/{}_test.exs",
"type": "source",
"template": [
"defmodule {camelcase|capitalize|dot} do",
"end"
]
},
"test/*_test.exs": {
"alternate": "lib/{}.ex",
"type": "test",
"template": [
"defmodule {camelcase|capitalize|dot}Test do",
" use ExUnit.Case, async: true",
"",
" alias {camelcase|capitalize|dot}",
"end"
]
},
"*_live.ex": {
"type": "live",
"alternate": "test/{dirname}/live/{basename}_live_test.exs",
"related": [
"{dirname|dirname|dirname}/live/{dirname|basename}_live.html.leex"
],
"template": [
"defmodule Web.{basename|camelcase|capitalize}Live do",
" use Phoenix.LiveView",
"",
" def render(assigns) do",
" ~L\"\"\"",
" <div class=\"\">",
" Hello from {basename}",
" </div>",
" \"\"\"",
" end",
"",
" def mount(_params, _session, socket) do",
" {open}:ok, socket{close}",
" end",
"end"
]
},
"*_view.ex": {
"type": "view",
"alternate": "test/{dirname}/views/{basename}_view_test.exs",
"template": [
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}View do",
" use {dirname|camelcase|capitalize}, :view",
"end"
]
},
"*eex": {
"type": "template",
"related": [
"{dirname|dirname|dirname}/controllers/{dirname|basename}_controller.ex",
"{dirname|dirname|dirname}/views/{dirname|basename}_view.ex"
],
"template": [
"<%# {basename} eex template %>"
]
},
"*leex": {
"type": "template",
"related": [
"{dirname|dirname|dirname}/controllers/{dirname|basename}_controller.ex",
"{dirname|dirname|dirname}/live/{dirname|basename}_live.ex"
],
"template": [
"<%# {basename} leex template %>"
]
}
}