11var promisify = require ( "promisify-node" ) ;
22var path = require ( "path" ) ;
33var fs = require ( "fs" ) ;
4-
4+ var cp = require ( "child_process" ) ;
55var prepareForBuild = require ( "./prepareForBuild" ) ;
66
77var exec = promisify ( function ( command , opts , callback ) {
8- return require ( "child_process" ) . exec ( command , opts , callback ) ;
8+ return cp . exec ( command , opts , callback ) ;
99} ) ;
1010
1111var fromRegistry ;
@@ -52,7 +52,9 @@ function installPrebuilt() {
5252
5353function pathForTool ( name ) {
5454 var toolPath = path . resolve ( "." , "node_modules" , ".bin" , name ) ;
55- toolPath = "\"" + toolPath + "\"" ;
55+ if ( process . platform == "win32" ) {
56+ toolPath += ".cmd" ;
57+ }
5658 return toolPath ;
5759}
5860
@@ -72,7 +74,8 @@ function build() {
7274 var opts = {
7375 cwd : "." ,
7476 maxBuffer : Number . MAX_VALUE ,
75- env : process . env
77+ env : process . env ,
78+ stdio : "inherit"
7679 } ;
7780
7881 var builder = "node-gyp" ;
@@ -104,26 +107,27 @@ function build() {
104107
105108 opts . env . HOME = path . join ( home , ".nodegit-gyp" ) ;
106109
107- var cmd = [
108- pathForTool ( builder ) ,
110+ var cmd = pathForTool ( builder ) ;
111+ var args = [
109112 "rebuild" ,
110113 debug ,
111114 target ,
112115 distUrl
113116 ]
114117 . join ( " " )
115- . trim ( ) ;
116-
117- return exec ( cmd , opts )
118- . then ( function ( ) {
119- console . info ( "[nodegit] Compilation complete." ) ;
120- console . info ( "[nodegit] Completed installation successfully." ) ;
121- process . exitCode = 0 ;
122- } ,
123- function ( err , stderr ) {
124- console . error ( err ) ;
125- console . error ( stderr ) ;
118+ . trim ( )
119+ . split ( " " ) ;
120+ return new Promise ( function ( resolve , reject ) {
121+ var child = cp . spawn ( cmd , args , opts ) ;
122+ child . on ( "close" , function ( code ) {
123+ console . log ( code ) ;
124+ if ( code ) {
125+ reject ( code ) ;
126126 process . exitCode = 13 ;
127127 }
128- ) ;
128+ else {
129+ resolve ( ) ;
130+ }
131+ } )
132+ } ) ;
129133}
0 commit comments