index.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #! /usr/bin/env node
  2. const { relative } = require('path')
  3. const pkgContents = require('../')
  4. const usage = `Usage:
  5. installed-package-contents <path> [-d<n> --depth=<n>]
  6. Lists the files installed for a package specified by <path>.
  7. Options:
  8. -d<n> --depth=<n> Provide a numeric value ("Infinity" is allowed)
  9. to specify how deep in the file tree to traverse.
  10. Default=1
  11. -h --help Show this usage information`
  12. const options = {}
  13. process.argv.slice(2).forEach(arg => {
  14. let match
  15. if ((match = arg.match(/^(?:--depth=|-d)([0-9]+|Infinity)/))) {
  16. options.depth = +match[1]
  17. } else if (arg === '-h' || arg === '--help') {
  18. console.log(usage)
  19. process.exit(0)
  20. } else {
  21. options.path = arg
  22. }
  23. })
  24. if (!options.path) {
  25. console.error('ERROR: no path provided')
  26. console.error(usage)
  27. process.exit(1)
  28. }
  29. const cwd = process.cwd()
  30. pkgContents(options)
  31. .then(list => list.sort().forEach(p => console.log(relative(cwd, p))))
  32. .catch(/* istanbul ignore next - pretty unusual */ er => {
  33. console.error(er)
  34. process.exit(1)
  35. })