index.js
1006 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env node
'use strict'
const packlist = require('../')
const dirs = []
let doSort = false
process.argv.slice(2).forEach(arg => {
if (arg === '-h' || arg === '--help') {
console.log('usage: npm-packlist [-s --sort] [directory, directory, ...]')
process.exit(0)
} else if (arg === '-s' || arg === '--sort') {
doSort = true
} else {
dirs.push(arg)
}
})
const sort = list => doSort ? list.sort((a, b) => a.localeCompare(b, 'en')) : list
const main = async () => {
if (!dirs.length) {
const results = await packlist({ path: process.cwd() })
console.log(sort(results).join('\n'))
} else {
for (const dir of dirs) {
console.group(`> ${dir}`)
const results = await packlist({ path: dir })
console.log(sort(results).join('\n'))
console.groupEnd()
}
}
}
// coverage disabled for catch handler because we don't need to test that
main().catch(/* istanbul ignore next */(err) => {
process.exitCode = 1
console.error(err.stack)
})