bin.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env node
  2. var path = require('path')
  3. var log = require('npmlog')
  4. var fs = require('fs')
  5. var extend = require('xtend')
  6. var pkg = require(path.resolve('package.json'))
  7. var rc = require('./rc')(pkg)
  8. var download = require('./download')
  9. var util = require('./util')
  10. var prebuildClientVersion = require('./package.json').version
  11. if (rc.version) {
  12. console.log(prebuildClientVersion)
  13. process.exit(0)
  14. }
  15. if (rc.path) process.chdir(rc.path)
  16. log.heading = 'prebuild-install'
  17. if (rc.verbose) {
  18. log.level = 'verbose'
  19. }
  20. if (!fs.existsSync('package.json')) {
  21. log.error('setup', 'No package.json found. Aborting...')
  22. process.exit(1)
  23. }
  24. if (rc.help) {
  25. console.error(fs.readFileSync(path.join(__dirname, 'help.txt'), 'utf-8'))
  26. process.exit(0)
  27. }
  28. log.info('begin', 'Prebuild-install version', prebuildClientVersion)
  29. var opts = extend(rc, {pkg: pkg, log: log})
  30. var execPath = process.env.npm_execpath || process.env.NPM_CLI_JS
  31. if (util.isYarnPath(execPath) && /node_modules/.test(process.cwd())) {
  32. // From yarn repository
  33. } else if (!(typeof pkg._from === 'string')) {
  34. log.info('install', 'installing standalone, skipping download.')
  35. process.exit(1)
  36. } else if (pkg._from.length > 4 && pkg._from.substr(0, 4) === 'git+') {
  37. log.info('install', 'installing from git repository, skipping download.')
  38. process.exit(1)
  39. } else if (opts.compile === true || opts.prebuild === false) {
  40. log.info('install', '--build-from-source specified, not attempting download.')
  41. process.exit(1)
  42. }
  43. download(opts, function (err) {
  44. if (err) {
  45. log.warn('install', err.message)
  46. return process.exit(1)
  47. }
  48. log.info('install', 'Successfully installed prebuilt binary!')
  49. })