Skip to content

Commit 19516b1

Browse files
Adds support for nested module names, closes #24
1 parent 01fa892 commit 19516b1

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

lib/js2e.ex

+13-4
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,18 @@ defmodule JS2E do
9292

9393
@spec create_output_dir(list) :: String.t()
9494
defp create_output_dir(options) do
95-
output_path =
95+
module_name =
9696
if Keyword.has_key?(options, :module_name) do
9797
Keyword.get(options, :module_name)
9898
else
9999
"Data"
100100
end
101101

102-
output_path
102+
module_name
103+
|> String.replace(".", "/")
103104
|> File.mkdir_p!()
104105

105-
output_path
106+
module_name
106107
end
107108

108109
@spec generate([String.t()], String.t()) :: :ok
@@ -127,7 +128,15 @@ defmodule JS2E do
127128
file_dict = printer_result.file_dict
128129

129130
Enum.each(file_dict, fn {file_path, file_content} ->
130-
{:ok, file} = File.open(file_path, [:write])
131+
normalized_file_path =
132+
String.replace(
133+
file_path,
134+
module_name,
135+
String.replace(module_name, ".", "/")
136+
)
137+
138+
Logger.debug("Writing file '#{file_path}'")
139+
{:ok, file} = File.open(normalized_file_path, [:write])
131140
IO.binwrite(file, file_content)
132141
File.close(file)
133142
Logger.info("Created file '#{file_path}'")

0 commit comments

Comments
 (0)