FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nodegit.nodegit/generate/scripts/generateJson.js at master · javascript-forks/nodegit.nodegit · GitHub
javascript-forks
nodegit.nodegit
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
nodegit.nodegit
/
generate
/
scripts
/
generateJson.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
238 lines (190 loc) · 6.57 KB
Breadcrumbs
nodegit.nodegit
/
generate
/
scripts
/
generateJson.js
Copy path
File metadata and controls
238 lines (190 loc) · 6.57 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
const
fs
=
require
(
"fs"
)
;
const
path
=
require
(
"path"
)
;
const
utils
=
require
(
"./utils"
)
;
var
_
;
var
version
=
require
(
"../../package.json"
)
.
libgit2
.
version
;
var
libgit2
=
require
(
"../input/v"
+
version
+
".json"
)
;
var
descriptor
=
require
(
"../input/descriptor.json"
)
;
var
supplement
=
require
(
"../input/libgit2-supplement.json"
)
;
module
.
exports
=
function
generateJson
(
)
{
var
helpers
=
require
(
"./helpers"
)
;
_
=
require
(
"lodash"
)
;
// libgit2's docs aren't complete so we'll add in what they're missing here
libgit2
.
types
.
forEach
(
function
(
type
)
{
if
(
supplement
.
types
[
type
[
0
]
]
)
{
_
.
merge
(
type
[
1
]
,
supplement
.
types
[
type
[
0
]
]
)
;
}
}
)
;
libgit2
.
groups
.
forEach
(
function
(
group
)
{
if
(
supplement
.
groups
[
group
[
0
]
]
)
{
Array
.
prototype
.
push
.
apply
(
group
[
1
]
,
supplement
.
groups
[
group
[
0
]
]
)
;
}
}
)
;
Array
.
prototype
.
push
.
apply
(
libgit2
.
types
,
supplement
.
new
.
types
)
;
Array
.
prototype
.
push
.
apply
(
libgit2
.
groups
,
supplement
.
new
.
groups
)
;
_
.
merge
(
libgit2
.
functions
,
supplement
.
new
.
functions
)
;
var
output
=
[
]
;
var
dependencyLookup
=
{
}
;
var
types
=
[
]
;
var
enums
=
[
]
;
// reduce all of the groups into a hashmap and a name array for easy lookup
var
groups
=
libgit2
.
groups
.
reduce
(
function
(
memo
,
group
)
{
var
groupName
=
group
[
0
]
;
// Some functions are in the wrong group so we can't just ignore them.
// We have to completely remove them from one group and manually add them
// into the other.
var
functionNames
=
group
[
1
]
.
filter
(
function
(
fnName
)
{
return
!
supplement
.
remove
[
groupName
]
||
!
supplement
.
remove
[
groupName
]
.
functions
||
!
~
supplement
.
remove
[
groupName
]
.
functions
.
indexOf
(
fnName
)
;
}
)
;
// if we have an empty group then just ignore it
if
(
functionNames
.
length
)
{
memo
[
groupName
]
=
functionNames
;
}
return
memo
;
}
,
{
}
)
;
// Split each type from the array into classes/structs and enums
// each entry is of type ['name', {definingobject}]
libgit2
.
types
.
forEach
(
function
(
current
)
{
current
[
1
]
.
typeName
=
current
[
0
]
;
// just log these out to a file for fun
if
(
current
[
1
]
.
type
===
"enum"
)
{
enums
.
push
(
current
[
1
]
)
;
}
else
{
types
.
push
(
current
[
1
]
)
;
}
}
)
;
var
previous
=
""
;
enums
=
_
(
enums
)
.
sortBy
(
"name"
)
.
reduce
(
function
(
enumMemo
,
enumerable
)
{
if
(
previous
==
enumerable
.
typeName
)
{
if
(
process
.
env
.
BUILD_ONLY
)
{
console
.
warn
(
'Duplicate definition for enum '
+
enumerable
.
typeName
+
". skipped."
)
;
}
}
else
if
(
!
enumerable
.
fields
)
{
if
(
process
.
env
.
BUILD_ONLY
)
{
console
.
warn
(
'Incomplete definition for enum '
+
enumerable
.
typeName
+
". skipped."
)
;
}
}
else
{
enumMemo
[
enumerable
.
typeName
]
=
{
typeName
:
enumerable
.
typeName
.
replace
(
/
^
g
i
t
_
/
,
""
)
.
replace
(
/
_
t
$
/
,
""
)
,
type
:
"enum"
,
cType
:
enumerable
.
typeName
,
isMask
:
(
/
_
t
$
/
)
.
test
(
enumerable
.
typeName
)
,
values
:
enumerable
.
fields
.
map
(
function
(
field
)
{
return
{
name
:
field
.
name
,
value
:
field
.
value
}
}
)
}
;
}
previous
=
enumerable
.
typeName
;
return
enumMemo
;
}
,
{
}
)
.
valueOf
(
)
;
// decorate the definitions with required data to build the C++ files
types
.
forEach
(
function
(
typeDef
)
{
var
typeName
=
typeDef
.
typeName
;
typeDef
.
cType
=
typeName
;
typeName
=
typeName
.
replace
(
"git_"
,
""
)
;
typeDef
.
typeName
=
typeName
;
dependencyLookup
[
typeName
]
=
typeName
;
typeDef
.
functions
=
groups
[
typeName
]
||
[
]
;
helpers
.
decoratePrimaryType
(
typeDef
,
enums
)
;
groups
[
typeName
]
=
false
;
typeDef
.
type
=
typeDef
.
hasConstructor
?
"struct"
:
"class"
;
output
.
push
(
typeDef
)
;
}
)
;
// Loop over the groups in case we missed anything (eg the types are missing in the docs);
for
(
var
groupName
in
groups
)
{
var
groupDef
=
groups
[
groupName
]
;
if
(
groupDef
===
false
)
{
continue
;
}
groupDef
=
{
functions
:
groupDef
}
;
groupDef
.
type
=
"class"
;
groupDef
.
cType
=
(
descriptor
.
types
[
groupName
]
||
{
}
)
.
cType
||
groupDef
.
cType
;
groupDef
.
typeName
=
groupName
;
dependencyLookup
[
groupName
]
=
groupName
;
helpers
.
decoratePrimaryType
(
groupDef
,
enums
)
;
output
.
push
(
groupDef
)
;
}
// Calculate dependencies
output
.
forEach
(
function
(
def
)
{
if
(
def
.
ignore
)
{
return
;
}
var
dependencies
=
{
}
;
var
addDependencies
=
function
(
prop
)
{
if
(
prop
.
ignore
)
{
return
;
}
var
type
=
helpers
.
normalizeCtype
(
prop
.
type
||
prop
.
cType
)
.
replace
(
"git_"
,
""
)
;
var
dependencyFilename
=
dependencyLookup
[
type
]
;
if
(
dependencyFilename
)
{
dependencies
[
dependencyFilename
]
=
dependencyFilename
;
}
(
prop
.
args
||
[
]
)
.
forEach
(
addDependencies
)
;
if
(
prop
.
return
)
{
addDependencies
(
prop
.
return
)
;
}
}
;
def
.
fields
.
forEach
(
addDependencies
)
;
def
.
functions
.
forEach
(
addDependencies
)
;
Object
.
keys
(
dependencies
)
.
forEach
(
function
(
dependencyFilename
)
{
def
.
dependencies
.
push
(
"../include/"
+
dependencyFilename
+
".h"
)
;
}
)
;
// Additionally provide a friendly name to the actual filename.
def
.
name
=
path
.
basename
(
def
.
filename
,
".h"
)
;
def
.
functions
.
forEach
(
function
(
fn
)
{
fn
.
cppClassName
=
def
.
cppClassName
;
}
)
;
}
)
;
// Process enums
_
(
enums
)
.
forEach
(
function
(
enumerable
)
{
output
.
some
(
function
(
obj
)
{
if
(
enumerable
.
typeName
.
indexOf
(
obj
.
typeName
)
==
0
)
{
enumerable
.
owner
=
obj
.
jsClassName
;
}
else
if
(
enumerable
.
owner
)
{
return
true
;
}
}
)
;
var
override
=
descriptor
.
enums
[
enumerable
.
typeName
]
||
{
}
;
enumerable
.
owner
=
override
.
owner
||
enumerable
.
owner
||
"Enums"
;
enumerable
.
JsName
=
enumerable
.
typeName
.
replace
(
new
RegExp
(
"^"
+
enumerable
.
owner
.
toLowerCase
(
)
)
,
""
)
.
replace
(
/
^
_
/
,
""
)
.
toUpperCase
(
)
;
enumerable
.
values
.
forEach
(
function
(
value
)
{
value
.
JsName
=
value
.
name
.
replace
(
/
^
G
I
T
_
/
,
""
)
.
replace
(
override
.
removeString
||
""
,
""
)
.
replace
(
new
RegExp
(
"^"
+
enumerable
.
owner
.
toUpperCase
(
)
)
,
""
)
.
replace
(
/
^
_
/
,
""
)
.
replace
(
new
RegExp
(
"^"
+
enumerable
.
JsName
)
,
""
)
.
replace
(
/
^
_
/
,
""
)
.
toUpperCase
(
)
;
if
(
override
.
values
&&
override
.
values
[
value
.
name
]
)
{
_
.
merge
(
value
,
override
.
values
[
value
.
name
]
)
;
}
}
)
;
_
.
merge
(
enumerable
,
_
.
omit
(
override
,
[
"values"
]
)
)
;
output
.
push
(
enumerable
)
;
}
)
.
value
(
)
;
output
=
_
.
sortBy
(
output
,
"typeName"
)
;
if
(
process
.
argv
[
2
]
!=
"--documentation"
)
{
helpers
.
filterDocumentation
(
output
)
;
}
utils
.
writeFile
(
"output/idefs.json"
,
output
)
;
}
;
if
(
require
.
main
===
module
)
{
module
.
exports
(
)
;
}
Back
|
FazBrowse Home
|
New Git URL