11var Promise = require ( "nodegit-promise" ) ;
22var promisify = require ( "promisify-node" ) ;
3- var descriptors = require ( "../generate/output/idefs.json" ) ;
43var rawApi ;
54
65// Attempt to load the production release first, if it fails fall back to the
@@ -13,31 +12,40 @@ catch (e) {
1312 rawApi = require ( "../build/Debug/nodegit" ) ;
1413}
1514
16- // Native methods do not return an identifiable function, so this function will
17- // filter down the function identity to match the libgit2 descriptor.
18- descriptors . forEach ( function ( descriptor ) {
19- if ( descriptor . type == "enum" ) {
20- return ;
21- }
22- var Ctor = rawApi [ descriptor . jsClassName ] ;
23-
24- // Iterate over each function in the file.
25- descriptor . functions . filter ( function ( func ) {
26- return func . isAsync ;
27- } ) . forEach ( function ( asyncFunc ) {
28- var original = null ;
29-
30- // Special case when you have a prototype method.
31- if ( asyncFunc . isPrototypeMethod && Ctor . prototype ) {
32- original = Ctor . prototype [ asyncFunc . jsFunctionName ] ;
33- Ctor . prototype [ asyncFunc . jsFunctionName ] = promisify ( original ) ;
34- }
35- else {
36- original = Ctor [ asyncFunc . jsFunctionName ] ;
37- Ctor [ asyncFunc . jsFunctionName ] = promisify ( original ) ;
38- }
39- } ) ;
40- } ) ;
15+ // Native methods do not return an identifiable function, so we
16+ // have to override them here
17+ /* jshint ignore:start */
18+ { % each . as idef % }
19+ { % if idef . type != "enum" % }
20+
21+ var _ { { idef . jsClassName } }
22+ = rawApi . { { idef . jsClassName } } ;
23+
24+ { % each idef . functions as fn % }
25+ { % if fn . isAsync % }
26+
27+ { % if fn . isPrototypeMethod % }
28+
29+ var _ { { idef . jsClassName } } _ { { fn . jsFunctionName } }
30+ = _ { { idef . jsClassName } } . prototype . { { fn . jsFunctionName } } ;
31+ _ { { idef . jsClassName } } . prototype . { { fn . jsFunctionName } }
32+ = promisify ( _ { { idef . jsClassName } } _ { { fn . jsFunctionName} } ) ;
33+
34+ { % else % }
35+
36+ var _ { { idef . jsClassName } } _ { { fn . jsFunctionName } }
37+ = _ { { idef . jsClassName } } . { { fn . jsFunctionName } } ;
38+ _ { { idef . jsClassName } } . { { fn . jsFunctionName } }
39+ = promisify ( _ { { idef . jsClassName } } _ { { fn . jsFunctionName} } ) ;
40+
41+ { % endif % }
42+
43+ { % endif % }
44+ { % endeach % }
45+
46+ { % endif % }
47+ { % endeach % }
48+ /* jshint ignore:end */
4149
4250// Set the exports prototype to the raw API.
4351exports . __proto__ = rawApi ;
0 commit comments