-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
[www/starters] tweaks to fix DX for no GH token on www #8718
Merged
DSchau
merged 1 commit into
gatsbyjs:master
from
amberleyromo:fix/www/starter-dev-process
Oct 2, 2018
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -444,18 +444,18 @@ exports.onCreateNode = ({ node, actions, getNode, getNodes }) => { | |
// Default fields are to avoid graphql errors. | ||
const { owner, name: repoStub } = parseGHUrl(node.repo) | ||
const defaultFields = { | ||
slug: ``, | ||
stub: ``, | ||
slug: `/${repoStub}/`, | ||
stub: repoStub, | ||
name: ``, | ||
description: ``, | ||
stars: 0, | ||
lastUpdated: ``, | ||
owner: ``, | ||
githubFullName: ``, | ||
gatsbyMajorVersion: ``, | ||
allDependencies: [], | ||
gatsbyDependencies: [], | ||
miscDependencies: [], | ||
gatsbyMajorVersion: [[`no data`, `0`]], | ||
allDependencies: [[`no data`, `0`]], | ||
gatsbyDependencies: [[`no data`, `0`]], | ||
miscDependencies: [[`no data`, `0`]], | ||
} | ||
|
||
if (!process.env.GITHUB_API_TOKEN) { | ||
|
@@ -466,92 +466,92 @@ exports.onCreateNode = ({ node, actions, getNode, getNodes }) => { | |
...defaultFields, | ||
}, | ||
}) | ||
} | ||
|
||
Promise.all([ | ||
getpkgjson(node.repo), | ||
githubApiClient.request(` | ||
query { | ||
repository(owner:"${owner}", name:"${repoStub}") { | ||
name | ||
stargazers { | ||
totalCount | ||
} | ||
createdAt | ||
updatedAt | ||
owner { | ||
login | ||
} else { | ||
Promise.all([ | ||
getpkgjson(node.repo), | ||
githubApiClient.request(` | ||
query { | ||
repository(owner:"${owner}", name:"${repoStub}") { | ||
name | ||
stargazers { | ||
totalCount | ||
} | ||
createdAt | ||
updatedAt | ||
owner { | ||
login | ||
} | ||
nameWithOwner | ||
} | ||
nameWithOwner | ||
} | ||
`), | ||
]) | ||
.then(results => { | ||
const [pkgjson, githubData] = results | ||
const { | ||
stargazers: { totalCount: stars }, | ||
updatedAt: lastUpdated, | ||
owner: { login: owner }, | ||
name, | ||
nameWithOwner: githubFullName, | ||
} = githubData.repository | ||
|
||
const { dependencies = [], devDependencies = [] } = pkgjson | ||
const allDependencies = Object.entries(dependencies).concat( | ||
Object.entries(devDependencies) | ||
) | ||
|
||
const gatsbyMajorVersion = allDependencies | ||
.filter(([key, _]) => key === `gatsby`) | ||
.map(version => { | ||
let [gatsby, versionNum] = version | ||
if (versionNum === `latest` || versionNum === `next`) { | ||
return [gatsby, `2`] | ||
} | ||
return [gatsby, versionNum.replace(/\D/g, ``).charAt(0)] | ||
}) | ||
|
||
// If a new field is added here, make sure a corresponding | ||
// change is made to "defaultFields" to not break DX | ||
const starterShowcaseFields = { | ||
slug: `/${repoStub}/`, | ||
stub: repoStub, | ||
name, | ||
description: pkgjson.description, | ||
stars, | ||
lastUpdated, | ||
owner, | ||
githubFullName, | ||
gatsbyMajorVersion, | ||
allDependencies, | ||
gatsbyDependencies: allDependencies | ||
.filter( | ||
([key, _]) => ![`gatsby-cli`, `gatsby-link`].includes(key) // remove stuff everyone has | ||
) | ||
.filter(([key, _]) => key.includes(`gatsby`)), | ||
miscDependencies: allDependencies.filter( | ||
([key, _]) => !key.includes(`gatsby`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same in these other spots. |
||
), | ||
} | ||
`), | ||
]) | ||
.then(results => { | ||
const [pkgjson, githubData] = results | ||
const { | ||
stargazers: { totalCount: stars }, | ||
updatedAt: lastUpdated, | ||
owner: { login: owner }, | ||
name, | ||
nameWithOwner: githubFullName, | ||
} = githubData.repository | ||
|
||
const { dependencies = [], devDependencies = [] } = pkgjson | ||
const allDependencies = Object.entries(dependencies).concat( | ||
Object.entries(devDependencies) | ||
) | ||
|
||
const gatsbyMajorVersion = allDependencies | ||
.filter(([key, _]) => key === `gatsby`) | ||
.map(version => { | ||
let [gatsby, versionNum] = version | ||
if (versionNum === `latest` || versionNum === `next`) { | ||
return [gatsby, `2`] | ||
} | ||
return [gatsby, versionNum.replace(/\D/g, ``).charAt(0)] | ||
createNodeField({ | ||
node, | ||
name: `starterShowcase`, | ||
value: starterShowcaseFields, | ||
}) | ||
|
||
// If a new field is added here, make sure a corresponding | ||
// change is made to "defaultFields" to not break DX | ||
const starterShowcaseFields = { | ||
slug: `/${repoStub}/`, | ||
stub: repoStub, | ||
name, | ||
description: pkgjson.description, | ||
stars, | ||
lastUpdated, | ||
owner, | ||
githubFullName, | ||
gatsbyMajorVersion, | ||
allDependencies, | ||
gatsbyDependencies: allDependencies | ||
.filter( | ||
([key, _]) => ![`gatsby-cli`, `gatsby-link`].includes(key) // remove stuff everyone has | ||
) | ||
.filter(([key, _]) => key.includes(`gatsby`)), | ||
miscDependencies: allDependencies.filter( | ||
([key, _]) => !key.includes(`gatsby`) | ||
), | ||
} | ||
createNodeField({ | ||
node, | ||
name: `starterShowcase`, | ||
value: starterShowcaseFields, | ||
}) | ||
}) | ||
.catch(err => { | ||
console.log( | ||
`\nError getting repo data. Your GitHub token may be invalid` | ||
) | ||
return createNodeField({ | ||
node, | ||
name: `starterShowcase`, | ||
value: { | ||
...defaultFields, | ||
}, | ||
.catch(err => { | ||
console.log( | ||
`\nError getting repo data. Your GitHub token may be invalid` | ||
) | ||
return createNodeField({ | ||
node, | ||
name: `starterShowcase`, | ||
value: { | ||
...defaultFields, | ||
}, | ||
}) | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
// Community/Creators Pages | ||
|
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 |
---|---|---|
|
@@ -67,15 +67,7 @@ const StartersList = ({ urlState, starters, count, sortRecent }) => { | |
stars, | ||
stub, | ||
} = starter.fields.starterShowcase | ||
const { url: demoUrl, repo: repoUrl } = starter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! Removed some client side code in favor of injecting it, correct? 🎉 |
||
const gatsbyVersion = gatsbyDependencies.find( | ||
([k, v]) => k === `gatsby` | ||
)[1] | ||
const match = gatsbyVersion.match(/([0-9]+)([.])([0-9]+)/) // we just want x.x | ||
const minorVersion = match ? match[0] : gatsbyVersion // default to version if no match | ||
const isGatsbyVersionWarning = !/(2..+|next|latest)/g.test( | ||
minorVersion | ||
) // either 2.x or next or latest | ||
const { url: demoUrl } = starter | ||
|
||
return ( | ||
starter.fields && ( // have to filter out null fields from bad data | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: but the second arg (
_
) isn't used here at all, right?