Skip to content

Instantly share code, notes, and snippets.

Forked from anonymous/-
Last active Feb 7, 2020
What would you like to do?
A node script that abuses child_process to run cfx and post the resulting xpi to Firefox. Requires: *nix, a working installation of the Add-on SDK ( with cfx on your PATH ) and a recent version of Firefox with the 'Extension Auto-installer' extension installed.
#!/usr/bin/env node
var util = require('util'),
fs = require('fs'),
path = require('path'),
http = require('http'),
_ = require('lodash'),
url = require('url');
var DEBUG = false,
host = '';
if (!module.parent) {
1. get some info from package.json
2. run cfx
3. on completion, post the xpi file to Firefox
var xpi = false;
var cwd = process.cwd();
var spawn = require('child_process').spawn;
var optimist = require('optimist');
var argv = optimist
.usage('addon-install -h http://localhost:888/')
.default({h: host})
.describe('h', 'The host and port that the extension auto-installer is listening on')
.alias('p', 'port')
fs.readFile(path.join(cwd, 'package.json'),
{encoding: 'utf8'},
function(err, buffer) {
if (err) throw err;
// console.log(buffer);
var package_data = JSON.parse(buffer),
xpi_name = + '.xpi';
console.log("Building %s", xpi_name);
var builder = spawn('cfx', ['xpi'], {cwd: cwd});
builder.stdout.on('data', function(data) {
console.log("cfx> %s", data);
builder.stderr.on('data', function(data) {
console.log("cfx> %s", data);
builder.on('error', function(err) {
builder.on('close', function(err, result) {
post_file = spawn('wget', ['--post-file='+xpi_name, host], {cwd: cwd});
post_file.stderr.on('data', function(data) {
console.log("wget> %s", data);
post_file.stdout.on('data', function(data) {
console.log("wget> %s", data);
post_file.on('close', function(err, result) {

This comment has been minimized.

Copy link

@duzun duzun commented May 9, 2015

What if we use http module instead of wget?

Here is an example:

var req = http.request(host, function (res) {
    console.log('status:', res.statusCode, res.statusMessage);
    res.on('data', function (d) {

var xpi = fs.createReadStream(path.resolve(cwd, xpi_name));

req.on('error', function (err) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment