get-manifest.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
  4. /*
  5. Copyright 2018 Google LLC
  6. Use of this source code is governed by an MIT-style
  7. license that can be found in the LICENSE file or at
  8. https://opensource.org/licenses/MIT.
  9. */
  10. const checkForDeprecatedOptions = require('../lib/check-for-deprecated-options');
  11. const getFileManifestEntries = require('../lib/get-file-manifest-entries');
  12. const getManifestSchema = require('./options/get-manifest-schema');
  13. const validate = require('./options/validate');
  14. /**
  15. * This method returns a list of URLs to precache, referred to as a "precache
  16. * manifest", along with details about the number of entries and their size,
  17. * based on the options you provide.
  18. *
  19. * @param {Object} config Please refer to the
  20. * [configuration guide](https://developers.google.com/web/tools/workbox/modules/workbox-build#getmanifest_mode).
  21. * @return {Promise<{manifestEntries: Array<ManifestEntry>,
  22. * count: number, size: number, warnings: Array<string>}>} A promise that
  23. * resolves once the precache manifest is determined. The `size` property
  24. * contains the aggregate size of all the precached entries, in bytes, the
  25. * `count` property contains the total number of precached entries, and the
  26. * `manifestEntries` property contains all the `ManifestEntry` items. Any
  27. * non-fatal warning messages will be returned via `warnings`.
  28. *
  29. * @memberof module:workbox-build
  30. */
  31. function getManifest(_x) {
  32. return _getManifest.apply(this, arguments);
  33. }
  34. function _getManifest() {
  35. _getManifest = (0, _asyncToGenerator2.default)(function* (config) {
  36. // This check needs to be done before validation, since the deprecated options
  37. // will be renamed.
  38. const deprecationWarnings = checkForDeprecatedOptions(config);
  39. const options = validate(config, getManifestSchema);
  40. const _ref = yield getFileManifestEntries(options),
  41. manifestEntries = _ref.manifestEntries,
  42. count = _ref.count,
  43. size = _ref.size,
  44. warnings = _ref.warnings; // Add in any deprecation warnings.
  45. warnings.push(...deprecationWarnings);
  46. return {
  47. manifestEntries,
  48. count,
  49. size,
  50. warnings
  51. };
  52. });
  53. return _getManifest.apply(this, arguments);
  54. }
  55. module.exports = getManifest;