Skip to content

Commit

Permalink
option to exclude files from serviceworker
Browse files Browse the repository at this point in the history
  • Loading branch information
sheppard committed Mar 20, 2024
1 parent 108da3f commit 703e562
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
Empty file.
2 changes: 2 additions & 0 deletions tests/commands/serviceworker/wq.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ serviceworker:
output: output/service-worker.js
cache:
- ../input/*.js
exclude:
- test.dev.js
10 changes: 9 additions & 1 deletion wq/build/commands/serviceworker.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
multiple=True,
help="File(s) or directories to cache",
)
@click.option(
"--exclude",
type=click.Path(),
multiple=True,
help="Individual file names to exclude from cache",
)
@click.option(
"--scope",
type=str,
Expand All @@ -36,7 +42,7 @@
help="Timeout to use before falling back to cache.",
)
@wq.pass_config
def serviceworker(config, version, template, output, cache, scope, timeout):
def serviceworker(config, version, template, output, cache, exclude, scope, timeout):
"""
Generate a service-worker.js. The default service worker will function as
follows:
Expand Down Expand Up @@ -79,6 +85,8 @@ def serviceworker(config, version, template, output, cache, scope, timeout):
paths.append(scope + path)
continue
for filename in glob(os.path.join(basedir, path)):
if os.path.basename(filename) in exclude:
continue
paths.append(filename.replace(basedir + "/", scope))

cache = ",".join(json.dumps(path) for path in paths)
Expand Down

0 comments on commit 703e562

Please sign in to comment.