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