forked from ackle-dev/lightblue-repl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.py
52 lines (51 loc) · 1.77 KB
/
list.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import glob
from datetime import datetime
print('Collecting files...')
html = glob.glob('./' + '/**/*.html', recursive=True)
css = glob.glob('./' + '/**/*.css', recursive=True)
js = glob.glob('./' + '/**/*.js', recursive=True)
svg = glob.glob('./' + '/**/*.svg', recursive=True)
ico = glob.glob('./' + '/**/*.ico', recursive=True)
wav = glob.glob('./' + '/**/*.wav', recursive=True)
mp3 = glob.glob('./' + '/**/*.mp3', recursive=True)
# ogg = glob.glob('./' + '/**/*.ogg', recursive=True)
print('Writing...')
split = "',\n\t'"
text = "[\n\t'"+split.join(html)+split+split.join(css)+split+split.join(js)+split+split.join(svg)+split+split.join(ico)+split+split.join(wav)+split+split.join(mp3)+"'\n]"
print(text)
list = open('list.txt', 'w')
list.write(text)
list.close()
split = "',\n\t\t\t\t'"
text = "[\n\t\t\t\t'"+split.join(html)+split+split.join(css)+split+split.join(js)+split+split.join(svg)+split+split.join(ico)+split+split.join(wav)+split+split.join(mp3)+"'\n\t\t\t]"
sw = open('service-worker.js', 'w')
sw.write("""
/*
\t! when updating this file, update the template in `/list.py`.
\t$ the list of files to be cached comes from the script in `/list.py`.
\t$ this list can be updated manually by running `/list.py`.
*/
/*
\tThis comment was generated by `/list.py`.
\tTimestamp: """ + datetime.now().strftime("%m/%d/%Y %H:%M:%S PST") + """
*/
self.addEventListener("install", (event) => {
\tevent.waitUntil(
\t\tcaches.open("lightblue").then((cache) => {
\t\t\tcache.addAll(""" + text + """);
\t\t})
\t);
});
self.addEventListener("fetch", (event) => {
\tevent.respondWith(
\t\tfetch(event.request).then((response) => {
\t\t\treturn response;
\t\t}).catch(async (error) => {
\t\t\treturn caches.match(event.request).then((cacheRes) => {
\t\t\t\treturn cacheRes;
\t\t\t});
\t\t})
\t);
});
""")
print('Done.')