| 1 |
#! /usr/bin/env node |
| 2 |
|
| 3 |
const { relative } = require('path') |
| 4 |
const pkgContents = require('../') |
| 5 |
|
| 6 |
const usage = `Usage: |
| 7 |
installed-package-contents <path> [-d<n> --depth=<n>] |
| 8 |
|
| 9 |
Lists the files installed for a package specified by <path>. |
| 10 |
|
| 11 |
Options: |
| 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 |
|
| 17 |
const options = {} |
| 18 |
|
| 19 |
process.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 |
|
| 31 |
if (!options.path) { |
| 32 |
console.error('ERROR: no path provided') |
| 33 |
console.error(usage) |
| 34 |
process.exit(1) |
| 35 |
} |
| 36 |
|
| 37 |
const cwd = process.cwd() |
| 38 |
|
| 39 |
pkgContents(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 |
}) |