-
Notifications
You must be signed in to change notification settings - Fork 3
/
createAppCache.js
56 lines (46 loc) · 1.26 KB
/
createAppCache.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
let fs = require('fs');
let glob = require('glob');
let getFiles = (filter) => {
return new Promise(resolve => {
glob(filter, (err, innerfiles) => {
resolve(innerfiles);
});
});
}
let getAllFiles = (filters) => {
var promises = [];
for (var i = 0; i < filters.length; i++) {
var promise = getFiles(filters[i]);
promises.push(promise);
}
return Promise.all(promises).then(fileArrays => {
var allFiles = [];
for (var j = 0; j < fileArrays.length; j++) {
var fileArray = fileArrays[j];
allFiles = allFiles.concat(fileArray);
}
return allFiles;
});
}
let writeFile = (fileName, content) => {
return new Promise(resolve => {
fs.writeFile(fileName, content, 'utf8', function (err) {
if (err) return console.log(err);
resolve();
});
});
}
getAllFiles([ "./app/*.js", "./app/*.html", "./app/*.ico", "./app/*.css", "./app/*.txt" ]).then(files => {
var content = `CACHE MANIFEST
CACHE:
`;
for (var k = 0; k < files.length; k++) {
var fileName = files[k];
content += fileName.replace("./app/", "") + `
`;
}
content += `
NETWORK:
*`;
writeFile("./app/cache.manifest", content);
});