@@ -14,20 +14,21 @@ defmodule JS2E do
14
14
## Options
15
15
16
16
* `--module-name` - the module name prefix for the printed Elm modules \
17
- default value is 'Domain '.
17
+ default value is 'Data '.
18
18
"""
19
19
20
20
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
23
23
alias JS2E.Parsers . { ParserWarning , ParserError }
24
24
alias JS2E.Printers.PrinterError
25
25
26
26
@ spec main ( [ String . t ( ) ] ) :: :ok
27
27
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 ] )
29
30
30
- if length ( paths ) == 0 do
31
+ if Enum . empty? ( paths ) == true do
31
32
IO . puts ( @ moduledoc )
32
33
exit ( :normal )
33
34
end
@@ -39,13 +40,16 @@ defmodule JS2E do
39
40
40
41
files = resolve_all_paths ( paths )
41
42
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
+
44
48
exit ( :no_files )
45
49
end
46
50
47
51
output_path = create_output_dir ( options )
48
- JS2E . generate ( files , output_path )
52
+ generate ( files , output_path )
49
53
end
50
54
51
55
@ spec resolve_all_paths ( [ String . t ( ) ] ) :: [ Path . t ( ) ]
@@ -92,7 +96,7 @@ defmodule JS2E do
92
96
if Keyword . has_key? ( options , :module_name ) do
93
97
Keyword . get ( options , :module_name )
94
98
else
95
- "Domain "
99
+ "Data "
96
100
end
97
101
98
102
output_path
@@ -104,14 +108,16 @@ defmodule JS2E do
104
108
@ spec generate ( [ String . t ( ) ] , String . t ( ) ) :: :ok
105
109
def generate ( schema_paths , module_name ) do
106
110
Logger . info ( "Parsing JSON schema files!" )
107
- parser_result = parse_schema_files ( schema_paths )
111
+ parser_result = Parser . parse_schema_files ( schema_paths )
108
112
pretty_parser_warnings ( parser_result . warnings )
109
113
110
114
if length ( parser_result . errors ) > 0 do
111
115
pretty_parser_errors ( parser_result . errors )
112
116
else
113
117
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 )
115
121
116
122
if length ( printer_result . errors ) > 0 do
117
123
pretty_printer_errors ( printer_result . errors )
@@ -149,7 +155,11 @@ defmodule JS2E do
149
155
padding =
150
156
String . duplicate (
151
157
"-" ,
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
+ )
153
163
)
154
164
155
165
warnings
@@ -181,7 +191,10 @@ defmodule JS2E do
181
191
padding =
182
192
String . duplicate (
183
193
"-" ,
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
+ )
185
198
)
186
199
187
200
errors
@@ -213,7 +226,10 @@ defmodule JS2E do
213
226
padding =
214
227
String . duplicate (
215
228
"-" ,
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
+ )
217
233
)
218
234
219
235
errors
@@ -237,7 +253,8 @@ defmodule JS2E do
237
253
end
238
254
239
255
defp warning_header do
240
- header = String . duplicate ( "^" , 35 ) <> " WARNINGS " <> String . duplicate ( "^" , 35 )
256
+ header =
257
+ String . duplicate ( "^" , 35 ) <> " WARNINGS " <> String . duplicate ( "^" , 35 )
241
258
242
259
IO . puts ( IO.ANSI . format ( [ :yellow , header ] ) )
243
260
end
0 commit comments