Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
migrate to create-react-app (#139)
Browse files Browse the repository at this point in the history
* migrate to create-react-app

* upd travis script

* revert as router

* fix ui tests

* ui as yarn cwd
  • Loading branch information
lanwen authored Feb 24, 2019
1 parent eac8bd6 commit a7a933e
Show file tree
Hide file tree
Showing 63 changed files with 11,417 additions and 6,078 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ node_modules
node
etc

bindata_assetfs.go
statik
selenoid-ui
data
coverage.txt
Expand Down
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
sudo: required
language: node_js
node_js:
- "7"
- "11"

services:
- docker

script:
- export GO111MODULE="on"
- go generate ./web ./...
- go generate ./ui ./...
- go test -race -v -coverprofile=coverage.txt -covermode=atomic ./...
- yarn --cwd ui test
- gox -os "linux darwin windows" -arch "amd64" -osarch="windows/386" -output "dist/{{.Dir}}_{{.OS}}_{{.Arch}}" -ldflags "-X main.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.gitRevision=`git describe --tags || git rev-parse HEAD`"
- GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-X main.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.gitRevision=`git describe --tags || git rev-parse HEAD`" # for docker

Expand All @@ -25,8 +26,7 @@ before_install:
- eval "$(curl -sL https://raw.githubusercontent.com/travis-ci/gimme/master/gimme | GIMME_GO_VERSION=1.11.x bash)"

install:
- go get -u github.com/jteeuwen/go-bindata/...
- go get -u github.com/elazarl/go-bindata-assetfs/...
- go get -u github.com/rakyll/statik
- go get -u github.com/mitchellh/gox # cross compile
- npm install cross-env

Expand Down Expand Up @@ -71,4 +71,4 @@ deploy:
cache:
yarn: true
directories:
- web/node_modules
- ui/node_modules
4 changes: 2 additions & 2 deletions docs/contributing.adoc
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
== Contributing & Development

1) Ensure you have https://github.com/yarnpkg/yarn[yarn] and https://github.com/elazarl/go-bindata-assetfs[go-bindata-assetfs] installed.
1) Ensure you have https://github.com/yarnpkg/yarn[yarn] and https://github.com/rakyll/statik[statik] installed.

2) Generate static resources:

[source,bash]
----
$ go generate ./web ./...
$ go generate ./ui ./...
----

3) Build (requires Golang 1.11 and above):
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/aerokube/selenoid-ui
require (
github.com/aandryashin/matchers v0.0.0-20161126170413-435295ea180e
github.com/aerokube/util v0.0.0-20181001032247-3a9b3f70da09
github.com/elazarl/go-bindata-assetfs v1.0.0
github.com/gorilla/websocket v1.4.0 // indirect
github.com/koding/websocketproxy v0.0.0-20180716164433-0fa3f994f6e7
github.com/rakyll/statik v0.1.5
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/koding/websocketproxy v0.0.0-20180716164433-0fa3f994f6e7 h1:UPc4az2SLy5Usu+JKfOV4KtfzuRQXXUxY6QOWf9QBJU=
github.com/koding/websocketproxy v0.0.0-20180716164433-0fa3f994f6e7/go.mod h1:Nn5wlyECw3iJrzi0AhIWg+AJUb4PlRQVW4/3XHH1LZA=
github.com/rakyll/statik v0.1.5 h1:Ly2UjURzxnsSYS0zI50fZ+srA+Fu7EbpV5hglvJvJG0=
github.com/rakyll/statik v0.1.5/go.mod h1:OEi9wJV/fMUAGx1eNjq75DKDsJVuEv1U0oYdX6GX8Zs=
12 changes: 9 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/aerokube/selenoid-ui/selenoid"
"github.com/aerokube/util/sse"
"github.com/koding/websocketproxy"
"github.com/rakyll/statik/fs"
"log"
"net/http"
"net/url"
Expand All @@ -16,9 +17,11 @@ import (
"strings"
"syscall"
"time"

_ "github.com/aerokube/selenoid-ui/statik"
)

//go:generate go-bindata-assetfs data/...
//go:generate statik -src=./ui/build

var (
listen string
Expand All @@ -36,9 +39,12 @@ var (

func mux(sse *sse.SseBroker) http.Handler {
mux := http.NewServeMux()
static := http.FileServer(assetFS())

mux.Handle("/", static)
if statik, err := fs.New(); err == nil {
static := http.FileServer(statik)
mux.Handle("/", static)
}

mux.Handle("/events", sse)

parsedUri, err := url.Parse(selenoidUri)
Expand Down
23 changes: 23 additions & 0 deletions ui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
68 changes: 68 additions & 0 deletions ui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.<br>
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.<br>
You will also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.<br>
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.<br>
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.<br>
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting

### Analyzing the Bundle Size

This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size

### Making a Progressive Web App

This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app

### Advanced Configuration

This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration

### Deployment

This section has moved here: https://facebook.github.io/create-react-app/docs/deployment

### `npm run build` fails to minify

This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
2 changes: 1 addition & 1 deletion web/main.go → ui/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package web
package ui

//go:generate yarn install
//go:generate yarn build
Expand Down
43 changes: 43 additions & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "ui",
"version": "0.1.0",
"private": true,
"dependencies": {
"@novnc/novnc": "^1.0.0",
"ansi-256-colors": "^1.1.0",
"event-source-polyfill": "^1.0.5",
"jsonschema": "^1.2.4",
"node-sass": "^4.11.0",
"react": "^16.8.2",
"react-dom": "^16.8.2",
"react-highlight": "^0.12.0",
"react-router-dom": "^4.3.1",
"react-scripts": "2.1.5",
"react-select": "^2.4.1",
"react-spinners": "^0.5.1",
"react-transition-group": "^2.5.3",
"rx-connect": "^0.7.0",
"rxjs": "^5.1.0",
"xterm": "^3.11.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --transformIgnorePatterns 'node_modules/(?!(@novnc|highlight.js|xterm)/)'",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"devDependencies": {
"eventsourcemock": "^2.0.0",
"http-proxy-middleware": "^0.19.1",
"mutationobserver-shim": "^0.3.3"
}
}
Binary file added ui/public/favicon.ico
Binary file not shown.
18 changes: 18 additions & 0 deletions ui/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<meta name="theme-color" content="#000000" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>Selenoid UI</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>
15 changes: 15 additions & 0 deletions ui/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "Selenoid UI",
"name": "Selenoid UI",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
13 changes: 13 additions & 0 deletions ui/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React, { Component } from 'react';

import Viewport from "./containers/Viewport";

class App extends Component {
render() {
return (
<Viewport/>
);
}
}

export default App;
9 changes: 9 additions & 0 deletions ui/src/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,7 @@ import {rxConnect} from "rx-connect";
import "./style.scss";
import Browser from "./Browser";

@rxConnect(props$ => {
return props$.map(({totalUsed, browsers}) => {
return {
totalUsed: totalUsed,
browsers: Object.keys(browsers)
.sort((a, b) => browsers[b] - browsers[a])
.map(browser => ({
name: browser,
used: browsers[browser]
}))
};
});
})
export default class Browsers extends Component {
class Browsers extends Component {
render() {
const {browsers, totalUsed} = this.props;

Expand All @@ -31,3 +18,17 @@ export default class Browsers extends Component {
);
}
}

export default rxConnect(props$ => {
return props$.map(({totalUsed, browsers}) => {
return {
totalUsed: totalUsed,
browsers: Object.keys(browsers)
.sort((a, b) => browsers[b] - browsers[a])
.map(browser => ({
name: browser,
used: browsers[browser]
}))
};
});
})(Browsers)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit a7a933e

Please sign in to comment.