From f8d66dd2b4435c8dc6586ff5865a30e6dd176fed Mon Sep 17 00:00:00 2001 From: Daniel Kukula Date: Sun, 21 Mar 2021 08:42:51 +0000 Subject: [PATCH 1/3] update dependencies --- mix.lock | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mix.lock b/mix.lock index 06ab67c..6bbd426 100644 --- a/mix.lock +++ b/mix.lock @@ -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"}, } From 2a925f48b53084fa7b29892725743b8f3a0eb881 Mon Sep 17 00:00:00 2001 From: Daniel Kukula Date: Sun, 21 Mar 2021 09:02:38 +0000 Subject: [PATCH 2/3] use projections.json from file for mix projects --- .projections.json | 132 ++++++++++++++++++++++++++++++- lib/ex_projections/gen_data.ex | 16 ++-- lib/projections.json | 140 +++++++++++++++++++++++++++++++++ 3 files changed, 277 insertions(+), 11 deletions(-) create mode 100644 lib/projections.json diff --git a/.projections.json b/.projections.json index 2f43fb6..b15f163 100644 --- a/.projections.json +++ b/.projections.json @@ -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\"\"\"", + "
", + " Hello from {basename}", + "
", + " \"\"\"", + " 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" } } diff --git a/lib/ex_projections/gen_data.ex b/lib/ex_projections/gen_data.ex index c5a8c96..dd65bf3 100644 --- a/lib/ex_projections/gen_data.ex +++ b/lib/ex_projections/gen_data.ex @@ -1,15 +1,6 @@ defmodule ExProjections.GenData do def mix_project do - %{ - "lib/*.ex" => %{ - "alternate" => "test/{}_test.exs", - "type" => "src" - }, - "test/*_test.exs" => %{ - "alternate" => "lib/{}.ex", - "type" => "test" - } - } + read_projections("lib/projections.json") end def umbrella_project(list) do @@ -40,4 +31,9 @@ defmodule ExProjections.GenData do } } end + + def read_projections(path) do + File.read!(path) + |> Jason.decode!() + end end diff --git a/lib/projections.json b/lib/projections.json new file mode 100644 index 0000000..7e7c560 --- /dev/null +++ b/lib/projections.json @@ -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\"\"\"", + "
", + " Hello from {basename}", + "
", + " \"\"\"", + " 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 %>" + ] + } +} From bf8d503d621208afb8e83a3fe953d0fb74291a44 Mon Sep 17 00:00:00 2001 From: Daniel Kukula Date: Sun, 21 Mar 2021 09:57:50 +0000 Subject: [PATCH 3/3] use projections.json from file for umbrella projects --- lib/ex_projections/gen_data.ex | 38 ++++++++++++++++------------------ lib/ex_projections/write.ex | 1 - {lib => priv}/projections.json | 0 3 files changed, 18 insertions(+), 21 deletions(-) rename {lib => priv}/projections.json (100%) diff --git a/lib/ex_projections/gen_data.ex b/lib/ex_projections/gen_data.ex index dd65bf3..e604f82 100644 --- a/lib/ex_projections/gen_data.ex +++ b/lib/ex_projections/gen_data.ex @@ -1,35 +1,33 @@ defmodule ExProjections.GenData do + @projections_path Path.join(:code.priv_dir(:ex_projections), "projections.json") + def mix_project do - read_projections("lib/projections.json") + 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 - defp all_map(dir, acc) do - acc - |> Map.merge(src_map(dir)) - |> Map.merge(test_map(dir)) + def generate_umbrella_entry(app_path, {k, v}) do + {get_new_path(app_path, k), maybe_update_alternate(app_path, v)} end - defp src_map(dir) do - %{ - "apps/#{dir}/lib/*.ex" => %{ - "type" => "src", - "alternate" => "apps/#{dir}/test/{}_test.exs" - } - } + def get_new_path(app_path, template) do + app_path <> "/" <> template end - defp test_map(dir) do - %{ - "apps/#{dir}/test/*_test.exs" => %{ - "type" => "src", - "alternate" => "apps/#{dir}/lib/{}.ex" - } - } + 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 def read_projections(path) do diff --git a/lib/ex_projections/write.ex b/lib/ex_projections/write.ex index 1eeb0fc..bac075f 100644 --- a/lib/ex_projections/write.ex +++ b/lib/ex_projections/write.ex @@ -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 diff --git a/lib/projections.json b/priv/projections.json similarity index 100% rename from lib/projections.json rename to priv/projections.json