From a18fb1b68686019f793f1aa3db4fc1cddf4bfcc4 Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Mon, 12 Apr 2010 13:32:29 -0700 Subject: [PATCH] Add manifest generation options to press and flatten, since manifests need to be updated after each is run. --- CommonJS/bin/flatten | 13 +++++++++++++ CommonJS/bin/press | 17 +++++++++++++++++ .../lib/objective-j/cache-manifest.js | 19 ++++++++++++++----- .../lib/objective-j/jake/applicationtask.js | 2 +- 4 files changed, 45 insertions(+), 6 deletions(-) diff --git a/CommonJS/bin/flatten b/CommonJS/bin/flatten index 563b181c6..1b746853d 100755 --- a/CommonJS/bin/flatten +++ b/CommonJS/bin/flatten @@ -10,6 +10,8 @@ var FILE = require("file"); var OS = require("os"); var UTIL = require("util"); +var CACHEMANIFEST = require("objective-j/cache-manifest"); + var stream = require("term").stream; var parser = new (require("args").Parser)(); @@ -49,6 +51,10 @@ parser.option("-c", "--compressor", "compressor") .set() .help("Select a compressor to use (closure-compiler, yuicompressor, shrinksafe), or \"none\" (default: shrinksafe)"); +parser.option("--manifest", "manifest") + .set(true) + .help("Generate HTML5 cache manifest."); + parser.option("-v", "--verbose", "verbose") .def(false) .set(true) @@ -126,6 +132,13 @@ function main(args) }); rewriteMainHTML(outputPath.join(options.index)); + + if (options.manifest) { + CACHEMANIFEST.generateManifest(outputPath, { + index : outputPath.join(options.index), + exclude : Object.keys(flattener.filesToCache).map(function(path) { return outputPath.join(path).toString(); }) + }); + } } // ObjectiveJFlattener inherits from ObjectiveJRuntimeAnalyzer diff --git a/CommonJS/bin/press b/CommonJS/bin/press index 8b7c28283..b36277bc3 100755 --- a/CommonJS/bin/press +++ b/CommonJS/bin/press @@ -10,6 +10,8 @@ require("narwhal").ensureEngine("rhino"); var FILE = require("file"); var OS = require("os"); +var CACHEMANIFEST = require("objective-j/cache-manifest"); + var stream = require("term").stream; var parser = new (require("args").Parser)(); @@ -31,11 +33,20 @@ parser.option("-f", "--force", "force") .set(true) .help("Force overwriting OUTPUT_PROJECT if it exists"); +parser.option("--index", "index") + .def("index.html") + .set() + .help("The root HTML file to modify (default: index.html) (NOTE: currently only used by '--manifest' option)"); + parser.option("-p", "--pngcrush", "png") .def(false) .set(true) .help("Run pngcrush on all PNGs (pngcrush must be installed!)"); +parser.option("--manifest", "manifest") + .set(true) + .help("Generate HTML5 cache manifest."); + parser.option("-v", "--verbose", "verbose") .def(false) .set(true) @@ -146,6 +157,12 @@ function press(rootPath, outputPath, options) { if (options.png) { pngcrushDirectory(outputPath); } + + if (options.manifest) { + CACHEMANIFEST.generateManifest(outputPath, { + index : outputPath.join(options.index) + }); + } } function pressEnvironment(rootPath, outputFiles, environment, options) { diff --git a/Objective-J/CommonJS/lib/objective-j/cache-manifest.js b/Objective-J/CommonJS/lib/objective-j/cache-manifest.js index 6b39c39f9..5b54372e9 100644 --- a/Objective-J/CommonJS/lib/objective-j/cache-manifest.js +++ b/Objective-J/CommonJS/lib/objective-j/cache-manifest.js @@ -2,12 +2,14 @@ var FILE = require("file"); var MD5 = require("md5"); -var FileList = require("jake").FileList, +var FileList = require("jake").FileList; var BundleTask = require("objective-j/jake/bundletask").BundleTask; -exports.generateManifest = function(productPath, indexFilePath) +exports.generateManifest = function(productPath, options) { - indexFilePath = indexFilePath || FILE.join(productPath, "index.html"); + options = options || {}; + + indexFilePath = options.index || FILE.join(productPath, "index.html"); if (!FILE.isFile(indexFilePath)) { print("Warning: Skipping cache manifest generation, no index file at "+indexFilePath); @@ -33,21 +35,28 @@ exports.generateManifest = function(productPath, indexFilePath) list.exclude("**/LICENSE"); list.exclude("**/MHTML*"); list.exclude("**/CommonJS.environment/*"); + list.exclude("**/*.cur"); // FIXME: sprite these? // FIXME: bleh. heuristic for whether index file includes debug frameworks if (index.indexOf('"Frameworks/Debug"') < 0) list.exclude("**/Frameworks/Debug/*"); + if (options.exclude) + options.exclude.forEach(list.exclude.bind(list)); + list.forEach(function(path) { if (FILE.isFile(path)) { + var relative = FILE.relative(productPath, path); + // FIXME: check the actual sprited images file - if (BundleTask.isSpritable(path)) + // check index for references to file (for spinner.gif, etc) + if (BundleTask.isSpritable(path) && index.indexOf(relative) < 0) return; // include hash of each file in comments to expire when any file changes var hash = MD5.hash(FILE.read(path, "b")).decodeToString("base16"); manifestOut.print("# " + hash); - manifestOut.print(FILE.relative(productPath, path)); + manifestOut.print(relative); } }); diff --git a/Objective-J/CommonJS/lib/objective-j/jake/applicationtask.js b/Objective-J/CommonJS/lib/objective-j/jake/applicationtask.js index dbc70bed4..c3a2045e9 100644 --- a/Objective-J/CommonJS/lib/objective-j/jake/applicationtask.js +++ b/Objective-J/CommonJS/lib/objective-j/jake/applicationtask.js @@ -130,7 +130,7 @@ ApplicationTask.prototype.defineCacheManifestTask = function() // TODO: can we conditionally generate based on outdated files? var manifestPath = FILE.join(productPath, "app.manifest"); Jake.task(manifestPath, function() { - require("../cache-manifest").generateManifest(productPath, indexFilePath); + require("../cache-manifest").generateManifest(productPath, { index : indexFilePath }); }); this.enhance([manifestPath]);