Permalink
Browse files

update for yuan

  • Loading branch information...
1 parent 79c8d2d commit 32c65da70267732bbab3bd486cb7f02bbc93b3e8 Hsiaoming Yang committed Mar 21, 2013
Showing with 7 additions and 22 deletions.
  1. +1 −1 lib/info.js
  2. +6 −21 lib/sdk/yuan.js
View
@@ -44,7 +44,7 @@ function print(data) {
console.log(' ' + text);
}
if (data.versions) {
- var versions = Object.keys(data.versions);
+ var versions = data.versions;
var lines = Math.ceil(versions.length / 5);
console.log(' vers:', color.magenta(versions.slice(0, 5).join(' ')));
for (var i = 1; i < lines; i++) {
View
@@ -247,21 +247,19 @@ Yuan.prototype.info = function(data, callback) {
} else if (res.statusCode !== 200) {
callback && callback(body.message);
} else {
- if (Array.isArray(body)) {
- body = body.map(self.extend);
- } else {
+ if (data.name) {
body = self.extend(body);
}
callback && callback(null, res, body);
}
});
};
Yuan.prototype.extend = function(item) {
- if (item.versions) {
- var versions = sort(item.versions);
- var latest = Object.keys(versions)[0];
- item = _.extend(item, versions[latest]);
- item.versions = versions;
+ if (item.packages) {
+ item = _.extend(item, item.packages[item.version]);
+ item.versions = Object.keys(item.packages).sort(function(a, b) {
+ return semver.compare(b, a);
+ });
return item;
}
return item;
@@ -313,16 +311,3 @@ exports = module.exports = function(options) {
return new Yuan(options);
};
exports.Yuan = Yuan;
-
-
-function sort(versions) {
- var vers = Object.keys(versions).sort(function(a, b) {
- return semver.compare(b, a);
- });
- var ret = {};
- vers.forEach(function(v) {
- var pkg = versions[v];
- ret[v] = pkg;
- });
- return ret;
-}

0 comments on commit 32c65da

Please sign in to comment.