Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Github API for listing releases to download #5

Merged
merged 1 commit into from Dec 10, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions app/github.js
@@ -0,0 +1,27 @@
var github = require('octonode');

var githubReleases = {
fetch: function (user, repo, cb) {
var client = github.client();

var repo = client.repo(user + '/' + repo);

repo.releases(function (err, status, body) {
if (err) {
return cb(err);
}

if (status !== 200) {
return cb(new Error("Bad response from Github API: "));
}

var releases = body.reduce(function (memo, releaseInfo) {
memo[releaseInfo.name] = releaseInfo;
}, {});

cb(null, releases);
});
}
};

module.exports = githubReleases;
39 changes: 28 additions & 11 deletions app/index.js
Expand Up @@ -3,6 +3,7 @@ var util = require('util');
var path = require('path');
var spawn = require('child_process').spawn;
var yeoman = require('yeoman-generator');
var githubReleases = require('./github');


var GhostGenerator = module.exports = function GhostGenerator(args, options, config) {
Expand All @@ -18,22 +19,38 @@ var GhostGenerator = module.exports = function GhostGenerator(args, options, con
util.inherits(GhostGenerator, yeoman.generators.Base);

GhostGenerator.prototype.askFor = function askFor() {
var self = this;
var cb = this.async();

// have Yeoman greet the user.
console.log(this.yeoman);

var prompts = [{
type: 'input',
name: 'version',
message: 'What version of Ghost do you want to download?',
default: '0.3.3'
}];

this.prompt(prompts, function (props) {
this.version = props.version;
cb();
}.bind(this));
// Grab the github releases for Ghost
githubReleases.fetch('TryGhost', 'Ghost', function (err, releases) {
// Store the available release map for later.
self.availableReleases = releases;

// Store the release names as the choices
var choices = [];
for(var key in releases) {
if (!releases.hasOwnProperty(key)) { continue; }

choices.push(key);
}

var prompts = [{
type: 'list',
name: 'version',
message: 'What version of Ghost do you want to download?',
choices: choices,
default: '0.3.3'
}];

self.prompt(prompts, function (props) {
self.version = props.version;
cb();
});
});
};

GhostGenerator.prototype.app = function app() {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -22,7 +22,8 @@
},
"dependencies": {
"yeoman-generator": "~0.13.0",
"fs-extra": "~0.8.1"
"fs-extra": "~0.8.1",
"octonode": "~0.4.1"
},
"devDependencies": {
"mocha": "~1.12.0"
Expand Down
9 changes: 6 additions & 3 deletions test/test-creation.js
Expand Up @@ -20,14 +20,17 @@ describe('ghost generator', function () {
});

it('creates expected files', function (done) {
// Extend the timeout since the github release download takes some time
this.timeout(10000);

var expected = [
// add files you expect to exist here.
'.jshintrc',
'.editorconfig'
'Gruntfile.js',
'core/ghost.js'
];

helpers.mockPrompt(this.app, {
'someOption': true
'version': '0.3.3'
});
this.app.options['skip-install'] = true;
this.app.run({}, function () {
Expand Down