_example.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // First, give it a name!
  2. module.exports.name = 'example module'
  3. // Provide a description.
  4. module.exports.description = 'An example module to show how it works'
  5. // Specify this reporter requires a backup.
  6. // The second parameter to func() is now a backup instead of the path to one.
  7. // Most reporting types should use this.
  8. module.exports.requiresBackup = true
  9. // Should this report be skipped in automated reports?
  10. // This is used when the 'all' report type is specified, and all possible reports are generated.
  11. // with this set to true, the report WILL NOT run when report type = 'all'
  12. // Most reporting types shouldn't need this.
  13. module.exports.requiresInteractivity = true
  14. // Specify this reporter supports the promises API for allowing chaining of reports.
  15. // All modules should use this.
  16. module.exports.usesPromises = true
  17. // Specify this only works for iOS 10+
  18. // If it is iOS-version specific, you can specify version information here.
  19. // You may provide a comma separated string such as ">=6.0,<11.0" to indicate ranges.
  20. module.exports.supportedVersions = '>=10.0'
  21. // Most reports will use this pattern.
  22. // Reporting function (for usesPromises = true)
  23. module.exports.func = function (program, backup, resolve, reject) {
  24. // This function will be called with the `commander` program, and the iPhoneBackup instance as arguments
  25. // It MUST resolve() the final result, or reject() if there's an error
  26. // First, fetch some data. This variable should be an array of objects representing each row in a report.
  27. // This would be replaced with a function from the backup object.
  28. let data = backup.getData()
  29. // Next, pass it to the user-selected formatter.
  30. var result = program.formatter.format(data, {
  31. // Provide the program options
  32. program: program,
  33. // A dictionary of items to be displayed as formatted data.
  34. // The key is the column name, the value is a function that returns the value given an object representing a row.
  35. columns: {
  36. 'Column-Name': row => row.ROWID
  37. }
  38. })
  39. // Resolve the promise with the result.
  40. // This ensures proper file output and multi-reporting.
  41. resolve(result)
  42. }
  43. // --- OR ---
  44. // You can also provide an array of functions instead of using `module.exports.func`.
  45. // These functions *should* be independent ranges to ensure reliable execution.
  46. module.exports.functions = {
  47. '>=10.0': function (program, backup, resolve, reject) {
  48. // This function would be called for iOS 10+.
  49. // format and resolve() in the same manner as the example above.
  50. },
  51. '>=9.0,<10.0': function (program, backup) {
  52. // This function would be called for all iOS 9.
  53. // format and resolve() in the same manner as the example above.
  54. }
  55. }