calculateProcessingProgress.js 783 B

1234567891011121314151617181920212223242526
  1. module.exports = function calculateProcessingProgress (files) {
  2. const values = []
  3. let mode
  4. let message
  5. for (const { progress } of Object.values(files)) {
  6. const { preprocess, postprocess } = progress
  7. // In the future we should probably do this differently. For now we'll take the
  8. // mode and message from the first file…
  9. if (message == null && (preprocess || postprocess)) {
  10. ({ mode, message } = preprocess || postprocess)
  11. }
  12. if (preprocess?.mode === 'determinate') values.push(preprocess.value)
  13. if (postprocess?.mode === 'determinate') values.push(postprocess.value)
  14. }
  15. const value = values.reduce((total, progressValue) => {
  16. return total + progressValue / values.length
  17. }, 0)
  18. return {
  19. mode,
  20. message,
  21. value,
  22. }
  23. }