@@ -20,18 +20,14 @@ const DEFAULT_OPTIONS = {
20
20
let EXIT_CODE = 0
21
21
let KEEP_OPEN = false
22
22
23
- const error = ( msg ) => {
23
+ const error = msg => {
24
24
console . error ( msg ) // eslint-disable-line no-console
25
25
26
26
return process . exit ( 1 )
27
27
}
28
28
29
- const pickArgs = args => (
30
- flow (
31
- pick ( args ) ,
32
- pickBy ( e => negate ( isNil ) ( e ) && ! ( isArray ( e ) && isEmpty ( e ) ) )
33
- )
34
- )
29
+ const pickArgs = args =>
30
+ flow ( pick ( args ) , pickBy ( e => negate ( isNil ) ( e ) && ! ( isArray ( e ) && isEmpty ( e ) ) ) )
35
31
36
32
const argv = yargs
37
33
. options ( {
@@ -68,40 +64,43 @@ const argv = yargs
68
64
} ,
69
65
} )
70
66
. help ( )
71
- . version ( `mjml-core: ${ coreVersion } \nmjml-cli: ${ cliVersion } ` )
72
- . argv
73
-
67
+ . version ( `mjml-core: ${ coreVersion } \nmjml-cli: ${ cliVersion } ` ) . argv
74
68
75
69
const config = Object . assign ( DEFAULT_OPTIONS , argv . c )
76
70
const inputArgs = pickArgs ( [ 'r' , 'w' , 'i' , '_' ] ) ( argv )
77
- const outputArgs = pickArgs ( [ 'o' , 's' ] ) ( argv ) ;
71
+ const outputArgs = pickArgs ( [ 'o' , 's' ] ) ( argv )
78
72
79
73
// implies (until yargs pr is accepted)
80
- [
74
+ ; [
81
75
[ Object . keys ( inputArgs ) . length > 1 , 'No input arguments received' ] ,
82
76
[ Object . keys ( inputArgs ) . length === 0 , 'Too much input arguments received' ] ,
83
77
[ Object . keys ( outputArgs ) . length > 1 , 'Too much output arguments received' ] ,
84
- [ argv . w && argv . w . length > 1 && ! argv . o , 'Need an output option when watching files' ] ,
85
- [ argv . w
86
- && argv . w . length > 1
87
- && argv . o
88
- && ! isDirectory ( argv . o )
89
- && argv . o !== '' ,
90
- 'Need an output option when watching files' ] ,
91
- ] . forEach ( v => (
92
- v [ 0 ] ? error ( v [ 1 ] ) : null
93
- ) )
78
+ [
79
+ argv . w && argv . w . length > 1 && ! argv . o ,
80
+ 'Need an output option when watching files' ,
81
+ ] ,
82
+ [
83
+ argv . w &&
84
+ argv . w . length > 1 &&
85
+ argv . o &&
86
+ ! isDirectory ( argv . o ) &&
87
+ argv . o !== '' ,
88
+ 'Need an output option when watching files' ,
89
+ ] ,
90
+ ] . forEach ( v => ( v [ 0 ] ? error ( v [ 1 ] ) : null ) )
94
91
95
92
const inputOpt = Object . keys ( inputArgs ) [ 0 ]
96
93
const outputOpt = Object . keys ( outputArgs ) [ 0 ] || 's'
97
94
98
- const inputFiles = isArray ( inputArgs [ inputOpt ] ) ? inputArgs [ inputOpt ] : [ inputArgs [ inputOpt ] ]
95
+ const inputFiles = isArray ( inputArgs [ inputOpt ] )
96
+ ? inputArgs [ inputOpt ]
97
+ : [ inputArgs [ inputOpt ] ]
99
98
const inputs = [ ]
100
99
101
100
switch ( inputOpt ) {
102
101
case 'r' :
103
102
case '_' : {
104
- flatMapPaths ( inputFiles ) . forEach ( ( file ) => {
103
+ flatMapPaths ( inputFiles ) . forEach ( file => {
105
104
inputs . push ( readFile ( file ) )
106
105
} )
107
106
break
@@ -120,14 +119,13 @@ switch (inputOpt) {
120
119
const convertedStream = [ ]
121
120
const failedStream = [ ]
122
121
123
- inputs . forEach ( ( i ) => { // eslint-disable-line array-callback-return
122
+ inputs . forEach ( i => {
123
+ // eslint-disable-line array-callback-return
124
124
try {
125
125
convertedStream . push (
126
- Object . assign (
127
- { } ,
128
- i ,
129
- { compiled : mjml2html ( i . mjml , { ...config , filePath : i . file } ) }
130
- )
126
+ Object . assign ( { } , i , {
127
+ compiled : mjml2html ( i . mjml , { ...config , filePath : i . file } ) ,
128
+ } ) ,
131
129
)
132
130
} catch ( e ) {
133
131
EXIT_CODE = 2
@@ -136,10 +134,13 @@ inputs.forEach((i) => { // eslint-disable-line array-callback-return
136
134
}
137
135
} )
138
136
139
- failedStream . forEach ( ( { error, file } ) => { // eslint-disable-line array-callback-return
137
+ failedStream . forEach ( ( { error, file } ) => {
138
+ // eslint-disable-line array-callback-return
140
139
console . error ( `${ file ? `File: ${ file } \n` : null } ${ error } ` ) // eslint-disable-line no-console
141
140
142
- if ( config . stack ) { console . error ( error . stack ) } // eslint-disable-line no-console
141
+ if ( config . stack ) {
142
+ console . error ( error . stack )
143
+ } // eslint-disable-line no-console
143
144
} )
144
145
145
146
if ( ! KEEP_OPEN && convertedStream . length === 0 ) {
@@ -149,21 +150,25 @@ if (!KEEP_OPEN && convertedStream.length === 0) {
149
150
switch ( outputOpt ) {
150
151
case 'o' :
151
152
if ( inputs . length > 1 && ( ! isDirectory ( argv . o ) && argv . o !== '' ) ) {
152
- error ( `Multiple input files, but output option should be either a directory or an empty string: ${ argv . o } given` )
153
+ error (
154
+ `Multiple input files, but output option should be either a directory or an empty string: ${ argv . o } given` ,
155
+ )
153
156
}
154
157
155
- Promise
156
- . all ( convertedStream . map ( outputToFile ( argv . o ) ) )
158
+ Promise . all ( convertedStream . map ( outputToFile ( argv . o ) ) )
157
159
. then ( ( ) => {
158
- if ( ! KEEP_OPEN ) { process . exit ( EXIT_CODE ) }
160
+ if ( ! KEEP_OPEN ) {
161
+ process . exit ( EXIT_CODE )
162
+ }
159
163
} )
160
164
. catch ( ( ) => {
161
- if ( ! KEEP_OPEN ) { process . exit ( 1 ) }
165
+ if ( ! KEEP_OPEN ) {
166
+ process . exit ( 1 )
167
+ }
162
168
} )
163
169
break
164
170
case 's' :
165
- Promise
166
- . all ( convertedStream . map ( outputToConsole ) )
171
+ Promise . all ( convertedStream . map ( outputToConsole ) )
167
172
. then ( ( ) => process . exit ( EXIT_CODE ) )
168
173
. catch ( ( ) => process . exit ( 1 ) )
169
174
break
0 commit comments