@@ -5,7 +5,6 @@ if (process.env.MODULES_PATH) {
5
5
const ts = require ( 'typescript' ) ;
6
6
const fs = require ( 'fs' ) ;
7
7
const path = require ( 'path' ) ;
8
- const R = require ( 'ramda' ) ;
9
8
10
9
const args = process . argv . slice ( 2 ) ;
11
10
const src = args [ 2 ] ;
@@ -40,9 +39,9 @@ const PRIMITIVES = [
40
39
'node'
41
40
] ;
42
41
43
- const unionSupport = R . concat ( PRIMITIVES , [ 'boolean' , 'Element' ] ) ;
42
+ const unionSupport = PRIMITIVES . concat ( 'boolean' , 'Element' ) ;
44
43
45
- const reArray = new RegExp ( `(${ R . join ( '|' , unionSupport ) } )\\[\\]` ) ;
44
+ const reArray = new RegExp ( `(${ unionSupport . join ( '|' ) } )\\[\\]` ) ;
46
45
47
46
const isArray = rawType => reArray . test ( rawType ) ;
48
47
@@ -62,6 +61,14 @@ if (fs.existsSync('tsconfig.json')) {
62
61
tsconfig = JSON . parse ( fs . readFileSync ( 'tsconfig.json' ) ) ;
63
62
}
64
63
64
+ function zipArrays ( ...arrays ) {
65
+ const arr = [ ] ;
66
+ for ( let i = 0 ; i <= arrays [ 0 ] . length - 1 ; i ++ ) {
67
+ arr . push ( arrays . map ( a => a [ i ] ) ) ;
68
+ }
69
+ return arr ;
70
+ }
71
+
65
72
function gatherComponents ( directory , components = { } ) {
66
73
const names = [ ] ;
67
74
const filepaths = [ ] ;
@@ -158,7 +165,7 @@ function gatherComponents(directory, components = {}) {
158
165
}
159
166
}
160
167
return (
161
- R . includes ( typeName , unionSupport ) ||
168
+ unionSupport . includes ( typeName ) ||
162
169
isArray ( checker . typeToString ( t ) )
163
170
) ;
164
171
} )
@@ -175,7 +182,7 @@ function gatherComponents(directory, components = {}) {
175
182
} ;
176
183
177
184
const getPropTypeName = propName => {
178
- if ( R . includes ( '=>' , propName ) || propName === 'Function' ) {
185
+ if ( propName . includes ( '=>' ) || propName === 'Function' ) {
179
186
return 'func' ;
180
187
} else if ( propName === 'boolean' ) {
181
188
return 'bool' ;
@@ -200,25 +207,23 @@ function gatherComponents(directory, components = {}) {
200
207
if ( propType . isUnion ( ) ) {
201
208
if ( isUnionlitteral ( propType ) ) {
202
209
return { ...getEnum ( propType ) , raw} ;
203
- } else if ( R . includes ( '|' , raw ) ) {
210
+ } else if ( raw . includes ( '|' ) ) {
204
211
return { ...getUnion ( propType , propObj ) , raw} ;
205
212
}
206
213
}
207
214
208
215
name = getPropTypeName ( name ) ;
209
216
210
217
// Shapes & array support.
211
- if (
212
- ! R . includes ( name , R . concat ( PRIMITIVES , [ 'enum' , 'func' , 'union' ] ) )
213
- ) {
218
+ if ( ! PRIMITIVES . concat ( 'enum' , 'func' , 'union' ) . includes ( name ) ) {
214
219
if (
215
- R . includes ( '[]' , name ) ||
216
- R . includes ( 'Array' , name ) ||
220
+ name . includes ( '[]' ) ||
221
+ name . includes ( 'Array' ) ||
217
222
name === 'tuple'
218
223
) {
219
224
name = 'arrayOf' ;
220
- const replaced = R . replace ( '[]' , '' , raw ) ;
221
- if ( R . includes ( replaced , unionSupport ) ) {
225
+ const replaced = raw . replace ( '[]' , '' ) ;
226
+ if ( unionSupport . includes ( ' replaced' ) ) {
222
227
// Simple types are easier.
223
228
value = {
224
229
name : getPropTypeName ( replaced ) ,
@@ -307,17 +312,14 @@ function gatherComponents(directory, components = {}) {
307
312
const comment = symbol . getDocumentationComment ( ) ;
308
313
const tags = symbol . getJsDocTags ( ) ;
309
314
if ( comment && comment . length ) {
310
- return R . join ( '\n' ) (
311
- R . concat (
312
- comment . map ( c => c . text ) ,
315
+ return comment
316
+ . map ( c => c . text )
317
+ . concat (
313
318
tags . map ( t =>
314
- R . concat (
315
- [ '@' , t . name ] ,
316
- ( t . text || [ ] ) . map ( e => e . text )
317
- )
319
+ [ '@' , t . name ] . concat ( ( t . text || [ ] ) . map ( e => e . text ) )
318
320
)
319
321
)
320
- ) ;
322
+ . join ( '\n' ) ;
321
323
}
322
324
return '' ;
323
325
} ;
@@ -528,7 +530,7 @@ function gatherComponents(directory, components = {}) {
528
530
return getProps ( propertiesOfProps , propsObj , baseProps , defaultProps ) ;
529
531
} ;
530
532
531
- R . zip ( filepaths , names ) . forEach ( ( [ f , name ] ) => {
533
+ zipArrays ( filepaths , names ) . forEach ( ( [ f , name ] ) => {
532
534
const source = program . getSourceFile ( f ) ;
533
535
const moduleSymbol = checker . getSymbolAtLocation ( source ) ;
534
536
const exports = checker . getExportsOfModule ( moduleSymbol ) ;
0 commit comments