Skip to content

Commit

Permalink
added module API, travis-ci integration
Browse files Browse the repository at this point in the history
  • Loading branch information
jed committed Dec 31, 2011
1 parent f520c6d commit 3da8170
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
language: node_js
node_js:
- 0.4
- 0.6
55 changes: 52 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,56 @@ crx is a [node.js](http://nodejs.org/) command line app for packing Google Chrom

$ npm install crx

## API
## Module API

### ChromeExtension = require("crx")
### crx = new ChromeExtension

This module exports the `ChromeExtension` constructor directly, which takes no arguments.

### crx.load(path, callback)

Loads the Chrome Extension from the specified path.

### crx.pack(callback)

Packs the Chrome Extension, and calls back with a Buffer containing the `.crx` file.

### crx.generateUpdateXML(url)

Returns a Buffer containing the update.xml file used for autoupdate, as specified for `update_url` in the manifest.

### crx.destroy()

Destroys all of the temporary resources used for packing.

## Module example

```javascript
var fs = require("fs")
, ChromeExtension = require("crx")
, crx = new ChromeExtension
, updateUrl = "http://localhost/update.xml"

crx.privateKey = fs.readFileSync(__dirname + "/key.pem")

crx.load(__dirname + "/myFirstExtension", function(err) {
if (err) throw err

this.pack(function(err, data){
if (err) throw err

var updateXML = this.generateUpdateXML(updateUrl)

fs.writeFile(__dirname + "/update.xml", updateXML)
fs.writeFile(__dirname + "/myFirstExtension.crx", data)

this.destroy()
})
})
```

## CLI API

### crx pack [directory] [-f file] [-p private-key]

Expand All @@ -32,7 +81,7 @@ Generate a 1,024-bit RSA private key within the directory. This is called automa

Show information about using this utility, generated by [commander](https://github.com/visionmedia/commander.js).

## Examples
## CLI example

Given the following directory structure:

Expand Down Expand Up @@ -79,6 +128,6 @@ to sign your package without keeping the key in the directory.
Copyright
---------

Copyright (c) 2011 Jed Schmidt. See LICENSE.txt for details.
Copyright (c) 2012 Jed Schmidt. See LICENSE.txt for details.

Send any questions or comments [here](http://twitter.com/jedschmidt).
1 change: 0 additions & 1 deletion index.js

This file was deleted.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
"type": "git",
"url": "git://github.com/jed/crx.git"
},
"main": "./src/crx.js",
"engines": {
"node": ">=0.4.12"
},
"scripts": {
"test": "node ./test/index.js"
},
"dependencies": {
"commander": ""
},
Expand Down
14 changes: 14 additions & 0 deletions src/crx.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,19 @@ module.exports = new function() {
})
}

this.generateUpdateXML = function(url) {
if (!url) throw new Error("No URL provided for update.xml.")

return this.updateXML =
Buffer(
"<?xml version='1.0' encoding='UTF-8'?>\n" +
"<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>\n" +
" <app appid='" + this.generateAppId() + "'>\n" +
" <updatecheck codebase='" + url + "' version='" + this.manifest.version + "' />\n" +
" </app>\n" +
"</gupdate>"
)
}

return ChromeExtension
}
22 changes: 22 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var fs = require("fs")
, assert = require("assert")
, ChromeExtension = require("../")
, crx = new ChromeExtension
, updateUrl = "http://localhost/update.xml"

crx.privateKey = fs.readFileSync(__dirname + "/key.pem")

crx.load(__dirname + "/myFirstExtension", function(err) {
if (err) throw err

this.pack(function(err, data){
if (err) throw err

var updateXML = this.generateUpdateXML(updateUrl)

fs.writeFile(__dirname + "/update.xml", updateXML)
fs.writeFile(__dirname + "/myFirstExtension.crx", data)

this.destroy()
})
})
15 changes: 15 additions & 0 deletions test/key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-----BEGIN RSA PRIVATE KEY-----
MIICWwIBAAKBgQDIE6oOlsG3WmTe9lxiv3ey9esYzFScqXjaAmWnNz68TSWQqe1G
QyTUit2cDEtRYBFRd5SibNHtRkbEwoYON574LWgi83nLJzqHQy2rYKxeqp3FO0ev
pNlHpmutDtutPW+UwRfGsULKGC9e97YdMPuRhcIa9Ff1qiLT6Fqj0U3NAwIDAQAB
AoGAE0j58lALug2nfWpHu2jzM7fKgmhnm3YmZPUoMTb9AA97mHcYnNYp/aao97qj
o+Nbp/ubwxA0J+fHOH37h/FKjDuq+yc8fJIHTGxeqIprN7y5HyWS0Q/DU7obzIKt
3voQ904ldsJU5zuP/Fb18iWA2svxE5u0XUNmiM7BX2P5qfkCQQD0I+/L1vul43Q0
CRq5e7btJtIW0LVbxSf+fxgUiexs6YJkccHbPkGDB60nnGxqaV7O5HqcTFj1JSjW
O9ZtXqAHAkEA0cvD3OGC7nsVV48Hgu3xnt+h8QoPS3Qwnla73OxAJf6UZ2WrCiWz
evd5Hqr4aBsfMHKTdzXsEMocfXcaApb0JQJAZ4+28KjJJp1NdaVHCNdJyV9mTvdJ
dxwy0unmtQ+skqabATCgIvhNod9nvB3Gf30jEnAo8pQQSCzzHa1UUCCLkQJAGTZn
v2/KkGZyVid2O6Hk27b8ez8+P08jWKQLx60MuIQzyYlKWNnXC/wZrjnVyI0Z3nSm
jDkKuanQarOZiJ4jkQJAdKbxR0vmg2qD+5Mq0WDtJ5chJV1QRNri1gU6URo69w34
Y78vDpKedMtiiXYW2cjXjONojRUMZFjsnSxM0CzmjQ==
-----END RSA PRIVATE KEY-----
Binary file added test/myFirstExtension.crx
Binary file not shown.
6 changes: 6 additions & 0 deletions test/update.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>
<app appid='eenbebfenfnlbeoccghenggcpkdnpbkh'>
<updatecheck codebase='http://localhost/update.xml' version='1.0' />
</app>
</gupdate>

0 comments on commit 3da8170

Please sign in to comment.