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

Adopt Gatsby #2906

Merged
merged 32 commits into from
Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
994dde7
Adopt Gatsby
paulmelnikow Feb 2, 2019
d24a51d
Rm unused dependencies
paulmelnikow Feb 2, 2019
fa08d7c
Path fixes
paulmelnikow Feb 2, 2019
169176e
Clean lint
paulmelnikow Feb 2, 2019
d2de581
Merge branch 'master' into gatsby
paulmelnikow Feb 2, 2019
4c2cc0d
Fix a bunch of things
paulmelnikow Feb 2, 2019
0baa43e
Get tests passing
paulmelnikow Feb 2, 2019
29b2642
Fixes?
paulmelnikow Feb 2, 2019
8811987
Fix tests in CI
paulmelnikow Feb 2, 2019
21cba40
Remove unused dep
paulmelnikow Feb 4, 2019
c2d51d4
Merge branch 'master' into gatsby
paulmelnikow Feb 4, 2019
38bb31d
Update lockfile
paulmelnikow Feb 4, 2019
3e8ac12
Fix coverage
paulmelnikow Feb 4, 2019
13c568d
now wip
paulmelnikow Feb 4, 2019
baafc06
Update nowignore
paulmelnikow Feb 4, 2019
db1daaa
Fix danger
paulmelnikow Feb 5, 2019
abddbe5
Redirect legacy routes
paulmelnikow Feb 5, 2019
7746bfa
Clean up NavLink
paulmelnikow Feb 5, 2019
354b155
Fix build
paulmelnikow Feb 5, 2019
f12ef32
Rm Next logic from dangerfile
paulmelnikow Feb 5, 2019
f7a4bc6
Update lockfile
paulmelnikow Feb 5, 2019
f462fef
Fix crash when displaying search results
paulmelnikow Feb 5, 2019
720e426
Fix favicon
paulmelnikow Feb 5, 2019
4c7322e
Merge branch 'master' into gatsby
paulmelnikow Feb 5, 2019
ee060b2
Update lockfile
paulmelnikow Feb 5, 2019
62ea1ab
Add comment about pageContext
paulmelnikow Feb 5, 2019
7883c9a
Merge branch 'master' into gatsby
paulmelnikow Feb 6, 2019
b68c282
Merge branch 'master' into gatsby
paulmelnikow Feb 6, 2019
51a1491
Require the rest of the files at the end instead of the beginning
paulmelnikow Feb 6, 2019
bc95151
Don’t crash because of PNGs
paulmelnikow Feb 6, 2019
b8cbf0f
Merge branch 'master' into gatsby
paulmelnikow Feb 6, 2019
bc645dd
Merge branch 'master' into gatsby
paulmelnikow Feb 6, 2019
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
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ jobs:
- run:
name: Danger
when: always
environment:
# https://github.com/gatsbyjs/gatsby/pull/11555
NODE_ENV: test
command: npm run danger ci

frontend:
Expand Down
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/build
/coverage
/__snapshots__
/public
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,7 @@ service-definitions.yml

# Template for the local runtime configuration.
!/config/local*.template.yml

# Gatsby
/.cache
/public
30 changes: 30 additions & 0 deletions .nowignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
*
!frontend/
!gh-badges/
!lib/
!core/
!logo/
!pages/
!public/
!templates/
!services/
!package-lock.json
!/*.js
!scripts/export-*.js
!config/
config/local*.yml
*.spec.js
*~
.env
.circleci
.github
.vscode
__snapshots__
.buildpacks
.eslint*
.editorconfig
.nycrc*
.gitpod*
.prettier*
CONTRIBUTING.md
Dockerfile
5 changes: 3 additions & 2 deletions .nycrc-frontend.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"reporter": ["lcov"],
"all": true,
"all": false,
"silent": true,
"clean": false,
"sourceMap": false,
"instrument": false,
"exclude": ["**/*.spec.js"]
"include": ["frontend/**/*.js"],
"exclude": ["**/*.spec.js", "**/mocha-*.js"]
}
2 changes: 1 addition & 1 deletion .nycrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"**/test-helpers.js",
"**/*-test-helpers.js",
"dangerfile.js",
"next.config.js",
"gatsby-*.js",
"services/**/*.tester.js",
"services/service-tester.js",
"services/create-service-tester.js",
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package-lock.json
/__snapshots__
/.next
/build
/public
/coverage
private/*.json
/.nyc_output
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ push-s2:
deploy-gh-pages:
rm -rf ${FRONTEND_TMP}
git worktree prune
BASE_URL=https://img.shields.io \
GATSBY_BASE_URL=https://img.shields.io \
NEXT_ASSET_PREFIX=https://shields.io \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is NEXT_ASSET_PREFIX still relevant?

Copy link
Member Author

@paulmelnikow paulmelnikow Feb 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, though I haven't attempted to tackle the deploy process at all. I figure I'll draft it when I do the first deploy and open a second PR once I get something that works.

npm run build
git worktree add -B gh-pages ${FRONTEND_TMP}
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p align="center">
<img src="https://rawgit.com/badges/shields/master/static/logo.svg"
<img src="https://rawgit.com/badges/shields/master/frontend/static/logo.svg"
height="130">
</p>
<p align="center">
Expand Down Expand Up @@ -116,9 +116,6 @@ Please report any Gitpod bugs, questions, or suggestions in issue

[![Edit with Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/badges/shields)

To analyze the frontend bundle, run `npm install webpack-bundle-analyzer` and
then `ANALYZE=true npm start`.

[Snapshot tests][] ensure we don't inadvertently make changes that affect the
SVG or JSON output. When deliberately changing the output, run
`SNAPSHOT_DRY=1 npm run test:js:server` to preview changes to the saved
Expand Down
29 changes: 18 additions & 11 deletions core/base-service/legacy-result-sender.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
'use strict'

const fs = require('fs')
const path = require('path')
const stream = require('stream')
const svg2img = require('../../gh-badges/lib/svg-to-img')
const log = require('../server/log')

const internalError = fs.readFileSync(
path.resolve(__dirname, '..', 'server', 'error-pages', '500.html'),
'utf-8'
)

function streamFromString(str) {
const newStream = new stream.Readable()
newStream._read = () => {
Expand All @@ -13,16 +20,6 @@ function streamFromString(str) {
return newStream
}

function makeSend(format, askres, end) {
if (format === 'svg') {
return res => sendSVG(res, askres, end)
} else if (format === 'json') {
return res => sendJSON(res, askres, end)
} else {
return res => sendOther(format, res, askres, end)
}
}

function sendSVG(res, askres, end) {
askres.setHeader('Content-Type', 'image/svg+xml;charset=utf-8')
end(null, { template: streamFromString(res) })
Expand All @@ -39,7 +36,7 @@ function sendOther(format, res, askres, end) {
.catch(err => {
// This emits status code 200, though 500 would be preferable.
log.error('svg2img error', err)
end(null, { template: '500.html' })
end(internalError)
})
}

Expand All @@ -49,6 +46,16 @@ function sendJSON(res, askres, end) {
end(null, { template: streamFromString(res) })
}

function makeSend(format, askres, end) {
if (format === 'svg') {
return res => sendSVG(res, askres, end)
} else if (format === 'json') {
return res => sendJSON(res, askres, end)
} else {
return res => sendOther(format, res, askres, end)
}
}

module.exports = {
makeSend,
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 8 additions & 2 deletions core/server/server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

const fs = require('fs')
const bytes = require('bytes')
const path = require('path')
const url = require('url')
Expand All @@ -25,6 +26,11 @@ const PrometheusMetrics = require('./prometheus-metrics')
const optionalUrl = Joi.string().uri({ scheme: ['http', 'https'] })
const requiredUrl = optionalUrl.required()

const notFound = fs.readFileSync(
path.resolve(__dirname, 'error-pages', '404.html'),
'utf-8'
)

const publicConfigSchema = Joi.object({
bind: {
port: Joi.number().port(),
Expand Down Expand Up @@ -172,7 +178,7 @@ module.exports = class Server {
})

camp.notfound(/.*/, (query, match, end, request) => {
end(null, { template: '404.html' })
end(notFound)
})
}

Expand Down Expand Up @@ -238,7 +244,7 @@ module.exports = class Server {
log(`Server is starting up: ${this.baseUrl}`)

const camp = (this.camp = Camp.start({
documentRoot: path.join(__dirname, '..', '..', 'public'),
documentRoot: path.resolve(__dirname, '..', '..', 'public'),
port,
hostname,
secure,
Expand Down
2 changes: 1 addition & 1 deletion core/server/server.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe('The server', function() {

context('with svg2img error', function() {
const expectedError = fs.readFileSync(
path.resolve(__dirname, '..', '..', 'public', '500.html')
path.resolve(__dirname, 'error-pages', '500.html')
)

let toBufferStub
Expand Down
3 changes: 1 addition & 2 deletions dangerfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ const packageJson = fileMatch('package.json')
const packageLock = fileMatch('package-lock.json')
const secretsDocs = fileMatch('doc/server-secrets.md')
const capitals = fileMatch('**/*[A-Z]*.js')
// _document.js is used by convention by Next.
const underscores = fileMatch('**/*_*.js', '!pages/_document.js')
const underscores = fileMatch('**/*_*.js')
const targetBranch = danger.github.pr.base.ref

message(
Expand Down
4 changes: 2 additions & 2 deletions doc/self-hosting.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ These are documented in [server-secrets.md](./server-secrets.md)
If you want to host the frontend on a separate server, such as cloud storage
or a CDN, you can do that.

First, build the frontend, pointing `BASE_URL` to your server.
First, build the frontend, pointing `GATSBY_BASE_URL` to your server.

```sh
BASE_URL=https://your-server.example.com npm run build
GATSBY_BASE_URL=https://your-server.example.com npm run build
```

Then copy the contents of the `build/` folder to your static hosting / CDN.
Expand Down
8 changes: 3 additions & 5 deletions frontend/components/category-headings.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'
import { Link, NavLink } from 'react-router-dom'
import { Link } from 'gatsby'
import { H3 } from './common'

const CategoryHeading = ({ category }) => {
const { id, name } = category

return (
<Link to={`/examples/${id}`}>
<Link to={`/category/${id}`}>
<H3 id={id}>{name}</H3>
</Link>
)
Expand Down Expand Up @@ -67,9 +67,7 @@ const CategoryNav = ({ categories }) => (
<ul>
{categories.map(({ id, name }) => (
<li key={id}>
<NavLink to={`/examples/${id}`} activeClassName="active">
{name}
</NavLink>
<Link to={`/category/${id}`}>{name}</Link>
</li>
))}
</ul>
Expand Down
32 changes: 14 additions & 18 deletions frontend/components/donate.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import React from 'react'
import styled from 'styled-components'

export default class DonateBox extends React.Component {
render() {
return (
<div>
<div id="donate">
Love Shields? Please consider{' '}
<a href="https://opencollective.com/shields">donating</a> to sustain
our activities
</div>
<style jsx>{`
#donate {
padding: 25px 50px;
}
`}</style>
</div>
)
}
}
const Donate = styled.div`
padding: 25px 50px;
`

const DonateBox = () => (
<Donate>
Love Shields? Please consider{' '}
<a href="https://opencollective.com/shields">donating</a> to sustain our
activities
</Donate>
)

export default DonateBox
5 changes: 3 additions & 2 deletions frontend/components/header.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Link } from 'react-router-dom'
import { Link } from 'gatsby'
import React from 'react'
import styled from 'styled-components'
import { VerticalSpace } from './common'
import Logo from '../images/logo.svg'

const Highlights = styled.p`
font-style: italic;
Expand All @@ -10,7 +11,7 @@ const Highlights = styled.p`
export default () => (
<section>
<Link to="/">
<img alt="Shields.io" src="/static/logo.svg" />
<Logo />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we lose the alt text with this, or is there some Gatsby magic (or is it baked into the svg already)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure! You could check the staging app. This is getting handled by babel-plugin-inline-react-svg, which I imagine has a way to provide alt text.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is, but I don't think it matters all that much

</Link>

<VerticalSpace />
Expand Down
27 changes: 12 additions & 15 deletions frontend/components/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ export default class Main extends React.Component {
}

static propTypes = {
match: PropTypes.object.isRequired,
}

get category() {
return this.props.match.params.category
// `pageContext` is the `context` passed to `createPage()` in
// `gatsby-node.js`. In the case of the index page, `pageContext` is empty.
pageContext: {
category: PropTypes.shape({
id: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
}),
}.isRequired,
}

performSearch(query) {
Expand Down Expand Up @@ -114,11 +117,11 @@ export default class Main extends React.Component {
}

renderMain() {
const { category: categoryId } = this
const {
pageContext: { category },
} = this.props
const { isSearchInProgress, isQueryTooShort, searchResults } = this.state

const category = findCategory(categoryId)

if (isSearchInProgress) {
return <div>searching...</div>
} else if (isQueryTooShort) {
Expand All @@ -129,7 +132,7 @@ export default class Main extends React.Component {
)
} else if (category) {
const definitions = ServiceDefinitionSetHelper.create(
getDefinitionsForCategory(categoryId)
getDefinitionsForCategory(category.id)
)
.notDeprecated()
.toArray()
Expand All @@ -139,12 +142,6 @@ export default class Main extends React.Component {
{this.renderCategory(category, definitions)}
</div>
)
} else if (categoryId) {
return (
<div>
Unknown category <b>{categoryId}</b>
</div>
)
} else {
return <CategoryHeadings categories={categories} />
}
Expand Down
Loading