Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove intermediate copy and use of temporary files #62

Merged
merged 7 commits into from
Sep 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 78 additions & 79 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,67 @@
# crx [![Build Status](https://secure.travis-ci.org/oncletom/crx.svg)](http://travis-ci.org/oncletom/crx)

crx is a [pure node.js](http://nodejs.org/) command line app for packing Google Chrome extensions. **No OpenSSL required**!
> crx is a utility to **package Google Chrome extensions** via a *Node API* and the *command line*. It is written **purely in JavaScript** and **does not require OpenSSL**!

If you'd like to integrate it into your [grunt](http://gruntjs.com/) workflow, give [grunt-crx](https://github.com/oncletom/grunt-crx) a spin.
Packages are available to use `crx` with:

Massive hat tip to the [node-rsa project](https://github.com/rzcoder/node-rsa)!
- *grunt*: [grunt-crx](https://npmjs.com/grunt-crx)
- *gulp*: [gulp-crx-pack](https://npmjs.com/gulp-crx-pack)
- *webpack*: [crx-webpack-plugin](https://npmjs.com/crx-webpack-plugin)

Massive hat tip to the [node-rsa project](https://npmjs.com/node-rsa) for the pure JavaScript encryption!

## Install

$ npm install crx
```bash
$ npm install crx
```

## Module API

Asynchronous functions returns an [ES6 Promise](https://github.com/jakearchibald/es6-promise).

```js
const fs = require("fs");
const ChromeExtension = require("crx");
const crx = new ChromeExtension(
codebase: "http://localhost:8000/myFirstExtension.crx",
privateKey: fs.readFileSync("./key.pem"))
});

crx.load("./myFirstExtension"))
.then(crx => crx.pack())
.then(crxBuffer => {
const updateXML = crx.generateUpdateXML()

fs.writeFile("../update.xml"), updateXML);
fs.writeFile("../myFirstExtension.crx"), crxBuffer);
});
```

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

This module exports the `ChromeExtension` constructor directly, which can take an optional attribute object, which is used to extend the instance.

### crx.load([path])
### crx.load(path)

Asynchronously prepares the temporary workspace for the Chrome Extension located at `attr.rootDirectory`.
Prepares the temporary workspace for the Chrome Extension located at `path`.

```js
crx.load().then(function(crx){
crx.load('/path/to/extension').then(crx => {
// ...
});
```

You can optionally pass a `path` argument in lieu of the `rootDirectory` constructor option.

### crx.pack([archiveBuffer])
### crx.pack()

Packs the Chrome Extension and resolves the promise with a Buffer containing the `.crx` file.

```js
crx.pack().then(function(crxBuffer){
fs.writeFile('/tmp/foobar.crx', crxBuffer);
});
```

You can optionally pass an `archiveBuffer` argument if you want a finer grained control over the packing process:

```js
crx.load()
.then(function(){
return crx.loadContents();
})
.then(function(archiveBuffer){
fs.writeFile('path/to/extension.zip', archiveBuffer);

return crx.pack(archiveBuffer);
})
.then(function(crxBuffer){
fs.writeFile('path/to/extension.crx', crxBuffer);
crx.load('/path/to/extension')
.then(crx => crx.pack())
.then(crxBuffer => {
fs.writeFile('/tmp/foobar.crx', crxBuffer);
});
```

Expand All @@ -63,35 +70,14 @@ crx.load()
Returns a Buffer containing the update.xml file used for `autoupdate`, as specified for `update_url` in the manifest. In this case, the instance must have a property called `codebase`.

```js
var crx = new ChromeExtension({ ..., codebase: 'https://autoupdateserver.com/myFirstExtension.crx' });

crx.pack().then(function(crxBuffer){
// ...

var xmlBuffer = crx.generateUpdateXML();
fs.writeFile('/foo/bar/update.xml', xmlBuffer);
});
```

## Module example

```javascript
var fs = require("fs"),
var ChromeExtension = require("crx"),
var join = require("path").join,
var crx = new ChromeExtension(
codebase: "http://localhost:8000/myFirstExtension.crx",
privateKey: fs.readFileSync(join(__dirname, "key.pem"))
});

crx.load(join(__dirname, "myFirstExtension"))
.then(function() {
return crx.pack().then(function(crxBuffer){
var updateXML = crx.generateUpdateXML()

fs.writeFile(join(__dirname, "update.xml"), updateXML)
fs.writeFile(join(__dirname, "myFirstExtension.crx"), crxBuffer)
})
const crx = new ChromeExtension({ ..., codebase: 'https://autoupdateserver.com/myFirstExtension.crx' });

crx.load('/path/to/extension')
.then(crx => crx.pack())
.then(crxBuffer => {
// ...
const xmlBuffer = crx.generateUpdateXML();
fs.writeFile('/foo/bar/update.xml', xmlBuffer);
});
```

Expand Down Expand Up @@ -123,50 +109,64 @@ Show information about using this utility, generated by [commander](https://gith

Given the following directory structure:

└─┬ myFirstExtension
├── manifest.json
└── icon.png
```
└─┬ myFirstExtension
├── manifest.json
└── icon.png
```

run this:

cd myFirstExtension
crx pack -o
```bash
$ cd myFirstExtension
$ crx pack -o
```

to generate this:

├─┬ myFirstExtension
│ ├── manifest.json
│ ├── icon.png
│ └── key.pem
└── myFirstExtension.crx
```bash
├─┬ myFirstExtension
│ ├── manifest.json
│ ├── icon.png
│ └── key.pem
└── myFirstExtension.crx
```

You can also name the output file like this:

cd myFirstExtension
crx pack -o myFirstExtension.crx
```bash
$ cd myFirstExtension
$ crx pack -o myFirstExtension.crx
```

to get the same results, or also pipe to the file manually like this.

cd myFirstExtension
crx pack > ../myFirstExtension.crx
```bash
$ cd myFirstExtension
$ crx pack > ../myFirstExtension.crx
```

As you can see a key is generated for you at `key.pem` if none exists. You can also specify an external key. So if you have this:

├─┬ myFirstExtension
│ ├── manifest.json
│ └── icon.png
└── myPrivateKey.pem
```
├─┬ myFirstExtension
│ ├── manifest.json
│ └── icon.png
└── myPrivateKey.pem
```

you can run this:

crx pack myFirstExtension -p myPrivateKey.pem -o
```bash
$ crx pack myFirstExtension -p myPrivateKey.pem -o
```

to sign your package without keeping the key in the directory.

Copyright
---------

Copyright (c) 2014 Jed Schmidt, Thomas Parisot
Copyright (c) 2016 Jed Schmidt, Thomas Parisot and collaborators

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand All @@ -186,4 +186,3 @@ Copyright
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

18 changes: 8 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "Jed Schmidt <[email protected]> (http://jed.is)",
"name": "crx",
"description": "Build Google Chrome extensions with node.js",
"description": "crx is a utility to package Google Chrome extensions via a Node API and the command line",
"version": "3.0.4",
"license": "MIT",
"homepage": "https://github.com/oncletom/crx",
Expand All @@ -19,31 +19,29 @@
},
"scripts": {
"test": "nyc tape ./test/*.js",
"posttest": "nyc report --reporter=html",
"version": "npm run changelog && git add CHANGELOG.md",
"changelog": "github-changes -o oncletom -r crx -n ${npm_package_version} --only-pulls --use-commit-body"
},
"nyc": {
"functions": 100,
"statements": 95,
"branches": 88,
"statements": 100,
"branches": 100,
"check-coverage": true,
"reporter": [
"text"
"text",
"html"
]
},
"dependencies": {
"archiver": "^1.1.0",
"commander": "^2.5.0",
"es6-promise": "^3.0.0",
"node-rsa": "^0.2.10",
"temp": "^0.8.1",
"wrench": "^1.5.0"
"node-rsa": "^0.2.10"
},
"devDependencies": {
"adm-zip": "^0.4.7",
"github-changes": "^1.0.0",
"nyc": "^8.3.0",
"sinon": "^1.12.1",
"tape": "^3.0.3"
"tape": "^4.6.0"
}
}
Loading