blob: e849a081fc2e4347cceeec2ae502774d0aadd647 [file] [log] [blame]
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import '../../globals.dart' as globals;
/// The caching strategy for the generated service worker.
enum ServiceWorkerStrategy {
/// Download the app shell eagerly and all other assets lazily.
/// Prefer the offline cached version.
/// Do not generate a service worker,
/// Generate a service worker with an app-specific cache name a map of
/// resource files.
/// The tool embeds file hashes directly into the worker so that the byte for byte
/// invalidation will automatically reactivate workers whenever a new
/// version is deployed.
String generateServiceWorker(
String fileGeneratorsPath,
Map<String, String> resources,
List<String> coreBundle, {
required ServiceWorkerStrategy serviceWorkerStrategy,
required String baseHref,
}) {
if (serviceWorkerStrategy == ServiceWorkerStrategy.none) {
return '';
final String flutterServiceWorkerJsPath = globals.localFileSystem.path.join(
return globals.localFileSystem
.replaceAll(r'$$BASE_HREF', '"$baseHref"'),
'{${<String, String> entry) => '"${entry.key}": "${entry.value}"').join(",\n")}}',
'[${ file) => '"$file"').join(',\n')}]',