@@ -26,7 +26,8 @@ defmodule ElixirScript.Output do
2626 end )
2727 |> Enum . map ( fn
2828 { module , name , path } ->
29- { module , name , Path . join ( opts . root , path ) }
29+ import_path = Path . join ( opts . root , path )
30+ { module , name , path , import_path }
3031 end )
3132
3233 bundle ( modules , opts , js_modules )
@@ -82,7 +83,7 @@ defmodule ElixirScript.Output do
8283
8384 apps = get_app_names ( )
8485 output_dir = Path . dirname ( file_name )
85- Enum . each ( js_modules , fn ( { _ , _ , path } ) ->
86+ Enum . each ( js_modules , fn ( { _ , _ , path , _ } ) ->
8687 copy_javascript_module ( apps , output_dir , path )
8788 end )
8889
@@ -108,16 +109,31 @@ defmodule ElixirScript.Output do
108109
109110 defp copy_javascript_module ( apps , output_dir , js_module_path ) do
110111 Enum . each ( apps , fn ( app ) ->
111- full_path = Path . join ( [ :code . priv_dir ( app ) , "elixir_script" , js_module_path ] ) <> ".js"
112+ base_path = Path . join ( [ :code . priv_dir ( app ) , "elixir_script" ] )
113+
114+ js_input_path = cond do
115+ File . exists? ( Path . join ( [ base_path , js_module_path ] ) ) ->
116+ Path . join ( [ base_path , js_module_path ] )
117+ File . exists? ( Path . join ( [ base_path , slashes_to_dots ( js_module_path ) ] ) ) ->
118+ Path . join ( [ base_path , slashes_to_dots ( js_module_path ) ] )
119+ true ->
120+ nil
121+ end
112122
113- if File . exists? ( full_path ) do
114- js_output_path = Path . join ( output_dir , js_module_path ) <> ".js"
115- if ! File . exists? ( Path . dirname ( js_output_path ) ) do
116- File . mkdir_p! ( Path . dirname ( js_output_path ) )
123+ if js_input_path != nil do
124+ js_output_path = Path . join ( output_dir , js_module_path )
125+ js_output_dir = Path . dirname ( js_output_path )
126+ if ! File . exists? ( js_output_dir ) do
127+ File . mkdir_p! ( js_output_dir )
117128 end
118129
119- File . cp ( full_path , js_output_path )
130+ File . cp ( js_input_path , js_output_path )
120131 end
121132 end )
122133 end
134+
135+ defp slashes_to_dots ( js_module_path ) do
136+ js_module_path
137+ |> String . replace ( "/" , "." )
138+ end
123139end
0 commit comments