|
| 1 | +// Mostly copied from https://github.com/nodegit/nodegit/blob/288ab93/lifecycleScripts/postinstall.js |
| 2 | +var fse = require( 'fs-extra' ); |
| 3 | +var path = require( 'path' ); |
| 4 | +var log = require( 'npmlog' ); |
| 5 | + |
| 6 | +var buildFlags = require( './buildFlags' ); |
| 7 | +var exec = require( './execPromise' ); |
| 8 | + |
| 9 | +log.heading = 'node-libcurl'; |
| 10 | + |
| 11 | +var rootPath = path.join( __dirname, '..' ); |
| 12 | + |
| 13 | +function printStandardLibError() { |
| 14 | + log.error( '', 'the latest libstdc++ is missing on your system!' ); |
| 15 | + log.error( 'On Ubuntu you can install it using:' ); |
| 16 | + log.error( '$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test' ); |
| 17 | + log.error( '$ sudo apt-get update' ); |
| 18 | + log.error( '$ sudo apt-get install libstdc++-4.9-dev' ); |
| 19 | +} |
| 20 | + |
| 21 | +module.exports = function install() { |
| 22 | + if ( buildFlags.isGitRepo ) { |
| 23 | + // If we're building NodeGit from a git repo we aren't going to do any |
| 24 | + // cleaning up |
| 25 | + return Promise.resolve(); |
| 26 | + } |
| 27 | + |
| 28 | + if ( buildFlags.isElectron || buildFlags.isNWjs ) { |
| 29 | + // If we're building for electron or NWjs, we're unable to require the |
| 30 | + // built library so we have to just assume success, unfortunately. |
| 31 | + return Promise.resolve(); |
| 32 | + } |
| 33 | + |
| 34 | + return exec( 'node "' + path.join( rootPath, 'lib/Curl.js"' ) ) |
| 35 | + .catch( function( e ) { |
| 36 | + if ( ~e.toString().indexOf( 'Module version mismatch' ) ) { |
| 37 | + log.warn( |
| 38 | + '', 'NodeGit was built for a different version of node.' |
| 39 | + ); |
| 40 | + log.warn( |
| 41 | + '', 'If you are building NodeGit for electron/nwjs you can ignore this warning.' |
| 42 | + ); |
| 43 | + } else { |
| 44 | + throw e; |
| 45 | + } |
| 46 | + }).then( function() { |
| 47 | + // Is we're using node-libcurl from a package manager then let's clean up after |
| 48 | + // ourselves when we install successfully. |
| 49 | + if ( !buildFlags.mustBuild ) { |
| 50 | + // We can't remove the source files yet because apparently the |
| 51 | + // "standard workflow" for native node modules in Electron/nwjs is to |
| 52 | + // build them for node and then nah eff that noise let's rebuild them |
| 53 | + // again for the actual platform! Hurray!!! When that madness is dead |
| 54 | + // we can clean up the source which is a serious amount of data. |
| 55 | + // fse.removeSync(path.join(rootPath, "vendor")); |
| 56 | + // fse.removeSync(path.join(rootPath, "src")); |
| 57 | + // fse.removeSync(path.join(rootPath, "include")); |
| 58 | + fse.removeSync( path.join( rootPath, 'build' ) ); |
| 59 | + if ( fse.pathExists( path.join( rootPath, 'curl-for-windows' ) ) ) { |
| 60 | + fse.removeSync( path.join( rootPath, 'curl-for-windows' ) ); |
| 61 | + } |
| 62 | + } |
| 63 | + }); |
| 64 | +}; |
| 65 | + |
| 66 | +// Called on the command line |
| 67 | +if ( require.main === module ) { |
| 68 | + module.exports() |
| 69 | + .catch( function( e ) { |
| 70 | + log.warn( '', 'Could not finish postinstall' ); |
| 71 | + |
| 72 | + if ( process.platform === 'linux' && ~e.toString().indexOf( 'libstdc++' ) ) { |
| 73 | + printStandardLibError(); |
| 74 | + } else { |
| 75 | + log.error( e ); |
| 76 | + } |
| 77 | + }); |
| 78 | +} |
0 commit comments