forked from superhighfives/an-almost-static-stack
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgenerate-appcache.js
42 lines (37 loc) · 973 Bytes
/
generate-appcache.js
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
const SW_PRECACHE_CONFIG = "./sw-precache-config";
const OUT_FILE = "../build/manifest.appcache";
const glob = require("globby");
const {
staticFileGlobs,
stripPrefix,
navigateFallback
} = require(SW_PRECACHE_CONFIG);
const fs = require("fs");
const path = require("path");
glob(staticFileGlobs).then(files => {
// filter out directories
files = files.filter(file => fs.statSync(file).isFile());
// strip out prefix
files = files.map(file => file.replace(stripPrefix, ""));
const index = files.indexOf(navigateFallback);
if (index > -1) {
files.splice(index, 1);
}
const out = [
"CACHE MANIFEST",
`# version ${new Date().getTime()}`,
"",
"CACHE:",
...files,
"",
"NETWORK:",
"*",
"http://*",
"https://*",
"",
"FALLBACK:",
`/ ${navigateFallback}`
].join("\n");
fs.writeFileSync(path.join(__dirname, OUT_FILE), out);
console.log(`Wrote ${OUT_FILE} with ${files.length} resources.`);
});