Skip to content

Commit

Permalink
Merge pull request #13 from mijdavis2/addDynamicVersionLookup
Browse files Browse the repository at this point in the history
Add dynamic weppy version lookup | yarn
  • Loading branch information
mijdavis2 authored Jan 1, 2017
2 parents e95e0ad + a608f2f commit 1d75227
Show file tree
Hide file tree
Showing 5 changed files with 3,956 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules/
.idea/
npm-debug.log
*.orig
yarn-error.log
11 changes: 9 additions & 2 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var yeoman = require('yeoman-generator');
var chalk = require('chalk');
var yosay = require('yosay');
var _ = require('lodash');

var svc = require('./service');

module.exports = yeoman.Base.extend({
_defaultYear: function() {
Expand All @@ -18,6 +18,7 @@ module.exports = yeoman.Base.extend({
},

prompting: function () {
var versionChoices = svc.getWeppyVersions();
return this.prompt([{
type : 'input',
name : 'useDirectory',
Expand All @@ -40,6 +41,12 @@ module.exports = yeoman.Base.extend({
name : 'username',
message : 'Your github username: '
},
{
type : 'list',
name : 'weppyVersion',
message : 'What Weppy version will you use?',
choices : versionChoices
},
{
type : 'list',
name : 'pythonVersion',
Expand Down Expand Up @@ -114,12 +121,12 @@ module.exports = yeoman.Base.extend({
reqMajor: this.answers.pythonVersion[0],
reqMinor: this.answers.pythonVersion[1],
reqPatch: this.answers.pythonVersion[2],
weppyVersion: this.answers.weppyVersion,
username: this.answers.username,
packageDescription: this.answers.packageDescription,
license: this.answers.license,
year: this._defaultYear(),
includeLicense: this.answers.includeLicense,
weppyVersion: '0.8.2'
};
if (this.answers.useDirectory != this.appname) {
this.destinationRoot(this.answers.useDirectory);
Expand Down
46 changes: 46 additions & 0 deletions app/service.js
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;
}
};
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,24 @@
"chalk": "^1.0.0",
"lodash": "^4.13.1",
"mocha": "^2.5.3",
"request": "^2.79.0",
"request-json": "^0.6.1",
"yeoman-character": "^1.1.0",
"yeoman-generator": "^0.23.0",
"yosay": "^1.0.0"
},
"devDependencies": {
"yeoman-test": "^1.0.0",
"yeoman-assert": "^2.0.0",
"eslint": "^2.1.0",
"eslint-config-xo-space": "^0.13.0",
"gulp": "^3.9.0",
"gulp-eslint": "^2.0.0",
"gulp-exclude-gitignore": "^1.0.0",
"gulp-line-ending-corrector": "^1.0.1",
"gulp-istanbul": "^0.10.3",
"gulp-line-ending-corrector": "^1.0.1",
"gulp-mocha": "^2.0.0",
"gulp-nsp": "^2.1.0",
"gulp-plumber": "^1.0.0",
"gulp-nsp": "^2.1.0"
"yeoman-assert": "^2.0.0",
"yeoman-test": "^1.0.0"
}
}
Loading

0 comments on commit 1d75227

Please sign in to comment.