printInstallDetails.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. Copyright 2018 Google LLC
  3. Use of this source code is governed by an MIT-style
  4. license that can be found in the LICENSE file or at
  5. https://opensource.org/licenses/MIT.
  6. */
  7. import { logger } from 'workbox-core/_private/logger.js';
  8. import '../_version.js';
  9. /**
  10. * @param {string} groupTitle
  11. * @param {Array<string>} urls
  12. *
  13. * @private
  14. */
  15. function _nestedGroup(groupTitle, urls) {
  16. if (urls.length === 0) {
  17. return;
  18. }
  19. logger.groupCollapsed(groupTitle);
  20. for (const url of urls) {
  21. logger.log(url);
  22. }
  23. logger.groupEnd();
  24. }
  25. /**
  26. * @param {Array<string>} urlsToPrecache
  27. * @param {Array<string>} urlsAlreadyPrecached
  28. *
  29. * @private
  30. * @memberof module:workbox-precaching
  31. */
  32. export function printInstallDetails(urlsToPrecache, urlsAlreadyPrecached) {
  33. const precachedCount = urlsToPrecache.length;
  34. const alreadyPrecachedCount = urlsAlreadyPrecached.length;
  35. if (precachedCount || alreadyPrecachedCount) {
  36. let message = `Precaching ${precachedCount} file${precachedCount === 1 ? '' : 's'}.`;
  37. if (alreadyPrecachedCount > 0) {
  38. message += ` ${alreadyPrecachedCount} ` +
  39. `file${alreadyPrecachedCount === 1 ? ' is' : 's are'} already cached.`;
  40. }
  41. logger.groupCollapsed(message);
  42. _nestedGroup(`View newly precached URLs.`, urlsToPrecache);
  43. _nestedGroup(`View previously precached URLs.`, urlsAlreadyPrecached);
  44. logger.groupEnd();
  45. }
  46. }