@@ -7,6 +7,7 @@ var Promise = require("nodegit-promise");
77var promisify = require ( "promisify-node" ) ;
88var request = require ( "request" ) ;
99var fse = promisify ( require ( "fs-extra" ) ) ;
10+ var findParentDir = promisify ( require ( 'find-parent-dir' ) ) ;
1011fse . ensureDir = promisify ( fse . ensureDir , function ( ) { return true ; } ) ;
1112
1213var 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.
1920var 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
7476fse . ensureDir ( path . resolve ( __dirname , paths . release ) )
77+ . then ( detectNodeWebkit . call ( null , __dirname ) )
7578. then ( fetch )
7679. then ( finish , compile )
7780. done ( )
7881
7982function 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
174184function 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+
189223function finish ( ) {
190224 console . info ( "[nodegit] Completed installation successfully." ) ;
191225 return Promise . resolve ( ) . done ( ) ;
@@ -194,6 +228,6 @@ function finish() {
194228function 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}
0 commit comments