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

Make listStarterkits return an array of repo objects #463

Merged
merged 2 commits into from
Sep 2, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions core/lib/starterkit_manager.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"use strict";

var starterkit_manager = function (config) {
var path = require('path'),
fs = require('fs-extra'),
util = require('./utilities'),
paths = config.paths;
var path = require('path'),
fetch = require('node-fetch'),
fs = require('fs-extra'),
util = require('./utilities'),
paths = config.paths;

function loadStarterKit(starterkitName, clean) {
try {
Expand Down Expand Up @@ -41,8 +42,35 @@ var starterkit_manager = function (config) {
}
}

/**
* @func listStarterkits
* @desc Fetches starterkit repos from GH API that contain 'starterkit' in their name for the user 'pattern-lab'
* @returns {Promise} Returns an Array<{name,url}> for the starterkit repos
*/
function listStarterkits() {
console.log('https://github.com/search?utf8=%E2%9C%93&q=starterkit+in%3Aname%2C+user%3Apattern-lab&type=Repositories&ref=searchresults');
return fetch('https://api.github.com/search/repositories?q=starterkit+in:name+user:pattern-lab&sort=stars&order=desc', {
method: 'GET',
headers: {
'Accept': 'application/json'
}
}).then(function (res) {
var contentType = res.headers.get('content-type');
if (contentType && contentType.indexOf('application/json') === -1) {
throw new TypeError("StarterkitManager->listStarterkits: Not valid JSON");
}
return res.json()
}).then(function (json) {
if (!json.items || !Array.isArray(json.items)) {
return false;
}
return json.items
.map(function (repo) {
return {name: repo.name, url: repo.html_url}
});
}).catch(function (err) {
console.error(err);
return false;
});
}

function packStarterkit() {
Expand All @@ -63,7 +91,7 @@ var starterkit_manager = function (config) {
loadStarterKit(starterkitName, clean);
},
list_starterkits: function () {
listStarterkits();
return listStarterkits();
},
pack_starterkit: function () {
packStarterkit();
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"json5": "^0.5.0",
"lodash": "~4.13.1",
"markdown-it": "^6.0.1",
"node-fetch": "^1.6.0",
"patternengine-node-mustache": "^1.0.0"
},
"devDependencies": {
Expand Down