1
- ' use strict' ;
1
+ " use strict"
2
2
3
- const fetch = require ( "node-fetch" ) ,
4
- _ = require ( "lodash" ) ,
5
- Entry = require ( ' ./lib/entry.js' ) ,
6
- getEntries = Entry . getEntries ;
3
+ const fetch = require ( "node-fetch" )
4
+ const _ = require ( "lodash" )
5
+ const Entry = require ( " ./lib/entry.js" )
6
+ const getEntries = Entry . getEntries
7
7
8
8
exports . sourceNodes = (
9
9
{ actions, createNodeId, createContentDigest } ,
@@ -15,85 +15,87 @@ exports.sourceNodes = (
15
15
delete configOptions . plugins
16
16
17
17
// TODO: Extend this to include multiple versions
18
- const url = configOptions . versions [ 0 ] . url ,
19
- version = configOptions . versions [ 0 ] . version ;
18
+ const url = configOptions . versions [ 0 ] . url
19
+ const version = configOptions . versions [ 0 ] . version
20
20
21
21
const processEntry = entry => {
22
22
try {
23
23
// Exit early if the entry is private or has no name
24
24
if ( ! entry || ! entry . getName ( ) || entry . isPrivate ( ) ) {
25
- return ;
26
- }
25
+ return
26
+ }
27
27
} catch ( err ) {
28
28
// Some of the non-lodash methods were throwing a hard to trace error
29
- // from the lib code. Rather than trace back, it was easier to catch
29
+ // from the lib code. Rather than trace back, it was easier to catch
30
30
// since they aren't part of lodash.
31
- return ;
31
+ return
32
32
}
33
33
34
34
// Special handling of aliases to get call names. Without this, there are
35
35
// circular JS object references.
36
36
const aliases = entry . getAliases ( ) . map ( alias => {
37
- const member = entry . getMembers ( 0 ) || '' ,
38
- name = alias . getName ( ) ;
39
- return `${ member } .${ name } ` ;
37
+ const member = entry . getMembers ( 0 ) || ""
38
+ const name = alias . getName ( )
39
+ return `${ member } .${ name } `
40
40
} )
41
41
42
- const params = entry . getParams ( ) . map (
43
- ( [ type , name , desc ] ) => ( { type, name, desc } ) ) ;
42
+ const params = entry
43
+ . getParams ( )
44
+ . map ( ( [ type , name , desc ] ) => ( { type, name, desc } ) )
44
45
45
46
const entryData = {
46
47
aliases,
47
- version,
48
- params,
49
48
call : entry . getCall ( ) ,
50
49
category : entry . getCategory ( ) ,
51
50
desc : entry . getDesc ( ) ,
52
51
example : entry . getExample ( ) ,
53
52
hash : entry . getHash ( ) ,
53
+ isAlias : entry . isAlias ( ) ,
54
+ isCtor : entry . isCtor ( ) ,
55
+ isFunction : entry . isFunction ( ) ,
56
+ isLicense : entry . isLicense ( ) ,
57
+ isPlugin : entry . isPlugin ( ) ,
58
+ isStatic : entry . isStatic ( ) ,
54
59
lineNumber : entry . getLineNumber ( ) ,
55
60
members : entry . getMembers ( ) ,
56
61
name : entry . getName ( ) ,
62
+ params,
57
63
related : entry . getRelated ( ) ,
58
64
returns : entry . getReturns ( ) ,
59
65
since : entry . getSince ( ) ,
60
66
type : entry . getType ( ) ,
61
- isAlias : entry . isAlias ( ) ,
62
- isCtor : entry . isCtor ( ) ,
63
- isFunction : entry . isFunction ( ) ,
64
- isLicense : entry . isLicense ( ) ,
65
- isPlugin : entry . isPlugin ( ) ,
66
- isStatic : entry . isStatic ( ) ,
67
+ version,
67
68
}
68
69
69
- const nodeData = _ . assign ( { } , entryData , {
70
- id : createNodeId ( `lodash_method_${ version } _${ entryData . hash } _${ entryData . lineNumber } ` ) ,
71
- parent : null ,
70
+ const nodeData = {
71
+ ...entryData ,
72
72
children : [ ] ,
73
+ id : createNodeId (
74
+ `lodash_method_${ version } _${ entryData . hash } _${ entryData . lineNumber } `
75
+ ) ,
73
76
internal : {
74
- type : 'LodashMethod' ,
75
77
content : JSON . stringify ( entryData ) ,
76
78
contentDigest : createContentDigest ( JSON . stringify ( entryData ) ) ,
77
- }
78
- } ) ;
79
+ type : "LodashMethod" ,
80
+ } ,
81
+ parent : null ,
82
+ }
79
83
80
- return nodeData ;
84
+ return nodeData
81
85
}
82
86
83
- return (
84
- fetch ( url )
85
- . then ( res => res . text ( ) )
86
- . then ( body => {
87
- const entries = getEntries ( body ) ;
87
+ return fetch ( url )
88
+ . then ( res => res . text ( ) )
89
+ . then ( body => {
90
+ const entries = getEntries ( body )
88
91
89
- // For each entry, create node.
90
- _ . each ( entries , entry => {
91
- entry = new Entry ( entry , body ) ;
92
- const nodeData = processEntry ( entry ) ;
93
- if ( nodeData ) {
94
- createNode ( nodeData ) ;
95
- }
96
- } )
92
+ // For each entry, create node.
93
+ _ . each ( entries , entry => {
94
+ entry = new Entry ( entry , body )
95
+ const nodeData = processEntry ( entry )
96
+ if ( nodeData ) {
97
+ createNode ( nodeData )
98
+ }
97
99
} )
98
- )
99
- }
100
+ } )
101
+ }
0 commit comments