Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 1 addition & 64 deletions generate/templates/templates/nodegit.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,7 @@
var Promise = require("bluebird");
var promisify = require("thenify-all");
var rawApi;

function promisify(source) {
var destination = {};
if (typeof source === "function") {
return thenify(source);
} else {
Object.keys(source).forEach(function (name) {
if (typeof source[name] === "function") {
destination[name] = thenify(source[name]);
}
});
}
}

function thenify ($$__fn__$$) {
return eval(createWrapper($$__fn__$$.name));
}

function createWrapper (name) {
name = name ? ~[
// js reserved words
// "abstract", "arguments", "boolean", "break", "byte", "case", "catch",
// "char", "class", "const", "continue", "debugger", "while", "with",
// "yield", "do", "double", "else", "enum", "eval", "export", "extends",
// "false", "final", "finally", "float", "for", "function", "goto", "if",
// "implements", "import", "in", "instanceof", "int", "interface", "let",
// "long", "native", "new", "null", "package", "private", "protected",
// "public", "return", "short", "static", "super", "switch", "synchronized",
// "this", "throw", "throws", "transient", "true", "try", "typeof", "var",
// "void", "volatile",

"default", "delete"
].indexOf(name) ? "$$" + name : name : "";

/* jshint ignore:start */
return "(function " + name + "() {\n"
+ "var self = this\n"
+ "var len = arguments.length\n"
+ "var args = new Array(len + 1)\n"
+ "for (var i = 0; i < len; ++i) args[i] = arguments[i]\n"
+ "var lastIndex = i\n"
+ "return new Promise(function (resolve, reject) {\n"
+ "args[lastIndex] = createCallback(resolve, reject)\n"
+ "$$__fn__$$.apply(self, args)\n"
+ "})\n"
+ "})"
/* jshint ignore:end */
}

/* jshint ignore:start */
function createCallback(resolve, reject) {
return function(err, value) {
if (err) return reject(err)
var length = arguments.length
if (length <= 2) return resolve(value)
var values = new Array(length - 1)
for (var i = 1; i < length; ++i) values[i - 1] = arguments[i]
resolve(values)
}
}
/* jshint ignore:end */




// Attempt to load the production release first, if it fails fall back to the
// debug release.
try {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"fs-extra": "^0.18.2",
"node-pre-gyp": "^0.6.5",
"npm": "^2.9.0",
"thenify": "heavyk/thenify",
"thenify-all": "^1.6.0",
"which-native-nodish": "^1.1.1"
},
Expand Down