format-manifest-filename.js 940 B

123456789101112131415161718192021222324252627282930
  1. "use strict";
  2. /*
  3. Copyright 2018 Google LLC
  4. Use of this source code is governed by an MIT-style
  5. license that can be found in the LICENSE file or at
  6. https://opensource.org/licenses/MIT.
  7. */
  8. /**
  9. * Looks for a placeholder string in originalFilename, and replaces it with a
  10. * value provided.
  11. *
  12. * @param {string} originalFilename
  13. * @param {string} manifestHash
  14. * @return {string}
  15. *
  16. * @private
  17. */
  18. module.exports = (originalFilename, manifestHash) => {
  19. const manifestHashPlaceholder = '[manifestHash]';
  20. const replacedFilename = originalFilename.replace(manifestHashPlaceholder, manifestHash);
  21. if (replacedFilename === originalFilename) {
  22. throw new Error(`Your configured precacheManifestFilename option, ` + `'${originalFilename}', must contain the placeholder string ` + `'${manifestHashPlaceholder}' somewhere. For example, ` + `'precache-manifest.${manifestHashPlaceholder}.js'`);
  23. }
  24. return replacedFilename;
  25. };