-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from mijdavis2/addDynamicVersionLookup
Add dynamic weppy version lookup | yarn
- Loading branch information
Showing
5 changed files
with
3,956 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ node_modules/ | |
.idea/ | ||
npm-debug.log | ||
*.orig | ||
yarn-error.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
var request = require('request-json'); | ||
var client = request.createClient('http://pypi.python.org/pypi/weppy/'); | ||
|
||
function getReleases(data) { | ||
var x; | ||
var xlist = []; | ||
for (x in data.releases) { | ||
xlist.push(x); | ||
} | ||
return xlist; | ||
} | ||
|
||
function cmpVersions (a, b) { | ||
var i, diff; | ||
var regExStrip0 = /(\.0+)+$/; | ||
var segmentsA = a.replace(regExStrip0, '').split('.'); | ||
var segmentsB = b.replace(regExStrip0, '').split('.'); | ||
var l = Math.min(segmentsA.length, segmentsB.length); | ||
|
||
for (i = 0; i < l; i++) { | ||
diff = parseInt(segmentsA[i], 10) - parseInt(segmentsB[i], 10); | ||
if (diff) { | ||
return diff; | ||
} | ||
} | ||
return segmentsA.length - segmentsB.length; | ||
} | ||
|
||
module.exports = { | ||
getWeppyVersions: function() { | ||
var choices = []; | ||
client.get('json/') | ||
.then(function(result) { | ||
var releases = getReleases(result.body); | ||
// console.log(releases); | ||
var sortedReleases = releases.sort(cmpVersions).reverse(); | ||
// console.log(sortedReleases); | ||
sortedReleases.forEach(function(x) { | ||
choices.push({name: x, value: x}) | ||
}); | ||
} | ||
); | ||
return choices; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.