| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,6 +9,7 @@ | |||
| 9 | 9 | /src/ | |
| 10 | 10 | /include/ | |
| 11 | 11 | /lib/enums.js | |
| 12 | + /lib/nodegit.js | ||
| 12 | 13 | ||
| 13 | 14 | ||
| 14 | 15 | /vendor/Release | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,5 @@ | |||
| 1 | 1 | var Promise = require("nodegit-promise"); | |
| 2 | 2 | var promisify = require("promisify-node"); | |
| 3 | - var descriptors = require("../generate/output/idefs.json"); | ||
| 4 | 3 | var rawApi; | |
| 5 | 4 | ||
| 6 | 5 | // Attempt to load the production release first, if it fails fall back to the | |
@@ -13,31 +12,40 @@ catch (e) { | |||
| 13 | 12 | rawApi = require("../build/Debug/nodegit"); | |
| 14 | 13 | } | |
| 15 | 14 | ||
| 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 */ | ||
| 41 | 49 | ||
| 42 | 50 | // Set the exports prototype to the raw API. | |
| 43 | 51 | exports.__proto__ = rawApi; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,7 +44,8 @@ module.exports = function() { | |||
| 44 | 44 | class_header: utils.readFile("combyne/templates/class_header.h"), | |
| 45 | 45 | struct_header: utils.readFile("combyne/templates/struct_header.h"), | |
| 46 | 46 | binding: utils.readFile("combyne/templates/binding.gyp"), | |
| 47 | - nodegit: utils.readFile("combyne/templates/nodegit.cc"), | ||
| 47 | + nodegitCC: utils.readFile("combyne/templates/nodegit.cc"), | ||
| 48 | + nodegitJS: utils.readFile("combyne/templates/nodegit.js"), | ||
| 48 | 49 | enums: utils.readFile("combyne/templates/enums.js") | |
| 49 | 50 | }; | |
| 50 | 51 | ||
@@ -101,19 +102,18 @@ module.exports = function() { | |||
| 101 | 102 | }).then(function() { | |
| 102 | 103 | // Write out single purpose templates. | |
| 103 | 104 | utils.writeFile("../binding.gyp", beautify(templates.binding.render(enabled))); | |
| 104 | - utils.writeFile("../src/nodegit.cc", templates.nodegit.render(enabled)); | ||
| 105 | - | ||
| 106 | - | ||
| 105 | + utils.writeFile("../src/nodegit.cc", templates.nodegitCC.render(enabled)); | ||
| 106 | + utils.writeFile("../lib/nodegit.js", beautify(templates.nodegitJS.render(enabled))); | ||
| 107 | 107 | // Write out all the classes. | |
| 108 | 108 | enabled.forEach(function(idef) { | |
| 109 | 109 | try { | |
| 110 | - if (idef.type == "struct") { | ||
| 111 | - utils.writeFile("../src/" + idef.filename + ".cc", templates.struct_content.render(idef)); | ||
| 112 | - utils.writeFile("../include/" + idef.filename + ".h", templates.struct_header.render(idef)); | ||
| 113 | - } | ||
| 114 | - else if (idef.type == "class") { | ||
| 115 | - utils.writeFile("../src/" + idef.filename + ".cc", templates.class_content.render(idef)); | ||
| 116 | - utils.writeFile("../include/" + idef.filename + ".h", templates.class_header.render(idef)); | ||
| 110 | + if (idef.type && idef.type != "enum") { | ||
| 111 | + utils.writeFile( | ||
| 112 | + "../src/" + idef.filename + ".cc", templates[idef.type + "_content"].render(idef) | ||
| 113 | + ); | ||
| 114 | + utils.writeFile( | ||
| 115 | + "../include/" + idef.filename + ".h", templates[idef.type + "_header"].render(idef) | ||
| 116 | + ); | ||
| 117 | 117 | } | |
| 118 | 118 | } | |
| 119 | 119 | catch (e) { | |
@@ -123,7 +123,6 @@ module.exports = function() { | |||
| 123 | 123 | } | |
| 124 | 124 | }); | |
| 125 | 125 | ||
| 126 | - | ||
| 127 | 126 | utils.writeFile("../lib/enums.js", beautify(templates.enums.render(enabled))); | |
| 128 | 127 | }).then(function() { | |
| 129 | 128 | return exec("command -v astyle").then(function(astyle) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments