Skip to content

Commit 443b80a

Browse files
feat(website): add versions
1 parent 02700fd commit 443b80a

File tree

10 files changed

+73
-8
lines changed

10 files changed

+73
-8
lines changed

package-lock.json

Lines changed: 11 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@babel/plugin-transform-runtime": "^7.2.0",
2828
"@babel/preset-env": "^7.2.0",
2929
"@types/node": "10.5.1",
30+
"axios": "^0.18.0",
3031
"color": "3.0.0",
3132
"color-hash": "1.0.3",
3233
"electron": "2.0.8",

packages/overmind-website/backend/index.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const path = require('path')
22
const express = require('express')
33
const https = require('https')
4+
const axios = require('axios')
45
const app = express()
56
const fs = require('fs')
67
const api = require('./api')
@@ -96,10 +97,27 @@ function getSearchData() {
9697
)
9798
}
9899

100+
function getVersion(name) {
101+
return axios.get('http://registry.npmjs.org/' + name).then((response) => ({
102+
name,
103+
version: response.data['dist-tags'].latest,
104+
}))
105+
}
106+
107+
function getVersions() {
108+
return Promise.all([
109+
getVersion('overmind'),
110+
getVersion('overmind-angular'),
111+
getVersion('overmind-vue'),
112+
getVersion('overmind-react'),
113+
])
114+
}
115+
99116
const guides = getGuides()
100117
const videos = getVideos()
101118
const demos = getDemos()
102119
const apis = getApis()
120+
const versions = getVersions()
103121

104122
const searchData = getSearchData()
105123

@@ -143,6 +161,17 @@ app.use(googleCrawlMiddleware)
143161
app.use(express.static(path.join(__dirname, '..', 'dist')))
144162
app.use('/images', express.static(path.join(__dirname, '..', 'images')))
145163
app.get('/workshop/posts', api.posts)
164+
app.get('/backend/versions', (_, res) => {
165+
versions.then((fetchedVersions) => {
166+
res.send(
167+
fetchedVersions.reduce(
168+
(aggr, version) =>
169+
Object.assign(aggr, { [version.name]: version.version }),
170+
{}
171+
)
172+
)
173+
})
174+
})
146175
app.get('/backend/guides', (_, res) =>
147176
res.send(IS_PRODUCTION ? guides : getGuides())
148177
)

packages/overmind-website/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"demo"
3535
],
3636
"dependencies": {
37+
"axios": "^0.18.0",
3738
"@types/node": "^10.5.1",
3839
"emotion": "^9.2.12",
3940
"express": "^4.16.3",

packages/overmind-website/src/components/TopBar/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ const TopBar: SFC = () => {
1616

1717
return (
1818
<div ref={mainRef} className={styles.wrapper}>
19+
<div className={styles.version}>
20+
v{state.versions['overmind']}{' '}
21+
<a href="https://github.com/cerebral/overmind/releases" target="_new">
22+
release notes
23+
</a>
24+
</div>
1925
<a
2026
href="/"
2127
className={css(

packages/overmind-website/src/components/TopBar/styles.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
import { css } from 'emotion'
22

3+
export const version = css`
4+
width: 150px;
5+
color: var(--color-black-1);
6+
a {
7+
text-decoration: none;
8+
color: var(--color-primary);
9+
font-weight: bold;
10+
font-size: 12px;
11+
}
12+
`
13+
314
export const wrapper = css`
415
position: fixed;
516
z-index: 2;

packages/overmind-website/src/components/ViewSelector/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,31 @@ const ViewSelector: SFC = () => {
3333
<div className={styles.viewOption}>
3434
<img src={VueImage} width={25} />
3535
Vue
36+
<small>{state.versions['overmind-vue']}</small>
3637
<img className={styles.image} src={JsImage} width="20" height="20" />
3738
</div>
3839
),
3940
react: (
4041
<div className={styles.viewOption}>
4142
<img src={ReactImage} width={25} />
4243
React
44+
<small>{state.versions['overmind-react']}</small>
4345
<img className={styles.image} src={JsImage} width="20" height="20" />
4446
</div>
4547
),
4648
react_ts: (
4749
<div className={styles.viewOption}>
4850
<img src={ReactImage} width={25} />
4951
React
52+
<small>{state.versions['overmind-react']}</small>
5053
<img className={styles.image} src={TsImage} width="20" height="20" />
5154
</div>
5255
),
5356
angular_ts: (
5457
<div className={styles.viewOption}>
5558
<img src={AngularImage} width={25} />
5659
Angular
60+
<small>{state.versions['overmind-angular']}</small>
5761
<img className={styles.image} src={TsImage} width="20" height="20" />
5862
</div>
5963
),

packages/overmind-website/src/components/ViewSelector/styles.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ export const viewOption = css`
1111
display: flex;
1212
align-items: center;
1313
width: 100%;
14-
img:last-child {
14+
small {
1515
margin-left: auto;
16+
margin-right: 0.5rem;
17+
color: #cacaca;
1618
}
1719
`
1820

packages/overmind-website/src/overmind/onInitialize.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { OnInitialize } from 'overmind'
22

3-
const onInitialize: OnInitialize = ({ effects, state }, app) => {
3+
const onInitialize: OnInitialize = async ({ effects, state }, app) => {
44
state.showViewHelp = !effects.storage.get('theme')
55

66
effects.router.route('/', app.actions.openHome)
@@ -12,6 +12,8 @@ const onInitialize: OnInitialize = ({ effects, state }, app) => {
1212
effects.router.redirect('/api', '/api/action')
1313

1414
effects.router.start()
15+
16+
state.versions = await effects.request('/backend/versions')
1517
}
1618

1719
export default onInitialize

packages/overmind-website/src/overmind/state.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ type State = {
2828
isLoadingApis: boolean
2929
isLoadingVideos: boolean
3030
showViewHelp: boolean
31+
versions: {
32+
[name: string]: string
33+
}
3134
}
3235

3336
const state: State = {
@@ -50,6 +53,7 @@ const state: State = {
5053
isLoadingApis: false,
5154
isLoadingVideos: false,
5255
showViewHelp: false,
56+
versions: {},
5357
}
5458

5559
export default state

0 commit comments

Comments
 (0)