forked from nodegit/nodegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnodegit.js
More file actions
68 lines (59 loc) · 1.76 KB
/
Copy pathnodegit.js
File metadata and controls
68 lines (59 loc) · 1.76 KB
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
var promisify = require("promisify-node");
var descriptors = require("../generate/idefs.json");
var rawApi;
// Attempt to load the production release first, if it fails fall back to the
// debug release.
try {
rawApi = require("../build/Release/nodegit");
}
catch (e) {
/* istanbul ignore next */
rawApi = require("../build/Debug/nodegit");
}
// Native methods do not return an identifiable function, so this function will
// filter down the function identity to match the libgit2 descriptor.
descriptors.forEach(function(descriptor) {
var Ctor = rawApi[descriptor.jsClassName];
// Iterate over each function in the file.
descriptor.functions.filter(function(func) {
return func.isAsync;
}).forEach(function(asyncFunc) {
var original = null;
// Special case when you have a prototype method.
if (asyncFunc.isPrototypeMethod && Ctor.prototype) {
original = Ctor.prototype[asyncFunc.jsFunctionName];
Ctor.prototype[asyncFunc.jsFunctionName] = promisify(original);
}
else {
original = Ctor[asyncFunc.jsFunctionName];
Ctor[asyncFunc.jsFunctionName] = promisify(original);
}
});
});
// Set the exports prototype to the raw API.
exports.__proto__ = rawApi;
// Import extensions
require("./attr");
require("./blob");
require("./clone");
require("./checkout");
require("./commit");
require("./diff");
require("./index");
require("./object");
require("./odb");
require("./oid");
require("./patch");
require("./refs");
require("./remote");
require("./repository");
require("./revwalk");
require("./signature");
require("./tree");
require("./tree_entry");
// Wrap asynchronous methods to return promises.
promisify(exports);
// Set version.
exports.version = require("../package").version;
// Initialize threads.
exports.Threads.init();