Permalink
Browse files

Bug 925555 - use mozilla-get-url and only export one thing

  • Loading branch information...
1 parent 5dab8f1 commit cd7b4d83ec60fd73a30fa0a32ec0b2395a4b05e7 @lightsofapollo lightsofapollo committed Oct 10, 2013
Showing with 72 additions and 92 deletions.
  1. +4 −0 Makefile
  2. +17 −28 README.md
  3. +3 −26 bin/mozilla-download
  4. +0 −3 index.js
  5. +1 −6 lib/detectos.js
  6. +14 −15 lib/download.js
  7. +12 −0 lib/options.js
  8. +3 −3 package.json
  9. +1 −1 test/detectos-test.js
  10. +17 −10 test/download-test.js
View
@@ -19,3 +19,7 @@ test: node_modules test/fixtures test/extract-out
.PHONY: test-full
test-full: node_modules test/fixtures test/extract-out
./node_modules/mocha/bin/mocha --reporter spec -t 100s
+
+.PHONY: clean
+clean:
+ rm -Rf test/darwin-out test/extract-out test/linux-out
View
@@ -1,43 +1,32 @@
# Mozilla Download
-Downloads mozilla product binaries. Version detection / support using [firefox-get](https://github.com/jsantell/node-firefox-get).
+Helper utility for downloading various mozilla products in various
+release channels. Built on top of
+[mozilla-get-url](https://github.com/mozilla-b2g/mozilla-get-url).
+
+Handles operating system detection (win32, mac, linux-i686,
+linux-x86_64) and extraction of files (.tar.bz2, .dmg).
+Extraction is platform dependent a .dmg may not unpack on linux.
## Usage
``` js
-var moz = require('mozilla-download');
+var mozdownload = require('mozilla-download');
-// detect which platform this computer uses
-moz.detectOS('firefox'); // platform for firefox
-moz.detectOS('b2g'); // platform for b2g
+// see https://github.com/mozilla-b2g/mozilla-get-url#usage for options
+var options = {};
// download firefox
-moz.download(
- 'firefox', // product can be either firefox or b2g
- __dirname + '/firefox', // save target
- functon(err, path) {
- // path is the same as save targe
- }
-);
-
-// download b2g desktop nightly
-moz.download(
- 'b2g', // product can be either firefox or b2g
- __dirname + '/b2g', // save target
- functon(err, path) {
- // path is the same as save targe
- }
-);
+moz.download('save/me', options, functon(err, path) {
+ // path is the same as save targe
+});
+```
-// with options
-moz.download(
- 'b2g',
- __dirname,
- // see firefox-get
- { version: 'xxx', os: 'xxx' }
-);
+## CLI Usage
+```sh
+mozilla-download path/to/place/extracted/folder
```
## License
View
@@ -1,8 +1,8 @@
#! /usr/bin/env node
var fs = require('fs'),
- mozdown = require('../index'),
- program = require('commander');
+ mozdown = require('../'),
+ program = require('mozilla-get-url/bin/mozilla-get-url');
function verbose() {
var args = Array.prototype.slice.call(arguments);
@@ -13,10 +13,6 @@ function verbose() {
program.
version(require('../package.json').version).
usage('[options] <target>').
- option('--verbose').
- option('--product-version [latest]', 'version of product to download').
- option('-P, --product [firefox]', 'product to download').
- option('--os [type]', 'override detected operating system').
parse(process.argv);
var target = program.args[0];
@@ -32,26 +28,7 @@ if (fs.existsSync(target)) {
process.exit();
}
-var product = program.product || 'firefox',
- version = program.productVersion,
- os = program.os;
-
-var downloadOptions = {};
-
-if (os)
- downloadOptions.os = os;
-
-if (version)
- downloadOptions.version = version;
-
-verbose(
- 'downloading product: "%s" to "%s" with options "%s"',
- product,
- target,
- JSON.stringify(downloadOptions)
-);
-
-mozdown.download(product, target, downloadOptions, function(err) {
+mozdown(target, program, function(err) {
if (err) {
console.log(err.message);
process.exit(1);
View
@@ -1,3 +0,0 @@
-module.exports.detectOS = require('./lib/detectos');
-module.exports.download = require('./lib/download');
-module.exports.extract = require('./lib/extract');
View
@@ -14,12 +14,7 @@ function detectOS(product, target) {
switch (platform) {
case 'darwin':
- // firefox is always mac
- if (product === 'firefox')
- return 'mac';
-
- // b2g is either mac or mac64
- return (arch === 'x64') ? 'mac64' : 'mac';
+ return 'mac';
case 'linux':
return (arch === 'x64') ? 'linux-x86_64' : 'linux-i686';
case 'win32':
View
@@ -1,9 +1,9 @@
-var mozget = require('firefox-get'),
+var mozget = require('mozilla-get-url'),
tmp = require('tmp'),
fs = require('fs'),
http = require('http'),
debug = require('debug')('mozilla-runner:download'),
- detectOS = require('./detectos'),
+ opts = require('./options'),
extract = require('./extract');
var DEFAULT_VERSION = 'nightly';
@@ -15,27 +15,26 @@ var DEFAULT_VERSION = 'nightly';
* // do amazing things!
* });
*
- * Options:
+ * Options (these are passed to mozilla-get-url):
+ * - product: like firefox / b2g
* - os: to download for (see firefox-get)
* - version: or channel (like 18 or 'nightly')
* - strict: send an error if given path exists.
*
- * @param {String} product to download (like firefox)
* @param {String} path to download file to.
* @param {Object} [options] optional set of configuration options.
* @param {Function} callback [err, path];
*/
-function download(product, path, options, callback) {
- var os = options.os || detectOS(product);
- var version = options.version || DEFAULT_VERSION;
-
- debug('download', product, os, version);
+function download(path, options, callback) {
+ var product = options.product || 'firefox';
+ var os = options.os;
+ debug('download', options);
function saveToTemp(err, url) {
if (err) return callback(err);
debug('got ftp download location', url);
- tmp.file({ prefix: product + '-' + os }, function(err, tmpPath) {
+ tmp.file({ prefix: 'mozilla-download-' + os }, function(err, tmpPath) {
if (err) return callback(err);
debug('open temp stream', tmpPath);
var stream = fs.createWriteStream(tmpPath);
@@ -51,18 +50,18 @@ function download(product, path, options, callback) {
});
}
- mozget[product](version, { os: os }, saveToTemp);
+ mozget(options, saveToTemp);
}
-function checkDownload(product, path, options, callback) {
+function checkDownload(path, options, callback) {
if (typeof options === 'function') {
callback = options;
options = null;
}
- options = options || {};
+ options = opts(options || {});
- var strictErrors = options && options.strict;
+ var strictErrors = options.strict;
// don't clobber an existing path
fs.exists(path, function(itDoes) {
@@ -79,7 +78,7 @@ function checkDownload(product, path, options, callback) {
}
// if path does not exist continue with normal download process.
- download(product, path, options, callback);
+ download(path, options, callback);
});
}
View
@@ -0,0 +1,12 @@
+function options(options) {
+ var defaults = { product: 'firefox' };
+ for (var key in options) defaults[key] = options[key];
+
+ if (!defaults.os) {
+ defaults.os = require('./detectos')(options.product);
+ }
+
+ return defaults;
+}
+
+module.exports = options;
View
@@ -1,9 +1,9 @@
{
"name": "mozilla-download",
- "version": "0.2.1",
+ "version": "0.3.0",
"author": "James Lal [:lightsofapollo]",
"description": "Download firefox/b2g-desktop runtimes",
- "main": "index.js",
+ "main": "lib/download.js",
"repository": {
"type": "git",
"url": "https://github.com/mozilla-b2g/mozilla-download.git"
@@ -19,7 +19,7 @@
},
"dependencies" : {
"debug": "*",
- "firefox-get": "~0.0.4",
+ "mozilla-get-url": "~0.0.1",
"dmg": "~0.0.3",
"tmp": "~0.0.20",
"ncp": "~0.4",
View
@@ -4,7 +4,7 @@ suite('detect', function() {
suite('#detectOS', function() {
var expected = [
- [{ platform: 'darwin', arch: 'x64' }, 'mac64'],
+ [{ platform: 'darwin', arch: 'x64' }, 'mac'],
// something other then x64 (unlikely)
[{ platform: 'darwin', arch: 'ia32' }, 'mac'],
[{ platform: 'win32', arch: 'ia32' }, 'win32'],
View
@@ -1,19 +1,20 @@
suite('download', function() {
var assert = require('assert');
- var runner = require('../index');
+ var download = require('../lib/download');
var fs = require('fs');
suite('when path exists', function() {
var path = __dirname + '/fixtures/b2g.dmg';
test('non-strict', function(done) {
- runner.download('b2g', path, function(err, givenPath) {
+ download(path, { product: 'b2g' }, function(err, givenPath) {
assert.equal(givenPath, path);
done(err);
});
});
test('strict', function(done) {
- runner.download('b2g', path, { strict: true }, function(err, givenPath) {
+ var options = { product: 'b2g', strict: true };
+ download(path, options, function(err, givenPath) {
if (!err) {
done(new Error('strict must return an error when file exists'));
return;
@@ -24,17 +25,17 @@ suite('download', function() {
});
- suite('mac64', function() {
+ suite('mac', function() {
var path = __dirname + '/darwin-out/';
if (process.platform !== 'darwin')
return test('cannot run mac64 tests on non darwin platforms');
test('package expansion', function(done) {
- var options = { os: 'mac64', version: 'release' };
- runner.download('b2g', path, options, function(err, path) {
+ var options = { os: 'mac' };
+ download(path, options, function(err, path) {
var stat = fs.statSync(path);
assert.ok(stat.isDirectory());
- done();
+ done(err);
});
});
});
@@ -45,11 +46,17 @@ suite('download', function() {
return test('cannot run on windows');
test('package expansion', function(done) {
- var options = { os: 'linux-x86_64', version: 'release' };
- runner.download('b2g', path, options, function(err, path) {
+ var options = {
+ os: 'linux-x86_64',
+ product: 'b2g',
+ channel: 'prerelease',
+ branch: 'nightly'
+ };
+
+ download(path, options, function(err, path) {
var stat = fs.statSync(path);
assert.ok(stat.isDirectory());
- done();
+ done(err);
});
});

0 comments on commit cd7b4d8

Please sign in to comment.