@@ -4,7 +4,8 @@ var os = require('os'),
44 versions = require ( './versions' ) ,
55 semver = require ( 'semver' ) ,
66 request = require ( 'request' ) ,
7- async = require ( 'async' ) ;
7+ async = require ( 'async' ) ,
8+ defaults = require ( 'amp-defaults' ) ;
89
910module . exports = function ( opts , fn ) {
1011 if ( Array . isArray ( opts ) ) {
@@ -20,38 +21,49 @@ module.exports = function(opts, fn){
2021 if ( typeof opts === 'string' ) {
2122 opts = { version : opts } ;
2223 }
24+ var handler = versions ;
25+
26+ defaults ( opts , {
27+ arch : ARCH ,
28+ platform : PLATFORM ,
29+ branch : 'master' ,
30+ bits : '64' ,
31+ debug : false
32+ } ) ;
33+
34+ // 64bit -> 64
35+ opts . bits = opts . bits . replace ( / [ ^ 0 - 9 ] / g, '' ) ;
2336
24- var arch = opts . arch || ARCH ,
25- platform = opts . platform || PLATFORM ,
26- handler = versions ;
37+ if ( opts . platform === 'darwin' ) opts . platform = 'osx' ;
38+ if ( opts . platform === 'windows' ) opts . platform = 'win32' ;
2739
28- opts . branch = opts . branch || 'master' ;
29- opts . platform = opts . platform || PLATFORM ;
30- opts . bits = opts . bits || '64' ;
31- opts . ext = ( platform === 'win32' ? '.zip' : '.tgz' ) ;
40+ opts . ext = ( opts . platform === 'win32' ? '.zip' : '.tgz' ) ;
41+ // @todo : get list of distros from mci and make sure passed in is valid.
3242 opts . distro = opts . distro || null ;
3343
44+ // A commit hash
45+ if ( opts . version . length === 40 || opts . version . length === 8 ) {
46+ // @todo : Use dyno rest api to resolve 8char short sha to full sha.
47+ return mci ( opts , fn ) ;
48+ }
49+
3450 if ( opts . version === 'latest' || opts . version === 'unstable' ) {
3551 handler = latest ;
3652 }
3753 else if ( opts . version === 'stable' ) {
3854 handler = stable ;
3955 }
40- else if ( opts . version . length === 40 || opts . version . length === 8 ) {
41- // A commit hash
42- return mci ( opts , fn ) ;
43- }
4456 else {
4557 handler = search . bind ( null , opts ) ;
4658 }
4759
4860 handler ( function ( err , v ) {
49- var basename = 'mongodb-' + platform + '-' + arch + ( opts . debug ? '-debugsymbols' : '' ) + '-' + v ,
61+ var basename = 'mongodb-' + opts . platform + '-' + opts . arch + ( opts . debug ? '-debugsymbols' : '' ) + '-' + v ,
5062 pkg = {
5163 name : 'mongodb' ,
5264 version : v ,
5365 artifact : basename + opts . ext ,
54- url : 'http://fastdl.mongodb.org/' + platform + '/' + basename + opts . ext
66+ url : 'http://fastdl.mongodb.org/' + opts . platform + '/' + basename + opts . ext
5567 } ;
5668
5769 fn ( null , pkg ) ;
@@ -86,8 +98,6 @@ function mci(opts, fn){
8698 } ) ;
8799}
88100
89-
90-
91101function search ( query , fn ) {
92102 versions ( function ( err , res ) {
93103 if ( err ) return fn ( err ) ;
0 commit comments