generate-sw-string.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 generateSWStringSchema = require('./options/generate-sw-string-schema');
  12. const getFileManifestEntries = require('../lib/get-file-manifest-entries');
  13. const populateSWTemplate = require('../lib/populate-sw-template');
  14. const validate = require('./options/validate');
  15. /**
  16. * This method generates a service worker based on the configuration options
  17. * provided.
  18. *
  19. * @param {Object} config Please refer to the
  20. * [configuration guide](https://developers.google.com/web/tools/workbox/modules/workbox-build#generateswstring_mode).
  21. * @return {Promise<{swString: string, warnings: Array<string>}>} A promise that
  22. * resolves once the service worker template is populated. The `swString`
  23. * property contains a string representation of the full service worker code.
  24. * Any non-fatal warning messages will be returned via `warnings`.
  25. *
  26. * @memberof module:workbox-build
  27. */
  28. function generateSWString(_x) {
  29. return _generateSWString.apply(this, arguments);
  30. }
  31. function _generateSWString() {
  32. _generateSWString = (0, _asyncToGenerator2.default)(function* (config) {
  33. // This check needs to be done before validation, since the deprecated options
  34. // will be renamed.
  35. const deprecationWarnings = checkForDeprecatedOptions(config);
  36. const options = validate(config, generateSWStringSchema);
  37. const _ref = yield getFileManifestEntries(options),
  38. manifestEntries = _ref.manifestEntries,
  39. warnings = _ref.warnings;
  40. const swString = yield populateSWTemplate(Object.assign({
  41. manifestEntries
  42. }, options)); // Add in any deprecation warnings.
  43. warnings.push(...deprecationWarnings);
  44. return {
  45. swString,
  46. warnings
  47. };
  48. });
  49. return _generateSWString.apply(this, arguments);
  50. }
  51. module.exports = generateSWString;