lib/utils/platforms.js
function resolveForVersion(version, platformID, opts) {
    opts = _.defaults(opts || {}, {
        // Order for filetype
        filePreference: ['.exe', '.dmg', '.deb', '.rpm', '.tgz', '.tar.gz', '.zip', '.nupkg'],
        wanted: null
    });

    // Prepare file prefs
    if (opts.wanted) opts.filePreference = _.uniq([opts.wanted].concat(opts.filePreference));

    // Normalize platform id
    platformID = detectPlatform(platformID);

    return _.chain(version.platforms)
        .filter(function(pl) {
            return pl.type.indexOf(platformID) === 0;
        })
        .sort(function(p1, p2) {
            var result = 0;

            // Compare by arhcitecture ("osx_64" > "osx")
            if (p1.type.length > p2.type.length) result = -1;
            else if (p2.type.length > p1.type.length) result = 1;

            // Order by file type if samee architecture
            if (result == 0) {
                var ext1 = path.extname(p1.filename);
                var ext2 = path.extname(p2.filename);
                var pos1 = _.indexOf(opts.filePreference, ext1);
                var pos2 = _.indexOf(opts.filePreference, ext2);

                pos1 = pos1 == -1? opts.filePreference.length : pos1;
                pos2 = pos2 == -1? opts.filePreference.length : pos2;

                if (pos1 < pos2) result = -1;
                else if (pos2 < pos1) result = 1;
            }
            return result;
        })
        .first()
        .value()
}
function resolveForVersion(version, platformID, opts) {
    opts = _.defaults(opts || {}, {
        // Order for filetype
        filePreference: ['.exe', '.dmg', '.deb', '.rpm', '.tgz', '.tar.gz', '.zip', '.nupkg'],
        wanted: null
    });

    // Prepare file prefs
    if (opts.wanted) opts.filePreference = _.uniq([opts.wanted].concat(opts.filePreference));

    // Normalize platform id
    platformID = detectPlatform(platformID);

    return _.chain(version.platforms)
        .filter(function(pl) {
            return pl.type.indexOf(platformID) === 0;
        })
        .sort(function(p1, p2) {
            var result = 0;

            // Compare by arhcitecture ("osx_64" > "osx")
            if (p1.type.length > p2.type.length) result = -1;
            else if (p2.type.length > p1.type.length) result = 1;

            // Order by file type if samee architecture
            if (result == 0) {
                var ext1 = path.extname(p1.filename);
                var ext2 = path.extname(p2.filename);
                var pos1 = _.indexOf(opts.filePreference, ext1);
                var pos2 = _.indexOf(opts.filePreference, ext2);

                pos1 = pos1 == -1? opts.filePreference.length : pos1;
                pos2 = pos2 == -1? opts.filePreference.length : pos2;

                if (pos1 < pos2) result = -1;
                else if (pos2 < pos1) result = 1;
            }
            return result;
        })
        .first()
        .value()
}
function resolveForVersion ( version , platformID , opts ) { opts = _ . defaults ( opts || { } , { // Order for filetype filePreference : [ '.exe' , '.dmg' , '.deb' , '.rpm' , '.tgz' , '.tar.gz' , '.zip' , '.nupkg' ] , wanted : null } ) ; // Prepare file prefs if ( opts . wanted ) opts . filePreference = _ . uniq ( [ opts . wanted ] . concat ( opts . filePreference ) ) ; // Normalize platform id platformID = detectPlatform ( platformID ) ; return _ . chain ( version . platforms ) . filter ( function ( pl ) { return pl . type . indexOf ( platformID ) === 0 ; } ) . sort ( function ( p1 , p2 ) { var result = 0 ; // Compare by arhcitecture ("osx_64" > "osx") if ( p1 . type . length > p2 . type . length ) result = - 1 ; else if ( p2 . type . length > p1 . type . length ) result = 1 ; // Order by file type if samee architecture if ( result == 0 ) { var ext1 = path . extname ( p1 . filename ) ; var ext2 = path . extname ( p2 . filename ) ; var pos1 = _ . indexOf ( opts . filePreference , ext1 ) ; var pos2 = _ . indexOf ( opts . filePreference , ext2 ) ; pos1 = pos1 == - 1 ? opts . filePreference . length : pos1 ; pos2 = pos2 == - 1 ? opts . filePreference . length : pos2 ; if ( pos1 < pos2 ) result = - 1 ; else if ( pos2 < pos1 ) result = 1 ; } return result ; } ) . first ( ) . value ( ) }
Resolve a platform for a version
Resolve a platform for a version