Skip to content

Commit 22064a9

Browse files
committed
look for node-webkit in engines of root package.json
1 parent e414f73 commit 22064a9

2 files changed

Lines changed: 50 additions & 14 deletions

File tree

install.js

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var Promise = require("nodegit-promise");
77
var promisify = require("promisify-node");
88
var request = require("request");
99
var fse = promisify(require("fs-extra"));
10+
var findParentDir = promisify(require('find-parent-dir'));
1011
fse.ensureDir = promisify(fse.ensureDir, function() { return true; });
1112

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

1819
// If the build only flag is set.
1920
var buildOnly = process.env.BUILD_ONLY;
21+
var nodeWebkit = false;
2022

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

7476
fse.ensureDir(path.resolve(__dirname, paths.release))
77+
.then(detectNodeWebkit.call(null, __dirname))
7578
.then(fetch)
7679
.then(finish, compile)
7780
.done()
7881

7982
function fetch() {
80-
if (!buildOnly) {
81-
console.info("[nodegit] Fetching binary from S3.");
83+
console.info("[nodegit] Fetching binary from S3.");
8284

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

87-
throw new Error("BUILD_ONLY is set to true, no fetching allowed.");
89+
if (buildOnly) {
90+
throw new Error("BUILD_ONLY is set to true, no fetching allowed.");
91+
}
92+
93+
// Using the node-pre-gyp module, attempt to fetch a compatible build.
94+
return exec("node-pre-gyp install");
8895
}
8996

90-
function compile() {
91-
if (!buildOnly) {
97+
function compile(err) {
98+
if (buildOnly || nodeWebkit) {
99+
console.info("[nodegit] " + err.message);
100+
}
101+
else {
92102
console.info("[nodegit] Failed to install prebuilt, attempting compile.");
93103
}
94104

@@ -173,11 +183,21 @@ function getVendorLib(name, url) {
173183

174184
function buildNative() {
175185
return exec("cd " + __dirname).then(function() {
176-
console.info("[nodegit] Building native node module.");
177-
var pythonFlag = " --python \"" + pythonPath + "\"";
178-
var cmd = path.resolve(systemPath([
179-
".", "node_modules", ".bin", "node-gyp clean configure build" + pythonFlag
180-
]));
186+
if (nodeWebkit) {
187+
console.info("[nodegit] Building native node-webkit module.");
188+
}
189+
else {
190+
console.info("[nodegit] Building native node module.");
191+
}
192+
193+
var builder = nodeWebkit ? "nw-gyp" : "node-gyp";
194+
195+
var cmd = path.resolve(".", "node_modules", ".bin", builder)
196+
+ " clean configure "
197+
+ (nodeWebkit ? "--target=\"" + nodeWebkit + "\"": "")
198+
+ " build " + pythonFlag
199+
+ "--python \"" + pythonPath + "\""
200+
181201
var opts = {
182202
cwd: __dirname,
183203
maxBuffer: Number.MAX_VALUE
@@ -186,6 +206,20 @@ function buildNative() {
186206
})
187207
}
188208

209+
function detectNodeWebkit(directory) {
210+
if (directory) {
211+
var pkg = require(path.resolve(directory, "package.json"));
212+
213+
nodeWebkit = pkg.engines && pkg.engines["node-webkit"];
214+
215+
return findParentDir(path.resolve(directory, ".."), "package.json")
216+
.then(detectNodeWebkit);
217+
}
218+
else {
219+
return Promise.resolve();
220+
}
221+
}
222+
189223
function finish() {
190224
console.info("[nodegit] Completed installation successfully.");
191225
return Promise.resolve().done();
@@ -194,6 +228,6 @@ function finish() {
194228
function fail(message) {
195229
console.info("[nodegit] Failed to build and install nodegit.");
196230
console.info(message.message);
197-
//console.info(message.stack);
231+
198232
return Promise.resolve().done();
199233
}

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,18 @@
6161
],
6262
"dependencies": {
6363
"combyne": "~0.6.2",
64+
"find-parent-dir": "^0.3.0",
6465
"fs-extra": "^0.12.0",
65-
"lodash": "^2.4.1",
6666
"istanbul": "~0.3.2",
6767
"js-beautify": "^1.5.4",
6868
"jshint": "~2.5.6",
69+
"lodash": "^2.4.1",
6970
"mocha": "~1.21.4",
7071
"nan": "~1.3.0",
7172
"node-gyp": "~1.0.2",
7273
"node-pre-gyp": "~0.5.27",
7374
"nodegit-promise": "~1.0.0",
75+
"nw-gyp": "^0.12.4",
7476
"promisify-node": "~0.1.2",
7577
"request": "~2.45.0",
7678
"tar": "~1.0.1"

0 commit comments

Comments
 (0)