Add manifest generation options to press and flatten, since manifests need to be updated after each is run.

This commit is contained in:
Tom Robinson
2010-04-12 13:47:38 -07:00
parent 6a72e1b6ff
commit a18fb1b686
4 changed files with 45 additions and 6 deletions
+13
View File
@@ -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
+17
View File
@@ -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) {
@@ -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);
}
});
@@ -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]);