rc.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. var minimist = require('minimist')
  2. var getAbi = require('node-abi').getAbi
  3. var env = process.env
  4. // Get `prebuild-install` arguments that were passed to the `npm` command
  5. if (env.npm_config_argv) {
  6. var npmargs = ['prebuild', 'compile', 'build-from-source', 'debug']
  7. try {
  8. var npmArgv = JSON.parse(env.npm_config_argv).cooked
  9. for (var i = 0; i < npmargs.length; ++i) {
  10. if (npmArgv.indexOf('--' + npmargs[i]) !== -1) {
  11. process.argv.push('--' + npmargs[i])
  12. }
  13. if (npmArgv.indexOf('--no-' + npmargs[i]) !== -1) {
  14. process.argv.push('--no-' + npmargs[i])
  15. }
  16. }
  17. if ((i = npmArgv.indexOf('--download')) !== -1) {
  18. process.argv.push(npmArgv[i], npmArgv[i + 1])
  19. }
  20. } catch (e) { }
  21. }
  22. // Get the configuration
  23. module.exports = function (pkg) {
  24. var pkgConf = pkg.config || {}
  25. var rc = require('rc')('prebuild-install', {
  26. target: pkgConf.target || env.npm_config_target || process.versions.node,
  27. runtime: pkgConf.runtime || env.npm_config_runtime || 'node',
  28. arch: pkgConf.arch || env.npm_config_arch || process.arch,
  29. libc: env.LIBC,
  30. platform: env.npm_config_platform || process.platform,
  31. debug: false,
  32. verbose: false,
  33. prebuild: true,
  34. compile: false,
  35. path: '.',
  36. proxy: env.npm_config_proxy || env['HTTP_PROXY'],
  37. 'https-proxy': env.npm_config_https_proxy || env['HTTPS_PROXY'],
  38. 'local-address': env.npm_config_local_address
  39. }, minimist(process.argv, {
  40. alias: {
  41. target: 't',
  42. runtime: 'r',
  43. help: 'h',
  44. arch: 'a',
  45. path: 'p',
  46. version: 'v',
  47. download: 'd',
  48. 'build-from-source': 'compile',
  49. compile: 'c'
  50. }
  51. }))
  52. if (rc.path === true) {
  53. delete rc.path
  54. }
  55. rc.abi = getAbi(rc.target, rc.runtime)
  56. return rc
  57. }
  58. // Print the configuration values when executed standalone for testing purposses
  59. if (!module.parent) {
  60. console.log(JSON.stringify(module.exports({}), null, 2))
  61. }