Skip to content

Commit

Permalink
Use flat array for repo data and object for each so we can add more meta
Browse files Browse the repository at this point in the history
  • Loading branch information
brentvatne committed Jul 6, 2017
1 parent 51988ee commit f9ce3f9
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 149 deletions.
4 changes: 2 additions & 2 deletions common/store.js
Expand Up @@ -5,8 +5,8 @@ import data from '../build/data.json';
const topics = {};
const all = [...data.incompatible, ...data.expo];

all.forEach(repo => {
repo.topics.forEach(topic => {
all.forEach(project => {
project.github.topics.forEach(topic => {
if (!topics[topic]) {
topics[topic] = 1;
return;
Expand Down
18 changes: 9 additions & 9 deletions components/List.js
Expand Up @@ -186,22 +186,22 @@ export default class List extends React.PureComponent {
} else {
elements = this.props.data.map(item => {
return renderItem({
name: item.name,
name: item.github.name,
column1: {
top: (
<Link isDarkStyled href={item.urls.repo}>
{item.name}
<Link isDarkStyled href={item.github.urls.repo}>
{item.github.name}
</Link>
),
bottom: item.urls.homepage
? <Link isStyled href={item.urls.homepage}>
bottom: item.github.urls.homepage
? <Link isStyled href={item.github.urls.homepage}>
homepage
</Link>
: undefined,
},
column2: {
top: item.description,
bottom: item.topics.map(each =>
top: item.github.description,
bottom: item.github.topics.map(each =>
<TopicItem
key={`list-${item.name}-${each}`}
count={this.props.topics[each]}>
Expand All @@ -210,8 +210,8 @@ export default class List extends React.PureComponent {
),
},
column3: {
top: getTimeSinceToday(item.stats.pushedAt),
bottom: `${item.score}/100 — ${item.stats.stars} stars`,
top: getTimeSinceToday(item.github.stats.pushedAt),
bottom: `${item.score}/100 — ${item.github.stats.stars} stars`,
},
});
});
Expand Down
19 changes: 9 additions & 10 deletions debug-github-repos.json
@@ -1,10 +1,9 @@
{
"expo": [
{"github": "https://github.com/expo/react-native-action-sheet", "pkg": "@expo/react-native-action-sheet"},
"https://github.com/react-community/react-navigation",
"https://github.com/gre/gl-react"
],
"incompatible": [
"https://github.com/PeelTechnologies/react-native-tcp"
]
}
[
{
"githubUrl": "https://github.com/react-community/react-navigation",
"expo": true
},
{ "githubUrl": "https://github.com/gre/gl-react", "expo": true },
{ "githubUrl": "https://github.com/n4kz/react-native-pages", "expo": true },
{ "githubUrl": "https://github.com/airbnb/lottie-react-native", "expo": true }
]
132 changes: 90 additions & 42 deletions github-repos.json
@@ -1,42 +1,90 @@
{
"expo": [
"https://github.com/react-community/react-navigation",
"https://github.com/gre/gl-react",
"https://github.com/n4kz/react-native-pages",
"https://github.com/airbnb/lottie-react-native",
"https://github.com/airbnb/react-native-maps",
"https://github.com/oblador/react-native-animatable",
"https://github.com/wix/react-native-calendars",
"https://github.com/oblador/react-native-vector-icons",
"https://github.com/idibidiart/react-native-responsive-grid",
"https://github.com/24ark/react-native-step-indicator",
"https://github.com/jacklam718/react-native-popup-dialog",
"https://github.com/react-native-community/react-native-drawer-layout",
"https://github.com/n4kz/react-native-material-textfield",
"https://github.com/maxs15/react-native-modalbox",
"https://github.com/react-native-community/react-native-modal",
"https://github.com/react-native-training/react-native-elements",
"https://github.com/FaridSafi/react-native-gifted-chat",
"https://github.com/react-native-community/react-native-tab-view",
"https://github.com/bgryszko/react-native-circular-slider",
"https://github.com/archriss/react-native-snap-carousel",
"https://github.com/mmazzarolo/react-native-modal-datetime-picker",
"https://github.com/magicismight/react-native-root-siblings",
{"github": "https://github.com/expo/react-native-action-sheet", "pkg": "@expo/react-native-action-sheet"}
],
"incompatible": [
"https://github.com/PeelTechnologies/react-native-tcp",
"https://github.com/naoufal/react-native-speech",
"https://github.com/EstebanFuentealba/react-native-share",
"https://github.com/aakashns/react-native-dialogs",
"https://github.com/oblador/react-native-keychain",
"https://github.com/joeferraro/react-native-cookies",
"https://github.com/doefler/react-native-social-share",
"https://github.com/innoveit/react-native-ble-manager",
"https://github.com/chirag04/react-native-mail",
"https://github.com/cnjon/react-native-pdf-view",
"https://github.com/kayla-tech/react-native-card-io",
"https://github.com/Kerumen/react-native-awesome-card-io",
"https://github.com/tolu360/react-native-google-places"
]
}
[
{
"githubUrl": "https://github.com/react-community/react-navigation",
"expo": true
},
{ "githubUrl": "https://github.com/gre/gl-react", "expo": true },
{ "githubUrl": "https://github.com/n4kz/react-native-pages", "expo": true },
{ "githubUrl": "https://github.com/airbnb/lottie-react-native", "expo": true },
{ "githubUrl": "https://github.com/airbnb/react-native-maps", "expo": true },
{
"githubUrl": "https://github.com/oblador/react-native-animatable",
"expo": true
},
{ "githubUrl": "https://github.com/wix/react-native-calendars", "expo": true },
{
"githubUrl": "https://github.com/oblador/react-native-vector-icons",
"expo": true
},
{
"githubUrl": "https://github.com/idibidiart/react-native-responsive-grid",
"expo": true
},
{
"githubUrl": "https://github.com/24ark/react-native-step-indicator",
"expo": true
},
{
"githubUrl": "https://github.com/jacklam718/react-native-popup-dialog",
"expo": true
},
{
"githubUrl": "https://github.com/react-native-community/react-native-drawer-layout",
"expo": true
},
{
"githubUrl": "https://github.com/n4kz/react-native-material-textfield",
"expo": true
},
{ "githubUrl": "https://github.com/maxs15/react-native-modalbox", "expo": true },
{
"githubUrl": "https://github.com/react-native-community/react-native-modal",
"expo": true
},
{
"githubUrl": "https://github.com/react-native-training/react-native-elements",
"expo": true
},
{
"githubUrl": "https://github.com/FaridSafi/react-native-gifted-chat",
"expo": true
},
{
"githubUrl": "https://github.com/react-native-community/react-native-tab-view",
"expo": true
},
{
"githubUrl": "https://github.com/bgryszko/react-native-circular-slider",
"expo": true
},
{
"githubUrl": "https://github.com/archriss/react-native-snap-carousel",
"expo": true
},
{
"githubUrl": "https://github.com/mmazzarolo/react-native-modal-datetime-picker",
"expo": true
},
{
"githubUrl": "https://github.com/magicismight/react-native-root-siblings",
"expo": true
},
{
"githubUrl": "https://github.com/expo/react-native-action-sheet",
"npmPkg": "@expo/react-native-action-sheet",
"expo": true
},
{ "githubUrl": "https://github.com/PeelTechnologies/react-native-tcp" },
{ "githubUrl": "https://github.com/naoufal/react-native-speech" },
{ "githubUrl": "https://github.com/EstebanFuentealba/react-native-share" },
{ "githubUrl": "https://github.com/aakashns/react-native-dialogs" },
{ "githubUrl": "https://github.com/oblador/react-native-keychain" },
{ "githubUrl": "https://github.com/joeferraro/react-native-cookies" },
{ "githubUrl": "https://github.com/doefler/react-native-social-share" },
{ "githubUrl": "https://github.com/innoveit/react-native-ble-manager" },
{ "githubUrl": "https://github.com/chirag04/react-native-mail" },
{ "githubUrl": "https://github.com/cnjon/react-native-pdf-view" },
{ "githubUrl": "https://github.com/kayla-tech/react-native-card-io" },
{ "githubUrl": "https://github.com/Kerumen/react-native-awesome-card-io" },
{ "githubUrl": "https://github.com/tolu360/react-native-google-places" }
]
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -25,6 +25,7 @@
"express": "^4.14.0",
"isomorphic-fetch": "^2.2.1",
"jsonfile": "^3.0.0",
"lodash": "^4.17.4",
"next": "^2.1.1",
"next-redux-wrapper": "^1.0.0",
"next-routes": "^1.0.24",
Expand Down
53 changes: 17 additions & 36 deletions scripts/build-and-score-data.js
Expand Up @@ -2,6 +2,7 @@ import 'isomorphic-fetch';
import path from 'path';
import fs from 'fs';
import jsonfile from 'jsonfile';
import _ from 'lodash';
import fetchGithubData from './fetch-github-data';
import calculateScore from './calculate-score';
import fetchReadmeImages from './fetch-readme-images';
Expand All @@ -16,7 +17,7 @@ const USE_DEBUG_REPOS = false;

// Loads the Github API results from disk rather than hitting the API each time.
// The first run will hit the API if raw-github-results.json doesn't exist yet.
const LOAD_GITHUB_RESULTS_FROM_DISK = false;
const LOAD_GITHUB_RESULTS_FROM_DISK = true;
const GITHUB_RESULTS_PATH = path.join('scripts', 'raw-github-results.json');

const JSON_OPTIONS = {
Expand All @@ -25,37 +26,26 @@ const JSON_OPTIONS = {

const buildAndScoreData = async () => {
console.log('** Loading data from Github');
let { expo, incompatible } = await loadRepositoryDataAsync();
let data = await loadRepositoryDataAsync();

console.log('\n** Scraping images from README');
expo = await Promise.all(
expo.map(repo => fetchReadmeImages(repo, repo.urls.repo))
);

incompatible = await Promise.all(
incompatible.map(repo => fetchReadmeImages(repo, repo.urls.repo))
);
data = await Promise.all(data.map(d => fetchReadmeImages(d, d.githubUrl)));

console.log('\n** Loading download stats from npm');
expo = await Promise.all(expo.map(repo => fetchNpmData(repo, repo.pkg)));

incompatible = await Promise.all(
incompatible.map(repo => fetchNpmData(repo, repo.pkg))
data = await Promise.all(
data.map(d => fetchNpmData(d, d.npmPkg, d.githubUrl))
);

// Calculate score
console.log('\n** Calculating scores');
expo = expo.map(calculateScore);
incompatible = incompatible.map(calculateScore);
data = data.map(calculateScore);

const jsonData = {
expo,
incompatible,
};
const expo = _.filter(data, d => d.expo);
const incompatible = _.filter(data, d => !d.expo);

return jsonfile.writeFile(
path.resolve('build', 'data.json'),
jsonData,
{ expo, incompatible },
JSON_OPTIONS,
err => {
if (err) {
Expand All @@ -81,26 +71,17 @@ async function loadRepositoryDataAsync() {
result = jsonfile.readFileSync(GITHUB_RESULTS_PATH);
console.log('Loaded Github results from disk, skipped API calls');
} else {
let expo = await Promise.all(data.expo.map(fetchGithubData));
let incompatible = await Promise.all(
data.incompatible.map(fetchGithubData)
);
result = { expo, incompatible };
result = await Promise.all(data.map(fetchGithubData));

if (LOAD_GITHUB_RESULTS_FROM_DISK) {
await new Promise((resolve, reject) => {
jsonfile.writeFile(
GITHUB_RESULTS_PATH,
{ expo, incompatible },
JSON_OPTIONS,
err => {
if (err) {
reject(err);
} else {
resolve();
}
jsonfile.writeFile(GITHUB_RESULTS_PATH, result, JSON_OPTIONS, err => {
if (err) {
reject(err);
} else {
resolve();
}
);
});
});
console.log('Saved Github results from disk');
}
Expand Down
56 changes: 29 additions & 27 deletions scripts/calculate-score.js
@@ -1,53 +1,55 @@
const calculateScore = repo => {
repo.score = 0;
const calculateScore = data => {
let { github } = data;
let score = 0;

const daysAgo = getDaysAgo(repo.stats.updatedAt);
const daysAgo = getDaysAgo(github.stats.updatedAt);

if (daysAgo <= 30) {
repo.score += 15;
score += 15;
} else if (daysAgo <= 60) {
repo.score += 10;
score += 10;
} else if (daysAgo <= 90) {
repo.score += 5;
score += 5;
}

if (repo.stats.hasIssues) {
repo.score += 10;
if (github.stats.hasIssues) {
score += 10;
}

if (repo.stats.hasWiki) {
repo.score += 10;
if (github.stats.hasWiki) {
score += 10;
}

if (repo.stats.hasPages) {
repo.score += 5;
if (github.stats.hasPages) {
score += 5;
}

if (repo.stats.hasDownloads) {
repo.score += 10;
if (github.stats.hasDownloads) {
score += 10;
}

if (repo.stats.hasTopics) {
repo.score += 10;
if (github.stats.hasTopics) {
score += 10;
}

if (repo.stats.watchers > 10) {
repo.score += 5;
if (github.stats.watchers > 10) {
score += 5;
}

if (repo.stats.forks > 5) {
repo.score += 10;
if (github.stats.forks > 5) {
score += 10;
}

if (repo.stats.stars >= 2500) {
repo.score += 20;
} else if (repo.stats.stars >= 500) {
repo.score += 15;
} else if (repo.stats.stars >= 100) {
repo.score += 10;
if (github.stats.stars >= 2500) {
score += 20;
} else if (github.stats.stars >= 500) {
score += 15;
} else if (github.stats.stars >= 100) {
score += 10;
}

return repo;
data.score = score;
return data;
};

const getDaysAgo = date => {
Expand Down

0 comments on commit f9ce3f9

Please sign in to comment.