list.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. const stripAnsi = require('strip-ansi')
  2. const iPhoneBackup = require('../util/iphone_backup.js').iPhoneBackup
  3. const normalizeCols = require('../util/normalize.js')
  4. const chalk = require('chalk')
  5. const fs = require('fs-extra')
  6. module.exports.name = 'list'
  7. module.exports.description = 'List of all backups. alias for -l'
  8. // Specify this reporter requires a backup.
  9. // The second parameter to func() is now a backup instead of the path to one.
  10. module.exports.requiresBackup = false
  11. // Specify this reporter supports the promises API for allowing chaining of reports.
  12. module.exports.usesPromises = true
  13. module.exports.func = function (program, base, resolve, reject) {
  14. var items = fs.readdirSync(base, { encoding: 'utf8' })
  15. .filter(el => (el !== '.DS_Store'))
  16. .map(file => iPhoneBackup.fromID(file, base))
  17. .filter(el => el.manifest && el.status)
  18. var output = program.formatter.format(items, {
  19. program: program,
  20. columns: {
  21. 'UDID': el => el.id,
  22. 'Encryption': el => el.manifest ? (el.manifest.IsEncrypted ? 'encrypted' : 'not encrypted') : 'unknown',
  23. 'Date': el => el.status ? new Date(el.status.Date).toLocaleString() : '',
  24. 'Device Name': el => el.manifest ? el.manifest.Lockdown.DeviceName : 'Unknown Device',
  25. 'Serial #': el => el.manifest.Lockdown.SerialNumber,
  26. 'iOS Version': el => el.manifest ? el.manifest.Lockdown.ProductVersion : '?',
  27. 'Backup Version': el => el.status ? el.status.Version : '?'
  28. }
  29. })
  30. resolve(output)
  31. }