Skip to content

Commit 3a31c76

Browse files
committed
Add a prototype of task and templates
1 parent 74dbe86 commit 3a31c76

8 files changed

Lines changed: 60 additions & 7 deletions

File tree

lib/mix/tasks/membrane.new.ex

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
defmodule Mix.Tasks.Membrane.Component.New do
2+
@moduledoc """
3+
$ mix membrane.component.new PATH [--source | --sink | --filter | --endpoint | --bin | --pipeline MODULE]...
4+
"""
5+
use Mix.Task
6+
7+
@switches [
8+
source: :string,
9+
sink: :string,
10+
filter: :string,
11+
endpoint: :string,
12+
bin: :string,
13+
pipeline: :string
14+
]
15+
16+
@impl true
17+
def run(argv) do
18+
{components, argv} = OptionParser.parse!(argv, strict: @switches)
19+
20+
base_dir =
21+
case argv do
22+
[] -> File.cwd!()
23+
[path | _rest] -> Path.expand(path)
24+
end
25+
26+
Enum.map(components, fn {type, module_name} ->
27+
component_path =
28+
module_name
29+
|> String.split(".")
30+
|> Enum.map(&String.downcase/1)
31+
|> List.update_at(-1, &"#{&1}.ex")
32+
|> Path.join()
33+
|> then(&Path.join(base_dir, &1))
34+
35+
File.mkdir_p!(Path.dirname(component_path))
36+
File.write!(component_path, get_component(type, module_name))
37+
end)
38+
end
39+
40+
defp get_component(type, module_name) do
41+
template =
42+
"../../../templates"
43+
|> Path.expand(__DIR__)
44+
|> Path.join(Atom.to_string(type) <> ".ex")
45+
|> File.read!()
46+
47+
template
48+
|> String.split("\n")
49+
|> List.replace_at(0, "defmodule Membrane.#{:string.titlecase(module_name)} do")
50+
|> Enum.join("\n")
51+
end
52+
end

templates/bin.ex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
defmodule Membrane.TemplateBin do
2+
@moduledoc """
3+
Template bin
4+
"""
5+
use Membrane.Bin
6+
7+
8+
end

templates/endpoint.ex

Whitespace-only changes.

templates/filter.ex

Whitespace-only changes.

templates/pipeline.ex

Whitespace-only changes.

templates/sink.ex

Whitespace-only changes.

templates/source.ex

Whitespace-only changes.

0 commit comments

Comments
 (0)