Skip to content
This repository has been archived by the owner on Nov 11, 2021. It is now read-only.

Commit

Permalink
Add function to build manifest file
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob Karreman committed Apr 27, 2011
1 parent 2a6bf97 commit 86fd5a7
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions lib/app.js
Expand Up @@ -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);

};

0 comments on commit 86fd5a7

Please sign in to comment.