aboutsummaryrefslogtreecommitdiffstats
path: root/docs/src/appCache.js
blob: 994054c2e6eb1fb7212021d49fa5a8394a4a7ef4 (plain)
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
/**
* Generate appCache Manifest file here
*/

exports.appCache = appCache;
var fs = require('fs');

function appCache(path) {
    var blackList = [ "offline.html",
                      "sitemap.xml",
                      "robots.txt",
                      "docs-scenario.html",
                      "docs-scenario.js",
                      "app-cache.manifest"
                    ];

    var result = ["CACHE MANIFEST",
                        "# %TIMESTAMP%",
                        "",
                        "# cache all of these",
                        "CACHE:",
                        "../angular.min.js"];

    var resultPostfix = [ "",
                        "FALLBACK:",
                        "/offline.html",
                        "",
                        "# allow access to google analytics and twitter when we are online",
                        "NETWORK:",
                        "*"];
    walk(path,result,blackList);
    return result.join('\n').replace(/%TIMESTAMP%/, (new Date()).toISOString()) + '\n' + resultPostfix.join('\n');
}

function walk(path, array, blackList) {
  var temp = fs.readdirSync(path);
  for (var i=0; i< temp.length; i++) {
    if(blackList.indexOf(temp[i]) < 0) {
      var currentPath = path + '/' + temp[i];
      var stat = fs.statSync(currentPath);
      
      if (stat.isDirectory()) {
        walk(currentPath, array, blackList);
      }
      else {
        array.push(currentPath.replace('build/docs/',''));
      }
    }
  }
}