Skip to content

Commit

Permalink
Merge pull request #83 from yuchi/feature-semver-install
Browse files Browse the repository at this point in the history
CLI: Support for semver matching
  • Loading branch information
FokkeZB committed Dec 12, 2014
2 parents 4c48891 + f7284f2 commit bd90305
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 19 deletions.
4 changes: 2 additions & 2 deletions bin/gittio.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ program
.option('-p, --platform <platform>', 'apply to a specific platform only');

var install_cmd = program.command('install')
.usage('<id>@<version>:<platform>')
.usage('<id>@<version>:<platform>')
.description('install all missing modules and widgets')
.option('-t, --type <type>', 'widget or module (default: both)')
.action(install);
Expand Down Expand Up @@ -218,4 +218,4 @@ function demo(env) {

return gittio.demo(params);
});
}
}
52 changes: 44 additions & 8 deletions lib/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -121,4 +145,16 @@ exports.filterDists = function(cmp, o) {
}

return dists;
};
};

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);
}
6 changes: 3 additions & 3 deletions lib/gittio.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -600,4 +600,4 @@ function demo(o) {
exports.install = install;
exports.uninstall = uninstall;
exports.info = info;
exports.demo = demo;
exports.demo = demo;
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit bd90305

Please sign in to comment.