diff --git a/lib/app.js b/lib/app.js index a539a6e..bd635a7 100644 --- a/lib/app.js +++ b/lib/app.js @@ -275,3 +275,79 @@ App.prototype.save = function() { savr = new Saver(that, html); savr.save(); }; + +App.prototype.manifest = function() { + console.log('Creating Manifest file'); + var that = this; + + var Scanner = function(app, callback) { + var that = this; + that.count = 0; + that.files = []; + + that.callbackIfDone = function() { + if (that.count <= 0) callback(that.files, app.rootDir); + }; + + that.scan = function(path) { + that.count += 1; + + l.fs.stat(path, function(err, stats) { + that.count -= 1; + + if (err) throw err; + + if (stats.isDirectory()) { + that.count += 1; + l.fs.readdir(path, function(err, subpaths) { + that.count -= 1; + + if (err) throw err; + + subpaths.forEach(function(subpath) { + if (subpath[0] !== '.') { + that.scan(l.path.join(path, subpath)); + } + }); + + that.callbackIfDone(); + }); + + } else { + that.files.push(path.replace(app.rootDir, '')); + } + + that.callbackIfDone(); + }); + }; + }; + + + this.rootDir = l.path.join(this.savePath, this.buildVersion); + + var scanner = new Scanner(this, function (files, rootDir) { + var cacheFiles = 'CACHE MANIFEST \n' + + '# List of all resources required by this project \n' + + '# Explicitly cached entries (only the "CACHE" needs to be added) \n'+ + 'CACHE:\n'; + + for (var i = 0; i < files.length; i++) { + cacheFiles += '/' + that.buildVersion + files[i] + '\n' + } + + cacheFiles += 'NETWORK:\n'+ + '*'; + + var manifestPath = l.path.join(rootDir, "app.manifest"); + console.info('ManifestPath', manifestPath); + l.fs.writeFile(manifestPath, cacheFiles, function(err) { + if(err) { + throw err; + } else { + console.info("The file was saved!"); + } + }); + + }).scan(this.rootDir); + +}; \ No newline at end of file