Skip to content

Commit 5860b8f

Browse files
committed
Build with rollup, use prettier formatting
1 parent 7f1fb2c commit 5860b8f

15 files changed

+792
-1636
lines changed

.babelrc

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
{
2-
"presets": ["env", "react"]
2+
"env": {
3+
"commonjs": {
4+
"presets": [
5+
["env", { "loose": true }], "react"
6+
]
7+
},
8+
"es": {
9+
"presets": [
10+
["env", { "modules": false, "loose": true }], "react"
11+
]
12+
}
13+
}
314
}

.editorconfig

-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@ root = true
44
end_of_line = lf
55
insert_final_newline = true
66
trim_trailing_whitespace = true
7-
8-
[*.{js,json}]
97
indent_style = space
108
indent_size = 2

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ coverage
99
# production
1010
dist
1111
lib
12+
es
1213

1314
# misc
1415
.DS_Store
1516
*.log
1617
.vscode
17-
flow-typed

.travis.yml

+3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
language: node_js
2+
23
node_js:
34
- "node"
5+
46
script:
57
- yarn run test
68
- yarn run build
9+
710
branches:
811
only:
912
- master

example/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<head>
55
<script src="https://unpkg.com/react@15/dist/react.js"></script>
66
<script src="https://unpkg.com/react-dom@15/dist/react-dom.js"></script>
7+
<script src="https://unpkg.com/prop-types@15/prop-types.js"></script>
78

89
<script src="go-lib.js"></script>
910
</head>

flow-typed/go-lib.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @flow
2+
3+
declare module 'go-lib' {
4+
declare type Point = {
5+
x: number,
6+
y: number,
7+
}
8+
9+
declare type Move = {
10+
pos: Point,
11+
color: 'W' | 'B',
12+
}
13+
}

package.json

+28-16
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,63 @@
22
"name": "go-lib",
33
"version": "0.1.4",
44
"description": "A React Component that renders a GO Board",
5-
"main": "lib/index.js",
65
"author": "Alexander Lücking <[email protected]>",
6+
"browser": "dist/go-lib.js",
7+
"main": "lib/index.js",
8+
"module": "es/index.js",
9+
"jsnext:main": "es/index.js",
710
"license": "MIT",
811
"files": [
12+
"dist",
913
"lib",
14+
"es",
1015
"src",
11-
"dist"
16+
"README.md",
17+
"LICENSE"
1218
],
1319
"repository": {
1420
"type": "git",
1521
"url": "https://github.com/beldur/go-lib.git"
1622
},
1723
"scripts": {
18-
"clean": "rimraf lib dist",
19-
"build:commonjs": "babel src --out-dir lib --ignore *.test.js",
20-
"build:umd": "webpack",
21-
"build:umd:min": "cross-env NODE_ENV=production webpack -p",
22-
"build": "npm run build:commonjs && npm run build:umd && npm run build:umd:min",
23-
"prepublish": "npm run clean && npm run build",
24+
"clean": "rimraf lib dist es",
25+
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib --ignore *.test.js",
26+
"build:es": "cross-env BABEL_ENV=es babel src --out-dir es --ignore *.test.js",
27+
"build:umd": "cross-env BABEL_ENV=es NODE_ENV=development rollup -c -i src/index.js -o dist/go-lib.js",
28+
"build:umd:min": "cross-env BABEL_ENV=es NODE_ENV=production rollup -c -i src/index.js -o dist/go-lib.min.js",
29+
"build": "yarn run build:commonjs && yarn run build:es && yarn run build:umd && yarn run build:umd:min",
30+
"prepublish": "yarn run clean && yarn run build",
2431
"test": "jest",
2532
"test:watch": "jest --watch",
2633
"test:coverage": "jest --coverage",
27-
"example": "webpack-dev-server --progress --content-base example"
34+
"example": "cross-env BABEL_ENV=es NODE_ENV=serve rollup -c -w -i src/index.js -o dist/go-lib.js"
2835
},
2936
"jest": {
3037
"verbose": true
3138
},
3239
"devDependencies": {
3340
"babel-cli": "^6.23.0",
34-
"babel-loader": "^6.3.2",
41+
"babel-plugin-external-helpers": "^6.22.0",
3542
"babel-preset-env": "^1.1.11",
3643
"babel-preset-react": "^6.23.0",
37-
"cross-env": "^3.1.4",
44+
"cross-env": "^4.0.0",
3845
"enzyme": "^2.7.1",
3946
"jest": "^19.0.2",
47+
"prop-types": "^15.5.8",
4048
"react": "^15.4.2",
4149
"react-addons-test-utils": "^15.4.2",
4250
"react-dom": "^15.4.2",
4351
"rimraf": "^2.6.1",
44-
"webpack": "^2.2.1",
45-
"webpack-dev-server": "^2.4.1"
52+
"rollup": "^0.41.6",
53+
"rollup-plugin-babel": "^2.7.1",
54+
"rollup-plugin-commonjs": "^8.0.2",
55+
"rollup-plugin-node-resolve": "^3.0.0",
56+
"rollup-plugin-serve": "^0.3.0",
57+
"rollup-plugin-uglify": "^1.0.2",
58+
"rollup-watch": "^3.2.2"
4659
},
47-
"dependencies": {},
4860
"peerDependencies": {
49-
"react": "^15.4.2",
50-
"react-dom": "^15.4.2"
61+
"prop-types": "^15.5.8",
62+
"react": "^15.4.2"
5163
}
5264
}

rollup.config.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import babel from 'rollup-plugin-babel'
2+
import nodeResolve from 'rollup-plugin-node-resolve'
3+
import commonjs from 'rollup-plugin-commonjs'
4+
import uglify from 'rollup-plugin-uglify'
5+
import serve from 'rollup-plugin-serve'
6+
7+
const env = process.env.NODE_ENV
8+
9+
const config = {
10+
format: 'umd',
11+
moduleName: 'GoLib',
12+
external: ['react', 'prop-types'],
13+
globals: {
14+
react: 'React',
15+
'prop-types': 'PropTypes',
16+
},
17+
plugins: [
18+
nodeResolve({
19+
jsnext: true,
20+
main: true,
21+
}),
22+
commonjs({
23+
include: 'node_modules/**',
24+
}),
25+
babel({
26+
exclude: 'node_modules/**',
27+
plugins: ['external-helpers'],
28+
}),
29+
],
30+
}
31+
32+
if (env === 'production') {
33+
config.plugins.push(uglify())
34+
}
35+
36+
if (env === 'serve') {
37+
config.plugins.push(serve(['example', 'dist']))
38+
}
39+
40+
export default config

src/board-drawer.js

+19-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @flow
22

3-
import type { Move, Point } from './types.js'
3+
import type { Move, Point } from 'go-lib'
44

55
const LINE_WIDTH_FACTOR = 20
66
const FONT_SIZE_FACTOR = 2.5
@@ -31,7 +31,7 @@ class BoardDrawer {
3131
const { boardSize, boxSize } = this
3232
const starPos = boardSize === 9 ? 3 : 4
3333
const single = starPos * boxSize
34-
const double = ((boardSize + 1) / 2) * boxSize
34+
const double = (boardSize + 1) / 2 * boxSize
3535
const triple = (boardSize + 1 - starPos) * boxSize
3636
const stars = [{ x: double, y: double }]
3737

@@ -79,18 +79,30 @@ class BoardDrawer {
7979
const isLastMove = index === moves.length - 1
8080

8181
// Draw stone
82-
ctx.fillStyle = (move.color === 'B') ? '#000' : '#FFF'
82+
ctx.fillStyle = move.color === 'B' ? '#000' : '#FFF'
8383
ctx.beginPath()
84-
ctx.arc(move.pos[0] * boxSize, move.pos[1] * boxSize, boxSize / 2, 0, 2 * Math.PI)
84+
ctx.arc(
85+
move.pos[0] * boxSize,
86+
move.pos[1] * boxSize,
87+
boxSize / 2,
88+
0,
89+
2 * Math.PI,
90+
)
8591
ctx.stroke()
8692
ctx.fill()
8793

8894
// Mark last move
8995
if (isLastMove) {
9096
ctx.beginPath()
91-
ctx.fillStyle = (move.color === 'B') ? '#FFF' : '#000'
97+
ctx.fillStyle = move.color === 'B' ? '#FFF' : '#000'
9298
ctx.lineWidth = lineWidth
93-
ctx.arc(move.pos[0] * boxSize, move.pos[1] * boxSize, boxSize / 3.5, 0, 2 * Math.PI)
99+
ctx.arc(
100+
move.pos[0] * boxSize,
101+
move.pos[1] * boxSize,
102+
boxSize / 3.5,
103+
0,
104+
2 * Math.PI,
105+
)
94106
ctx.stroke()
95107
}
96108
})
@@ -123,7 +135,7 @@ class BoardDrawer {
123135
ctx.beginPath()
124136
ctx.fillStyle = '#000'
125137

126-
stars.forEach((pos) => {
138+
stars.forEach(pos => {
127139
ctx.moveTo(pos.x, pos.y)
128140
ctx.arc(pos.x, pos.y, boxSize / STAR_POINT_SIZE_FACTOR, 0, 2 * Math.PI)
129141
})

src/board-drawer.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('BoardDrawer', () => {
4848

4949
it('should render correct amount of stones', () => {
5050
const drawer = new BoardDrawer(19, 100, 100)
51-
const moves = [
51+
const moves = [
5252
{ pos: [16, 4], color: 'B' },
5353
{ pos: [4, 16], color: 'W' },
5454
{ pos: [16, 17], color: 'B' },

src/board.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// @flow
22

3-
import type { Move } from './types.js'
4-
import React, { PropTypes } from 'react'
3+
import type { Move } from 'go-lib'
4+
import React from 'react'
5+
import PropTypes from 'prop-types'
56
import BoardDrawer from './board-drawer.js'
67

78
type BoardDefaultProps = {
@@ -16,7 +17,6 @@ type BoardProps = BoardDefaultProps & {
1617

1718
// Board draw's a Go Board
1819
class Board extends React.PureComponent<BoardDefaultProps, BoardProps, any> {
19-
2020
static defaultProps: BoardDefaultProps
2121

2222
props: BoardProps
@@ -54,19 +54,19 @@ class Board extends React.PureComponent<BoardDefaultProps, BoardProps, any> {
5454
}
5555

5656
render() {
57-
return (
58-
<canvas ref={c => this.canvas = c} />
59-
)
57+
return <canvas ref={c => (this.canvas = c)} />
6058
}
6159
}
6260

6361
Board.propTypes = {
6462
width: PropTypes.number.isRequired,
6563
height: PropTypes.number.isRequired,
6664
size: PropTypes.number,
67-
moves: PropTypes.arrayOf(PropTypes.shape({
68-
color: PropTypes.oneOf(['B', 'W']),
69-
})),
65+
moves: PropTypes.arrayOf(
66+
PropTypes.shape({
67+
color: PropTypes.oneOf(['B', 'W']),
68+
}),
69+
),
7070
}
7171

7272
Board.defaultProps = {

src/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
// @flow
2+
13
import Board from './board.js'
24

3-
export {
4-
Board
5-
}
5+
export { Board }

src/types.js

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
// @flow
22

3-
export type Point = {
4-
x: number,
5-
y: number,
6-
}
7-
8-
export type Move = {
9-
pos: Point,
10-
color: 'W' | 'B',
11-
}
3+
export type {
4+
Point,
5+
Move,
6+
} from 'go-lib'

webpack.config.js

-24
This file was deleted.

0 commit comments

Comments
 (0)