1- var os = require ( 'os' ) ;
2- var fs = require ( 'fs' ) ;
3- var path = require ( ' path' ) ;
4- var zlib = require ( ' zlib' ) ;
5- var exec = require ( ' child_process' ) . exec ;
6- var Q = require ( 'q' ) ;
7- var request = require ( ' request' ) ;
8- var tar = require ( ' tar' ) ;
9- var which = require ( ' which' ) ;
10- var rimraf = require ( ' rimraf' ) ;
1+ var os = require ( "os" ) ;
2+ var fs = require ( "fs" ) ;
3+ var path = require ( " path" ) ;
4+ var zlib = require ( " zlib" ) ;
5+ var exec = require ( " child_process" ) . exec ;
6+ var Q = require ( "q" ) ;
7+ var request = require ( " request" ) ;
8+ var tar = require ( " tar" ) ;
9+ var which = require ( " which" ) ;
10+ var rimraf = require ( " rimraf" ) ;
1111
1212// This will take in an object and find any matching keys in the environment
1313// to use as overrides.
@@ -43,15 +43,15 @@ var local = path.join.bind(path, __dirname);
4343
4444// Common reusable paths that can be overwritten by environment variables.
4545var paths = envOverride ( {
46- pkg : local ( ' package' ) ,
47- libgit2 : local ( ' vendor/libgit2/' ) ,
48- libssh2 : local ( ' vendor/libssh2/' ) ,
46+ pkg : local ( " package" ) ,
47+ libgit2 : local ( " vendor/libgit2/" ) ,
48+ libssh2 : local ( " vendor/libssh2/" ) ,
4949 sys : {
50- include : local ( ' include/sys/' ) ,
51- src : local ( ' src/sys/' ) ,
52- build : local ( ' build/Release/obj.target/src/sys/' )
50+ include : local ( " include/sys/" ) ,
51+ src : local ( " src/sys/" ) ,
52+ build : local ( " build/Release/obj.target/src/sys/" )
5353 } ,
54- release : local ( ' build/Release/' )
54+ release : local ( " build/Release/" )
5555} ) ;
5656
5757// Load the package.json.
@@ -60,40 +60,40 @@ var pkg = require(paths.pkg);
6060// Ensure all dependencies are available.
6161var dependencies = Q . allSettled ( [
6262 // This will prioritize `python2` over `python`, because we always want to
63- // work with Python 2.* if it' s available.
64- Q . nfcall ( which , ' python2' ) ,
65- Q . nfcall ( which , ' python' )
63+ // work with Python 2.* if it" s available.
64+ Q . nfcall ( which , " python2" ) ,
65+ Q . nfcall ( which , " python" )
6666] )
6767
6868// Determine if all the dependency requirements are met.
6969. then ( function ( results ) {
70- console . info ( ' [nodegit] Determining dependencies.' ) ;
70+ console . info ( " [nodegit] Determining dependencies." ) ;
7171
7272 // Assign to reusable variables.
7373 python = results [ 0 ] . value || results [ 1 ] . value ;
7474
7575 // Missing Python.
7676 if ( ! python ) {
77- throw new Error ( ' Python is required to build libgit2.' ) ;
77+ throw new Error ( " Python is required to build libgit2." ) ;
7878 }
7979
80- // Now lets check the Python version to ensure it' s < 3.
81- return Q . nfcall ( exec , python + ' --version' ) . then ( function ( version ) {
82- if ( version [ 1 ] . indexOf ( ' Python 3' ) === 0 ) {
83- throw new Error ( ' Incorrect version of Python, gyp requires < 3.' ) ;
80+ // Now lets check the Python version to ensure it" s < 3.
81+ return Q . nfcall ( exec , python + " --version" ) . then ( function ( version ) {
82+ if ( version [ 1 ] . indexOf ( " Python 3" ) === 0 ) {
83+ throw new Error ( " Incorrect version of Python, gyp requires < 3." ) ;
8484 }
8585 } ) ;
8686} )
8787
8888// Successfully found all dependencies. First step is to detect the vendor
8989// directory.
9090. then ( function ( ) {
91- console . info ( ' [nodegit] Detecting vendor/libgit2.' ) ;
91+ console . info ( " [nodegit] Detecting vendor/libgit2." ) ;
9292
93- return Q . ninvoke ( fs , ' stat' , paths . libgit2 ) . then ( function ( ) {
94- return Q . ninvoke ( fs , ' stat' , paths . libgit2 + pkg . libgit2 . sha ) ;
93+ return Q . ninvoke ( fs , " stat" , paths . libgit2 ) . then ( function ( ) {
94+ return Q . ninvoke ( fs , " stat" , paths . libgit2 + pkg . libgit2 . sha ) ;
9595 } ) . fail ( function ( ) {
96- console . info ( ' [nodegit] Removing outdated vendor/libgit2.' ) ;
96+ console . info ( " [nodegit] Removing outdated vendor/libgit2." ) ;
9797
9898 // This directory is outdated, remove.
9999 throw Q . ninvoke ( rimraf , null , paths . libgit2 ) ;
@@ -103,9 +103,9 @@ var dependencies = Q.allSettled([
103103// If the directory already exists, no need to refetch.
104104. fail ( function ( ) {
105105 // Otherwise fetch the libgit2 source from GitHub.
106- console . info ( ' [nodegit] Fetching vendor/libgit2.' ) ;
106+ console . info ( " [nodegit] Fetching vendor/libgit2." ) ;
107107
108- var url = ' https://github.com/libgit2/libgit2/tarball/' + pkg . libgit2 . sha ;
108+ var url = " https://github.com/libgit2/libgit2/tarball/" + pkg . libgit2 . sha ;
109109
110110 var extract = tar . Extract ( {
111111 path : paths . libgit2 ,
@@ -115,20 +115,20 @@ var dependencies = Q.allSettled([
115115 // First extract from Zlib and then extract from Tar.
116116 var expand = request . get ( url ) . pipe ( zlib . createUnzip ( ) ) . pipe ( extract ) ;
117117
118- return Q . ninvoke ( expand , 'on' , ' end' ) . then ( function ( ) {
118+ return Q . ninvoke ( expand , "on" , " end" ) . then ( function ( ) {
119119 // Write out a sha file for testing in the future.
120- return Q . ninvoke ( fs , ' writeFile' , paths . libgit2 + pkg . libgit2 . sha , '' ) ;
120+ return Q . ninvoke ( fs , " writeFile" , paths . libgit2 + pkg . libgit2 . sha , "" ) ;
121121 } ) ;
122122} )
123123
124124// Grab libssh2 if needed
125125. then ( function ( ) {
126- console . info ( ' [nodegit] Detecting vendor/libssh2.' ) ;
126+ console . info ( " [nodegit] Detecting vendor/libssh2." ) ;
127127
128- return Q . ninvoke ( fs , ' stat' , paths . libssh2 ) . then ( function ( ) {
129- return Q . ninvoke ( fs , ' stat' , paths . libssh2 + pkg . libssh2 . version ) ;
128+ return Q . ninvoke ( fs , " stat" , paths . libssh2 ) . then ( function ( ) {
129+ return Q . ninvoke ( fs , " stat" , paths . libssh2 + pkg . libssh2 . version ) ;
130130 } ) . fail ( function ( ) {
131- console . info ( ' [nodegit] Removing outdated vendor/libssh2.' ) ;
131+ console . info ( " [nodegit] Removing outdated vendor/libssh2." ) ;
132132
133133 // This directory is outdated, remove.
134134 throw Q . ninvoke ( rimraf , null , paths . libssh2 ) ;
@@ -138,7 +138,7 @@ var dependencies = Q.allSettled([
138138// If the directory already exists, no need to refetch.
139139. fail ( function ( ) {
140140 // Otherwise fetch the libssh2 source.
141- console . info ( ' [nodegit] Fetching vendor/libssh2.' ) ;
141+ console . info ( " [nodegit] Fetching vendor/libssh2." ) ;
142142
143143 var url = pkg . libssh2 . url ;
144144
@@ -150,59 +150,61 @@ var dependencies = Q.allSettled([
150150 // First extract from Zlib and then extract from Tar.
151151 var expand = request . get ( url ) . pipe ( zlib . createUnzip ( ) ) . pipe ( extract ) ;
152152
153- return Q . ninvoke ( expand , 'on' , ' end' ) . then ( function ( ) {
153+ return Q . ninvoke ( expand , "on" , " end" ) . then ( function ( ) {
154154 // Write out a sha file for testing in the future.
155- return Q . ninvoke ( fs , 'writeFile' , paths . libssh2 + pkg . libssh2 . version , '' ) ;
155+ return Q . ninvoke ( fs , "writeFile" , paths . libssh2 + pkg . libssh2 . version , "" ) ;
156+ } ) . then ( function ( ) {
157+ return Q . nfcall ( exec , "cd " + paths . libssh2 + " ; " + paths . libssh2 + "configure" ) ;
156158 } ) ;
157159} )
158160
159161// Build the native module using node-gyp.
160162. then ( function ( ) {
161- console . info ( ' [nodegit] Building native node module.' ) ;
162- var pythonFlag = ' --python ' + python ;
163+ console . info ( " [nodegit] Building native node module." ) ;
164+ var pythonFlag = " --python " + python ;
163165
164166 return Q . nfcall ( exec , systemPath ( [
165- '.' , ' node_modules' , ' .bin' , ' node-gyp clean configure build' + pythonFlag
167+ "." , " node_modules" , " .bin" , " node-gyp clean configure build" + pythonFlag
166168 ] ) , {
167- cwd : '.' ,
169+ cwd : "." ,
168170 maxBuffer : Number . MAX_VALUE
169171 } ) ;
170172} )
171173
172174// Attempt to fallback on a prebuilt binary.
173175. fail ( function ( message ) {
174- console . info ( ' [nodegit] Failed to build nodegit.' ) ;
175- console . info ( ' [nodegit] Attempting to fallback on a prebuilt binary.' ) ;
176+ console . info ( " [nodegit] Failed to build nodegit." ) ;
177+ console . info ( " [nodegit] Attempting to fallback on a prebuilt binary." ) ;
176178
177179 console . log ( message . stack ) ;
178180
179181 function fetchPrebuilt ( ) {
180- console . info ( ' [nodegit] Fetching binary from S3.' ) ;
182+ console . info ( " [nodegit] Fetching binary from S3." ) ;
181183
182184 // Using the node-pre-gyp module, attempt to fetch a compatible build.
183- return Q . nfcall ( exec , ' node-pre-gyp install' ) ;
185+ return Q . nfcall ( exec , " node-pre-gyp install" ) ;
184186 }
185187
186188 // Attempt to fetch prebuilt binary.
187- return Q . ninvoke ( fs , ' mkdir' , paths . release )
189+ return Q . ninvoke ( fs , " mkdir" , paths . release )
188190 . then ( fetchPrebuilt , fetchPrebuilt ) ;
189191} )
190192
191193// Display a warning message about failing to build native node module.
192194. fail ( function ( message ) {
193- console . info ( ' [nodegit] Failed to build and install nodegit.' ) ;
195+ console . info ( " [nodegit] Failed to build and install nodegit." ) ;
194196 console . info ( message . message ) ;
195197 console . info ( message . stack ) ;
196198} )
197199
198200// Display a success message.
199201. then ( function ( ) {
200- console . info ( ' [nodegit] Completed installation successfully.' ) ;
202+ console . info ( " [nodegit] Completed installation successfully." ) ;
201203} )
202204
203205// Display a warning message about failing to build native node module.
204206. fail ( function ( message ) {
205- console . info ( ' [nodegit] Failed to build nodegit.' ) ;
207+ console . info ( " [nodegit] Failed to build nodegit." ) ;
206208 console . info ( message . message ) ;
207209 console . info ( message . stack ) ;
208210} ) ;
0 commit comments