Skip to content

Instantly share code, notes, and snippets.

@jeffgca
Forked from anonymous/-
Last active February 7, 2020 11:13
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jeffgca/9301061 to your computer and use it in GitHub Desktop.
Save jeffgca/9301061 to your computer and use it in GitHub Desktop.
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 = 'http://127.0.0.1:8888/';
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')
.argv;
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 = package_data.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) {
console.log([].slice.call(arguments));
});
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) {
console.log("done?");
});
});
});
}
@duzun
Copy link

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) {
        process.stdout.write(d);
    });
});

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

req.on('error', function (err) {
    console.log(err);
});

https://gist.github.com/duzun/d1b90826e6fbbb7bd8b0

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