diff --git a/bin/gittio.js b/bin/gittio.js index 21a7fc2..7360cfa 100755 --- a/bin/gittio.js +++ b/bin/gittio.js @@ -21,7 +21,7 @@ program .option('-p, --platform ', 'apply to a specific platform only'); var install_cmd = program.command('install') - .usage('@:') + .usage('@:') .description('install all missing modules and widgets') .option('-t, --type ', 'widget or module (default: both)') .action(install); @@ -218,4 +218,4 @@ function demo(env) { return gittio.demo(params); }); -} \ No newline at end of file +} diff --git a/lib/component.js b/lib/component.js index 080c4b4..8238fa2 100644 --- a/lib/component.js +++ b/lib/component.js @@ -2,6 +2,7 @@ var os = require('os'), path = require('path'), logger = require('./logger'), request = require('request'), + semver = require('semver'), _ = require('underscore'), utils = require('./utils'), config = require('./config'); @@ -67,18 +68,41 @@ exports.filterDists = function(cmp, o) { var platform; + // valid **specific** version, valid range, or something else (tags?) + var targetVersion = semver.valid(o.version) || semver.validRange(o.version) || o.version; + + var versions = cmp.versions.map(function (v) { + return _.defaults({ + // checking for valid semvers (x.y.z) + // or semi-valid (x.y) + // or unknown format ones + version: semver.valid(v.version) || semver.valid(v.version + '.0') || v.version + }, v); + }).sort(looseCompareDists); + + var matches; + // while we have platforms to cover while ((platform = platforms.shift()) !== undefined) { - // find first version that.. - var version = _.find(cmp.versions, function (v) { + // filter for versions that.. + matches = versions.filter(function (v) { + // have a dist and matches platform + return v.dist && _.contains(v.platforms, platform); + }); - // has a dist if no version was asked - // or matches version if asked - // and matches platform - return ((o.version === undefined && v.dist) || v.version === o.version) && _.contains(v.platforms, platform); + var version; - }); + if (!targetVersion) { + version = matches.pop(); + + } else { + while ((version = matches.pop()) !== undefined) { + if (semver.satisfies(version.version, targetVersion)) { + break; + } + } + } var prefix = utils.prefix(cmp.id, o.version, platform); @@ -121,4 +145,16 @@ exports.filterDists = function(cmp, o) { } return dists; -}; \ No newline at end of file +}; + +function looseCompareDists(a, b) { + // 'master' is to be considered the 'last resort' version + if (a.version === 'master') { + return -1; + } + else if (b.version === 'master') { + return +1; + } + + return semver.compareLoose(a.version, b.version); +} diff --git a/lib/gittio.js b/lib/gittio.js index 0f34cf2..00c51a2 100755 --- a/lib/gittio.js +++ b/lib/gittio.js @@ -160,9 +160,9 @@ function install(o) { function _addDependency(cmp, dst, o) { if (cmp.type === 'module' && config.context === 'project') { - tiapp.addDependency(cmp.id, o.version, dst.platforms); + tiapp.addDependency(cmp.id, dst.version, dst.platforms); } else if (cmp.type === 'widget') { - alloy.addDependency(cmp.id, o.version); + alloy.addDependency(cmp.id, dst.version); } } @@ -600,4 +600,4 @@ function demo(o) { exports.install = install; exports.uninstall = uninstall; exports.info = info; -exports.demo = demo; \ No newline at end of file +exports.demo = demo; diff --git a/package.json b/package.json index 4517a8a..b8257fe 100644 --- a/package.json +++ b/package.json @@ -34,17 +34,18 @@ }, "preferGlobal": true, "dependencies": { - "request": "~2.30.0", "adm-zip": "~0.4.3", - "fs-extended": "~0.2.0", - "underscore": "~1.5.2", "async": "~0.2.9", "chalk": "~0.4.0", "commander": "~2.1.0", - "timodules": "~0.1.1", - "xml2js": "~0.4.1", + "fs-extended": "~0.2.0", + "request": "~2.30.0", "rimraf": "~2.2.5", - "update-notifier": "~0.1.7" + "semver": "^4.1.0", + "timodules": "~0.1.1", + "underscore": "~1.5.2", + "update-notifier": "~0.1.7", + "xml2js": "~0.4.1" }, "license": "Apache Public License v2", "bin": "./bin/gittio.js",