-
Notifications
You must be signed in to change notification settings - Fork 699
Expand file tree
/
Copy pathnodegit.js
More file actions
82 lines (71 loc) · 2.04 KB
/
nodegit.js
File metadata and controls
82 lines (71 loc) · 2.04 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var Promise = require("nodegit-promise");
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) {
if (descriptor.type == "enum") {
return;
}
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("./merge");
require("./object");
require("./odb");
require("./odb_object");
require("./oid");
require("./patch");
require("./reference");
require("./remote");
require("./revwalk");
require("./repository");
require("./revwalk");
require("./signature");
require("./status");
require("./tree");
require("./tree_entry");
//must go last!
require("./enums");
// Wrap asynchronous methods to return promises.
promisify(exports);
// Set version.
exports.version = require("../package").version;
// Expose Promise implementation.
exports.Promise = Promise;
// Initialize threads.
exports.Threads.init();