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

Desktop bootstrapping #31

Merged
merged 11 commits into from
Jul 24, 2019
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
21 changes: 21 additions & 0 deletions src/desktop/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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*
*/.env*

npm-debug.log*
yarn-debug.log*
yarn-error.log*
6 changes: 6 additions & 0 deletions src/desktop/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Installation instructions
=========================
You need to create a file `.env` or `.env.development` with the following variables:
```
REACT_APP_SENTRY_DSN=your_sentry_dsn
```
3 changes: 3 additions & 0 deletions src/desktop/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"baseUrl": "http://localhost:3000"
}
5 changes: 5 additions & 0 deletions src/desktop/cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
5 changes: 5 additions & 0 deletions src/desktop/cypress/integration/homepage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('Homepage', function() {
it('Can visit the page', function() {
cy.visit('/')
})
})
17 changes: 17 additions & 0 deletions src/desktop/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
25 changes: 25 additions & 0 deletions src/desktop/cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This is will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions src/desktop/cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
78 changes: 78 additions & 0 deletions src/desktop/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"name": "bitsky",
"author": "Jason Van Malder, Sylvain Urbain",
"appId": "be.bitsky.desktop",
"main": "public/electron.js",
"homepage": "./",
"private": true,
"dependencies": {
"@material-ui/core": "^4.2.1",
"@sentry/browser": "^5.5.0",
"@types/node": "^12.6.8",
"@types/react": "^16.8.23",
"@types/react-dom": "^16.8.4",
"@types/react-router-dom": "^4.3.4",
"@types/styled-components": "^4.1.18",
"@types/styled-theming": "^2.2.2",
"cross-env": "^5.2.0",
"electron-is-dev": "^1.1.0",
"final-form": "^4.18.2",
"i18next": "^17.0.6",
"i18next-xhr-backend": "^3.0.0",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-final-form": "^6.3.0",
"react-i18next": "^10.11.4",
"react-pose": "^4.0.8",
"react-redux": "^7.1.0",
"react-router-dom": "^5.0.1",
"react-scripts": "3.0.1",
"redux": "^4.0.4",
"styled-components": "^4.3.2",
"styled-theming": "^2.2.0",
"typescript": "^3.5.3"
},
"scripts": {
"react-start": "react-scripts start",
"react-build": "react-scripts build",
"react-test": "react-scripts test",
"react-eject": "react-scripts eject",
"cypress-test": "./node_modules/.bin/cypress open",
"electron-build": "electron-builder",
"electron-start": "electron .",
"release": "yarn react-build && electron-builder --publish=always",
"build": "yarn react-build && yarn electron-build",
"start": "concurrently \"cross-env BROWSER=none yarn react-start\" \"wait-on http://localhost:3000 && yarn electron-start\""
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@types/enzyme": "^3.10.3",
"@types/enzyme-adapter-react-16": "^1.0.5",
"@types/jest": "^24.0.15",
"concurrently": "^4.1.1",
"cypress": "^3.4.0",
"electron": "^5.0.7",
"electron-builder": "^21.1.1",
"enzyme": "^3.10.0",
"enzyme-adapter-react-16": "^1.14.0",
"react-test-renderer": "^16.8.6",
"tslint": "^5.18.0",
"tslint-react": "^4.0.0",
"wait-on": "^3.3.0"
}
}
36 changes: 36 additions & 0 deletions src/desktop/public/electron.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const electron = require('electron')
const app = electron.app
const BrowserWindow = electron.BrowserWindow

const path = require('path')
const isDev = require('electron-is-dev')

let mainWindow

createWindow = async () => {
mainWindow = new BrowserWindow({ width: 900, height: 680 })

await mainWindow.loadURL(
isDev
? 'http://localhost:3000'
: `file://${path.join(__dirname, '../build/index.html')}`
)

mainWindow.on('closed', () => (mainWindow = null))
}

app.on('ready', async () => {
await createWindow()
})

app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})

app.on('activate', async () => {
if (mainWindow === null) {
await createWindow()
}
})
Binary file added src/desktop/public/favicon.ico
Binary file not shown.
39 changes: 39 additions & 0 deletions src/desktop/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" />
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Bitsky</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
3 changes: 3 additions & 0 deletions src/desktop/public/locales/en/translation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"app.test": "Hello"
}
3 changes: 3 additions & 0 deletions src/desktop/public/locales/fr/translation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"app.test": "Bonjour"
}
15 changes: 15 additions & 0 deletions src/desktop/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "Bitsky",
"name": "Bitsky Desktop",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
9 changes: 9 additions & 0 deletions src/desktop/src/Router.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react'
import {TestScreen} from './screens/TestScreen'
import {BrowserRouter, Route} from 'react-router-dom'

export const Router = () => (
<BrowserRouter>
<Route exact path='/' component={TestScreen} />
</BrowserRouter>
)
21 changes: 21 additions & 0 deletions src/desktop/src/__tests__/screens/TestScreen.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react'
import {shallow, ShallowWrapper} from 'enzyme'
import {TestScreen} from '../../screens/TestScreen'

it('renders without crashing', (): void => {
shallow(<TestScreen/>)
})

it('increase the counter when the button is clicked', (): void => {
const screen = shallow(<TestScreen/>)
const button = (): ShallowWrapper => screen.find('[data-testid="counterButton"]')
const title = (): string => screen.find('h1').text()

button().simulate('click')
expect(title()).toContain('1')
expect(title()).toContain('time')

button().simulate('click')
expect(title()).toContain('2')
expect(title()).toContain('times')
})
15 changes: 15 additions & 0 deletions src/desktop/src/constants/colors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {IStringTMap} from '../interfaces/generics'
import theme, { ThemeSet } from 'styled-theming'

/*
Colors used with styled components
*/
export const colors: IStringTMap<ThemeSet> = {
gradientBlue: theme('mode', {
classic: '#6CC1FF',
}),

gradientPink: theme('mode', {
classic: '#FF80FA',
}),
}
45 changes: 45 additions & 0 deletions src/desktop/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React, {Fragment, Suspense} from 'react'
import ReactDOM from 'react-dom'
import {unregister} from './serviceWorker'
import * as Sentry from '@sentry/browser'
import {Router} from './Router'
import i18n from 'i18next'
import backend from 'i18next-xhr-backend'
import {initReactI18next} from 'react-i18next'
import {ThemeProvider} from 'styled-components'
import { StylesProvider } from '@material-ui/styles'

// Initiating Sentry, this tool is used for error catching
Sentry.init({dsn: process.env.REACT_APP_SENTRY_DSN})

// Initiating I18n for translation
i18n
// load locales files in public/locales
.use(backend)
.use(initReactI18next)
.init({
lng: 'en',
keySeparator: false,
interpolation: {
escapeValue: false,
},
})

// TODO: Maybe change Suspense fallback props into a beautiful loading screen
const App = (): JSX.Element => (
<Suspense fallback={<Fragment />}>
<ThemeProvider theme={{mode: 'classic'}}>
<StylesProvider injectFirst>
<Router />
</StylesProvider>
</ThemeProvider>
</Suspense>
)

// Rendering the app
ReactDOM.render(
<App />,
document.getElementById('root'),
)

unregister()
7 changes: 7 additions & 0 deletions src/desktop/src/interfaces/generics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
File containing generics typescript interface for type checking
*/

export interface IStringTMap<T> {
[key: string]: T
}
1 change: 1 addition & 0 deletions src/desktop/src/react-app-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="react-scripts" />