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

detect node-webkit and build with nw-gyp by maxkorp · Pull Request #309 · 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  (1) .json  (1) .md  (1) All 3 file types selected
Only manifest files
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
9 changes: 9 additions & 0 deletions README.md
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 @@ -186,3 +186,12 @@ https://github.com/nodegit/nodegit/compare/refs/tags/0.1.4...0.2.0
This update is wholly and entirely a breaking one, and older versions won't be
maintained. For the purpose of migration, perhaps the biggest point to make
is that async methods can now use promises, rather than just taking callbacks. Additionally, lots of method and property names have changed.

## Node-Webkit ##

A common issue is with nodegit not functioning properly inside of
[node-webkit](http://github.com/rogerwang/node-webkit) applications. Because nodegit
is a native module, it has to be rebuilt for node-webkit using
[nw-gyp](http://github.com/rogerwang/nw-gyp). By default, nodegit will look in the root package's package.json for an `engines` property, and within look for a `node-webkit` property that holds a specific version of node-webkit. The value of this property is what will get passed as the `--target` argument to `nw-gyp configure`.

Currently, support for node-webkit is limited, although we intend to support it better in the future.
60 changes: 47 additions & 13 deletions install.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 @@ -7,6 +7,7 @@ var Promise = require("nodegit-promise");
var promisify = require("promisify-node");
var request = require("request");
var fse = promisify(require("fs-extra"));
var findParentDir = promisify(require('find-parent-dir'));
fse.ensureDir = promisify(fse.ensureDir, function() { return true; });

var exec = promisify(function(command, opts, callback) {
Expand All @@ -17,6 +18,7 @@ var NODE_VERSION = Number(process.version.match(/^v(\d+\.\d+)/)[1]);

// If the build only flag is set.
var buildOnly = process.env.BUILD_ONLY;
var nodeWebkit = false;

// This will take in an object and find any matching keys in the environment
// to use as overrides.
Expand Down Expand Up @@ -72,23 +74,31 @@ if (NODE_VERSION === 0.1) {
}

fse.ensureDir(path.resolve(__dirname, paths.release))
.then(detectNodeWebkit.call(null, __dirname))
.then(fetch)
.then(finish, compile)
.done()

function fetch() {
if (!buildOnly) {
console.info("[nodegit] Fetching binary from S3.");
console.info("[nodegit] Fetching binary from S3.");

// Using the node-pre-gyp module, attempt to fetch a compatible build.
return exec("node-pre-gyp install");
if (nodeWebkit) {
throw new Error("Must build for node-webkit");
}

throw new Error("BUILD_ONLY is set to true, no fetching allowed.");
if (buildOnly) {
throw new Error("BUILD_ONLY is set to true, no fetching allowed.");
}

// Using the node-pre-gyp module, attempt to fetch a compatible build.
return exec("node-pre-gyp install");
}

function compile() {
if (!buildOnly) {
function compile(err) {
if (buildOnly || nodeWebkit) {
console.info("[nodegit] " + err.message);
}
else {
console.info("[nodegit] Failed to install prebuilt, attempting compile.");
}

Expand Down Expand Up @@ -173,11 +183,21 @@ function getVendorLib(name, url) {

function buildNative() {
return exec("cd " + __dirname).then(function() {
console.info("[nodegit] Building native node module.");
var pythonFlag = " --python \"" + pythonPath + "\"";
var cmd = path.resolve(systemPath([
".", "node_modules", ".bin", "node-gyp clean configure build" + pythonFlag
]));
if (nodeWebkit) {
console.info("[nodegit] Building native node-webkit module.");
}
else {
console.info("[nodegit] Building native node module.");
}

var builder = nodeWebkit ? "nw-gyp" : "node-gyp";

var cmd = path.resolve(".", "node_modules", ".bin", builder)
+ " clean configure "
+ (nodeWebkit ? "--target=\"" + nodeWebkit + "\"": "")
+ " build " + pythonFlag
+ "--python \"" + pythonPath + "\""

var opts = {
cwd: __dirname,
maxBuffer: Number.MAX_VALUE
Expand All @@ -186,6 +206,20 @@ function buildNative() {
})
}

function detectNodeWebkit(directory) {
if (directory) {
var pkg = require(path.resolve(directory, "package.json"));

nodeWebkit = pkg.engines && pkg.engines["node-webkit"];

return findParentDir(path.resolve(directory, ".."), "package.json")
.then(detectNodeWebkit);
}
else {
return Promise.resolve();
}
}

function finish() {
console.info("[nodegit] Completed installation successfully.");
return Promise.resolve().done();
Expand All @@ -194,6 +228,6 @@ function finish() {
function fail(message) {
console.info("[nodegit] Failed to build and install nodegit.");
console.info(message.message);
//console.info(message.stack);

return Promise.resolve().done();
}
4 changes: 3 additions & 1 deletion package.json
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 @@ -61,16 +61,18 @@
],
"dependencies": {
"combyne": "~0.6.2",
"find-parent-dir": "^0.3.0",
"fs-extra": "^0.12.0",
"lodash": "^2.4.1",
"istanbul": "~0.3.2",
"js-beautify": "^1.5.4",
"jshint": "~2.5.6",
"lodash": "^2.4.1",
"mocha": "~1.21.4",
"nan": "~1.3.0",
"node-gyp": "~1.0.2",
"node-pre-gyp": "~0.5.27",
"nodegit-promise": "~1.0.0",
"nw-gyp": "^0.12.4",
"promisify-node": "~0.1.2",
"request": "~2.45.0",
"tar": "~1.0.1"
Expand Down

Back | FazBrowse Home | New Git URL