From 0cb6e1bfb4b467d2af79b68e879591a005cf1fba Mon Sep 17 00:00:00 2001 From: Jed Schmidt Date: Sun, 1 Jan 2012 15:10:44 -0500 Subject: [PATCH] rewrite manifest on pack --- src/crx.js | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/crx.js b/src/crx.js index 2aaedf4..415717c 100644 --- a/src/crx.js +++ b/src/crx.js @@ -27,12 +27,14 @@ module.exports = new function() { } this.pack = function(cb) { - this.loadManifest(function(err) { + this.generatePublicKey(function(err) { if (err) return cb(err) - this.generatePublicKey(function(err) { - if (err) return cb(err) + var manifest = JSON.stringify(this.manifest) + this.writeFile("manifest.json", manifest, function(err) { + if (err) return cb(err) + this.loadContents(function(err) { if (err) return cb(err) @@ -47,14 +49,20 @@ module.exports = new function() { this.load = function(path, cb) { fs.stat(path, function(err, stat) { - if (stat.isDirectory()) this.loadFromDir(path, cb) + if (stat.isDirectory()) this.loadFromDir(path || this.rootDirectory, cb) else if (stat.isFile()) this.loadFromFile(path, cb) }.bind(this)) } this.loadFromDir = function(path, cb) { - spawn("cp", ["-R", path, this.path]).on("exit", cb.bind(this)) + var child = spawn("cp", ["-R", path, this.path]) + + child.on("exit", function() { + this.manifest = require(join(this.path, "manifest.json")) + + cb.call(this) + }.bind(this)) } this.readFile = function(name, cb) { @@ -95,19 +103,6 @@ module.exports = new function() { }.bind(this)) } - this.loadManifest = function(cb) { - this.readFile("manifest.json", function(err, data) { - if (!err) { - try { this.manifest = JSON.parse(data.toString()) } - catch (e) { err = e } - } - - err - ? cb.call(this, err) - : cb.call(this, null, this.manifest) - }) - } - this.generatePublicKey = function(cb) { var rsa = spawn("openssl", ["rsa", "-pubout", "-outform", "DER"])