index.js 662 B

12345678910111213141516171819202122232425
  1. #!/usr/bin/env node
  2. const dirs = []
  3. let doSort = false
  4. process.argv.slice(2).forEach(arg => {
  5. if (arg === '-h' || arg === '--help') {
  6. console.log('usage: npm-packlist [-s --sort] [directory, directory, ...]')
  7. process.exit(0)
  8. } else if (arg === '-s' || arg === '--sort')
  9. doSort = true
  10. else
  11. dirs.push(arg)
  12. })
  13. const sort = list => doSort ? list.sort((a, b) => a.localeCompare(b, 'en')) : list
  14. const packlist = require('../')
  15. if (!dirs.length)
  16. console.log(sort(packlist.sync({ path: process.cwd() })).join('\n'))
  17. else {
  18. dirs.forEach(path => {
  19. console.log(`> ${path}`)
  20. console.log(sort(packlist.sync({ path })).join('\n'))
  21. })
  22. }