Skip to content

Commit 7bfb4b0

Browse files
amberleyromoDSchau
authored andcommitted
[www/starters] tweaks to fix DX for no GH token on www (#8718)
Relevant to #8700 The mocked defaults for when there's no token / no github data fetched were incorrectly formatted. This fix ensures that you can develop on `www` without a token. cc @DSchau
1 parent 69a304a commit 7bfb4b0

File tree

2 files changed

+87
-95
lines changed

2 files changed

+87
-95
lines changed

www/gatsby-node.js

+86-86
Original file line numberDiff line numberDiff line change
@@ -444,18 +444,18 @@ exports.onCreateNode = ({ node, actions, getNode, getNodes }) => {
444444
// Default fields are to avoid graphql errors.
445445
const { owner, name: repoStub } = parseGHUrl(node.repo)
446446
const defaultFields = {
447-
slug: ``,
448-
stub: ``,
447+
slug: `/${repoStub}/`,
448+
stub: repoStub,
449449
name: ``,
450450
description: ``,
451451
stars: 0,
452452
lastUpdated: ``,
453453
owner: ``,
454454
githubFullName: ``,
455-
gatsbyMajorVersion: ``,
456-
allDependencies: [],
457-
gatsbyDependencies: [],
458-
miscDependencies: [],
455+
gatsbyMajorVersion: [[`no data`, `0`]],
456+
allDependencies: [[`no data`, `0`]],
457+
gatsbyDependencies: [[`no data`, `0`]],
458+
miscDependencies: [[`no data`, `0`]],
459459
}
460460

461461
if (!process.env.GITHUB_API_TOKEN) {
@@ -466,92 +466,92 @@ exports.onCreateNode = ({ node, actions, getNode, getNodes }) => {
466466
...defaultFields,
467467
},
468468
})
469-
}
470-
471-
Promise.all([
472-
getpkgjson(node.repo),
473-
githubApiClient.request(`
474-
query {
475-
repository(owner:"${owner}", name:"${repoStub}") {
476-
name
477-
stargazers {
478-
totalCount
479-
}
480-
createdAt
481-
updatedAt
482-
owner {
483-
login
469+
} else {
470+
Promise.all([
471+
getpkgjson(node.repo),
472+
githubApiClient.request(`
473+
query {
474+
repository(owner:"${owner}", name:"${repoStub}") {
475+
name
476+
stargazers {
477+
totalCount
478+
}
479+
createdAt
480+
updatedAt
481+
owner {
482+
login
483+
}
484+
nameWithOwner
484485
}
485-
nameWithOwner
486486
}
487+
`),
488+
])
489+
.then(results => {
490+
const [pkgjson, githubData] = results
491+
const {
492+
stargazers: { totalCount: stars },
493+
updatedAt: lastUpdated,
494+
owner: { login: owner },
495+
name,
496+
nameWithOwner: githubFullName,
497+
} = githubData.repository
498+
499+
const { dependencies = [], devDependencies = [] } = pkgjson
500+
const allDependencies = Object.entries(dependencies).concat(
501+
Object.entries(devDependencies)
502+
)
503+
504+
const gatsbyMajorVersion = allDependencies
505+
.filter(([key, _]) => key === `gatsby`)
506+
.map(version => {
507+
let [gatsby, versionNum] = version
508+
if (versionNum === `latest` || versionNum === `next`) {
509+
return [gatsby, `2`]
510+
}
511+
return [gatsby, versionNum.replace(/\D/g, ``).charAt(0)]
512+
})
513+
514+
// If a new field is added here, make sure a corresponding
515+
// change is made to "defaultFields" to not break DX
516+
const starterShowcaseFields = {
517+
slug: `/${repoStub}/`,
518+
stub: repoStub,
519+
name,
520+
description: pkgjson.description,
521+
stars,
522+
lastUpdated,
523+
owner,
524+
githubFullName,
525+
gatsbyMajorVersion,
526+
allDependencies,
527+
gatsbyDependencies: allDependencies
528+
.filter(
529+
([key, _]) => ![`gatsby-cli`, `gatsby-link`].includes(key) // remove stuff everyone has
530+
)
531+
.filter(([key, _]) => key.includes(`gatsby`)),
532+
miscDependencies: allDependencies.filter(
533+
([key, _]) => !key.includes(`gatsby`)
534+
),
487535
}
488-
`),
489-
])
490-
.then(results => {
491-
const [pkgjson, githubData] = results
492-
const {
493-
stargazers: { totalCount: stars },
494-
updatedAt: lastUpdated,
495-
owner: { login: owner },
496-
name,
497-
nameWithOwner: githubFullName,
498-
} = githubData.repository
499-
500-
const { dependencies = [], devDependencies = [] } = pkgjson
501-
const allDependencies = Object.entries(dependencies).concat(
502-
Object.entries(devDependencies)
503-
)
504-
505-
const gatsbyMajorVersion = allDependencies
506-
.filter(([key, _]) => key === `gatsby`)
507-
.map(version => {
508-
let [gatsby, versionNum] = version
509-
if (versionNum === `latest` || versionNum === `next`) {
510-
return [gatsby, `2`]
511-
}
512-
return [gatsby, versionNum.replace(/\D/g, ``).charAt(0)]
536+
createNodeField({
537+
node,
538+
name: `starterShowcase`,
539+
value: starterShowcaseFields,
513540
})
514-
515-
// If a new field is added here, make sure a corresponding
516-
// change is made to "defaultFields" to not break DX
517-
const starterShowcaseFields = {
518-
slug: `/${repoStub}/`,
519-
stub: repoStub,
520-
name,
521-
description: pkgjson.description,
522-
stars,
523-
lastUpdated,
524-
owner,
525-
githubFullName,
526-
gatsbyMajorVersion,
527-
allDependencies,
528-
gatsbyDependencies: allDependencies
529-
.filter(
530-
([key, _]) => ![`gatsby-cli`, `gatsby-link`].includes(key) // remove stuff everyone has
531-
)
532-
.filter(([key, _]) => key.includes(`gatsby`)),
533-
miscDependencies: allDependencies.filter(
534-
([key, _]) => !key.includes(`gatsby`)
535-
),
536-
}
537-
createNodeField({
538-
node,
539-
name: `starterShowcase`,
540-
value: starterShowcaseFields,
541541
})
542-
})
543-
.catch(err => {
544-
console.log(
545-
`\nError getting repo data. Your GitHub token may be invalid`
546-
)
547-
return createNodeField({
548-
node,
549-
name: `starterShowcase`,
550-
value: {
551-
...defaultFields,
552-
},
542+
.catch(err => {
543+
console.log(
544+
`\nError getting repo data. Your GitHub token may be invalid`
545+
)
546+
return createNodeField({
547+
node,
548+
name: `starterShowcase`,
549+
value: {
550+
...defaultFields,
551+
},
552+
})
553553
})
554-
})
554+
}
555555
}
556556

557557
// Community/Creators Pages

www/src/views/starter-library/starter-list.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,7 @@ const StartersList = ({ urlState, starters, count, sortRecent }) => {
6767
stars,
6868
stub,
6969
} = starter.fields.starterShowcase
70-
const { url: demoUrl, repo: repoUrl } = starter
71-
const gatsbyVersion = gatsbyDependencies.find(
72-
([k, v]) => k === `gatsby`
73-
)[1]
74-
const match = gatsbyVersion.match(/([0-9]+)([.])([0-9]+)/) // we just want x.x
75-
const minorVersion = match ? match[0] : gatsbyVersion // default to version if no match
76-
const isGatsbyVersionWarning = !/(2..+|next|latest)/g.test(
77-
minorVersion
78-
) // either 2.x or next or latest
70+
const { url: demoUrl } = starter
7971

8072
return (
8173
starter.fields && ( // have to filter out null fields from bad data

0 commit comments

Comments
 (0)