@@ -14,20 +14,21 @@ defmodule JS2E do
1414 ## Options
1515
1616 * `--module-name` - the module name prefix for the printed Elm modules \
17- default value is 'Domain '.
17+ default value is 'Data '.
1818 """
1919
2020 require Logger
21- import JS2E.Parser , only: [ parse_schema_files: 1 ]
22- import JS2E.Printer , only: [ print_schemas: 2 ]
21+ alias JS2E.Parser
22+ alias JS2E.Printer
2323 alias JS2E.Parsers . { ParserWarning , ParserError }
2424 alias JS2E.Printers.PrinterError
2525
2626 @ spec main ( [ String . t ( ) ] ) :: :ok
2727 def main ( args ) do
28- { options , paths , errors } = OptionParser . parse ( args , switches: [ module_name: :string ] )
28+ { options , paths , errors } =
29+ OptionParser . parse ( args , switches: [ module_name: :string ] )
2930
30- if length ( paths ) == 0 do
31+ if Enum . empty? ( paths ) == true do
3132 IO . puts ( @ moduledoc )
3233 exit ( :normal )
3334 end
@@ -39,13 +40,16 @@ defmodule JS2E do
3940
4041 files = resolve_all_paths ( paths )
4142
42- if length ( files ) == 0 do
43- print_error ( "Error: Could not find any " <> "JSON files in path: #{ inspect ( paths ) } " )
43+ if Enum . empty? ( files ) == true do
44+ print_error (
45+ "Error: Could not find any " <> "JSON files in path: #{ inspect ( paths ) } "
46+ )
47+
4448 exit ( :no_files )
4549 end
4650
4751 output_path = create_output_dir ( options )
48- JS2E . generate ( files , output_path )
52+ generate ( files , output_path )
4953 end
5054
5155 @ spec resolve_all_paths ( [ String . t ( ) ] ) :: [ Path . t ( ) ]
@@ -92,7 +96,7 @@ defmodule JS2E do
9296 if Keyword . has_key? ( options , :module_name ) do
9397 Keyword . get ( options , :module_name )
9498 else
95- "Domain "
99+ "Data "
96100 end
97101
98102 output_path
@@ -104,14 +108,16 @@ defmodule JS2E do
104108 @ spec generate ( [ String . t ( ) ] , String . t ( ) ) :: :ok
105109 def generate ( schema_paths , module_name ) do
106110 Logger . info ( "Parsing JSON schema files!" )
107- parser_result = parse_schema_files ( schema_paths )
111+ parser_result = Parser . parse_schema_files ( schema_paths )
108112 pretty_parser_warnings ( parser_result . warnings )
109113
110114 if length ( parser_result . errors ) > 0 do
111115 pretty_parser_errors ( parser_result . errors )
112116 else
113117 Logger . info ( "Converting to Elm code!" )
114- printer_result = print_schemas ( parser_result . schema_dict , module_name )
118+
119+ printer_result =
120+ Printer . print_schemas ( parser_result . schema_dict , module_name )
115121
116122 if length ( printer_result . errors ) > 0 do
117123 pretty_printer_errors ( printer_result . errors )
@@ -149,7 +155,11 @@ defmodule JS2E do
149155 padding =
150156 String . duplicate (
151157 "-" ,
152- max ( 0 , 74 - String . length ( pretty_warning_type ) - String . length ( file_path ) )
158+ max (
159+ 0 ,
160+ 74 - String . length ( pretty_warning_type ) -
161+ String . length ( file_path )
162+ )
153163 )
154164
155165 warnings
@@ -181,7 +191,10 @@ defmodule JS2E do
181191 padding =
182192 String . duplicate (
183193 "-" ,
184- max ( 0 , 74 - String . length ( pretty_error_type ) - String . length ( file_path ) )
194+ max (
195+ 0 ,
196+ 74 - String . length ( pretty_error_type ) - String . length ( file_path )
197+ )
185198 )
186199
187200 errors
@@ -213,7 +226,10 @@ defmodule JS2E do
213226 padding =
214227 String . duplicate (
215228 "-" ,
216- max ( 0 , 74 - String . length ( pretty_error_type ) - String . length ( file_path ) )
229+ max (
230+ 0 ,
231+ 74 - String . length ( pretty_error_type ) - String . length ( file_path )
232+ )
217233 )
218234
219235 errors
@@ -237,7 +253,8 @@ defmodule JS2E do
237253 end
238254
239255 defp warning_header do
240- header = String . duplicate ( "^" , 35 ) <> " WARNINGS " <> String . duplicate ( "^" , 35 )
256+ header =
257+ String . duplicate ( "^" , 35 ) <> " WARNINGS " <> String . duplicate ( "^" , 35 )
241258
242259 IO . puts ( IO.ANSI . format ( [ :yellow , header ] ) )
243260 end
0 commit comments