FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

move nodegit.js to a template to remove idefs dependency by maxkorp · Pull Request #303 · nodegit/nodegit · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (2) dotfile  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
1 change: 1 addition & 0 deletions .gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/src/
/include/
/lib/enums.js
/lib/nodegit.js


/vendor/Release
Expand Down
60 changes: 34 additions & 26 deletions lib/nodegit.js → generate/combyne/templates/nodegit.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var Promise = require("nodegit-promise");
var promisify = require("promisify-node");
var descriptors = require("../generate/output/idefs.json");
var rawApi;

// Attempt to load the production release first, if it fails fall back to the
Expand All @@ -13,31 +12,40 @@ catch (e) {
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);
}
});
});
// Native methods do not return an identifiable function, so we
// have to override them here
/* jshint ignore:start */
{% each . as idef %}
{% if idef.type != "enum" %}

var _{{ idef.jsClassName }}
= rawApi.{{idef.jsClassName}};

{% each idef.functions as fn %}
{% if fn.isAsync %}

{% if fn.isPrototypeMethod %}

var _{{ idef.jsClassName }}_{{ fn.jsFunctionName}}
= _{{ idef.jsClassName }}.prototype.{{ fn.jsFunctionName }};
_{{ idef.jsClassName }}.prototype.{{ fn.jsFunctionName }}
= promisify(_{{ idef.jsClassName }}_{{ fn.jsFunctionName}});

{% else %}

var _{{ idef.jsClassName }}_{{ fn.jsFunctionName}}
= _{{ idef.jsClassName }}.{{ fn.jsFunctionName }};
_{{ idef.jsClassName }}.{{ fn.jsFunctionName }}
= promisify(_{{ idef.jsClassName }}_{{ fn.jsFunctionName}});

{% endif %}

{% endif %}
{% endeach %}

{% endif %}
{% endeach %}
/* jshint ignore:end */

// Set the exports prototype to the raw API.
exports.__proto__ = rawApi;
Expand Down
23 changes: 11 additions & 12 deletions generate/scripts/generateNativeCode.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ module.exports = function() {
class_header: utils.readFile("combyne/templates/class_header.h"),
struct_header: utils.readFile("combyne/templates/struct_header.h"),
binding: utils.readFile("combyne/templates/binding.gyp"),
nodegit: utils.readFile("combyne/templates/nodegit.cc"),
nodegitCC: utils.readFile("combyne/templates/nodegit.cc"),
nodegitJS: utils.readFile("combyne/templates/nodegit.js"),
enums: utils.readFile("combyne/templates/enums.js")
};

Expand Down Expand Up @@ -101,19 +102,18 @@ module.exports = function() {
}).then(function() {
// Write out single purpose templates.
utils.writeFile("../binding.gyp", beautify(templates.binding.render(enabled)));
utils.writeFile("../src/nodegit.cc", templates.nodegit.render(enabled));


utils.writeFile("../src/nodegit.cc", templates.nodegitCC.render(enabled));
utils.writeFile("../lib/nodegit.js", beautify(templates.nodegitJS.render(enabled)));
// Write out all the classes.
enabled.forEach(function(idef) {
try {
if (idef.type == "struct") {
utils.writeFile("../src/" + idef.filename + ".cc", templates.struct_content.render(idef));
utils.writeFile("../include/" + idef.filename + ".h", templates.struct_header.render(idef));
}
else if (idef.type == "class") {
utils.writeFile("../src/" + idef.filename + ".cc", templates.class_content.render(idef));
utils.writeFile("../include/" + idef.filename + ".h", templates.class_header.render(idef));
if (idef.type && idef.type != "enum") {
utils.writeFile(
"../src/" + idef.filename + ".cc", templates[idef.type + "_content"].render(idef)
);
utils.writeFile(
"../include/" + idef.filename + ".h", templates[idef.type + "_header"].render(idef)
);
}
}
catch (e) {
Expand All @@ -123,7 +123,6 @@ module.exports = function() {
}
});


utils.writeFile("../lib/enums.js", beautify(templates.enums.render(enabled)));
}).then(function() {
return exec("command -v astyle").then(function(astyle) {
Expand Down

Back | FazBrowse Home | New Git URL