Skip to content

Commit d802f1a

Browse files
authored
Add tests and bundle with Rollup (michalochman#40)
* Add tests and bundle with Rollup
1 parent 13d4819 commit d802f1a

33 files changed

+3612
-621
lines changed

.babelrc

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,37 @@
11
{
22
"env": {
33
"production": {
4-
"plugins": [
5-
"transform-object-rest-spread",
6-
"transform-react-jsx",
7-
"transform-es2015-modules-commonjs",
8-
],
4+
"plugins": ["external-helpers", "transform-object-rest-spread", "transform-react-jsx"],
95
"presets": [
10-
["env", {
11-
"targets": {
12-
"browsers": [
13-
"last 2 versions"
14-
]
15-
},
16-
"modules": false,
17-
"useBuiltIns": true
18-
}]
6+
[
7+
"env",
8+
{
9+
"targets": {
10+
"browsers": ["last 2 versions"]
11+
},
12+
"modules": false,
13+
"useBuiltIns": true
14+
}
15+
]
1916
]
2017
},
2118
"development": {
22-
"plugins": [
23-
"transform-object-rest-spread",
24-
"transform-react-jsx",
25-
"transform-es2015-modules-commonjs"
26-
],
19+
"plugins": ["external-helpers", "transform-object-rest-spread", "transform-react-jsx"],
2720
"presets": [
28-
["env", {
29-
"targets": {
30-
"browsers": [
31-
"last 2 versions"
32-
]
33-
},
34-
"modules": false,
35-
"useBuiltIns": true
36-
}]
21+
[
22+
"env",
23+
{
24+
"targets": {
25+
"browsers": ["last 2 versions"]
26+
},
27+
"modules": false,
28+
"useBuiltIns": true
29+
}
30+
]
3731
]
3832
},
3933
"test": {
40-
"plugins": [
41-
"transform-object-rest-spread",
42-
"transform-react-jsx",
43-
"transform-es2015-modules-commonjs"
44-
]
34+
"plugins": ["transform-object-rest-spread", "transform-react-jsx", "transform-es2015-modules-commonjs"]
4535
}
4636
}
4737
}

.circleci/config.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
version: 2
2+
jobs:
3+
build:
4+
docker:
5+
- image: circleci/node:8.9
6+
7+
working_directory: ~/react-pixi-fiber
8+
9+
steps:
10+
- checkout
11+
12+
# Download and cache dependencies
13+
- restore_cache:
14+
keys:
15+
- npm-dependencies-{{ checksum "package.json" }}
16+
# fallback to using the latest cache if no exact match is found
17+
- npm-dependencies-
18+
19+
- run: yarn install
20+
21+
# Cache dependencies
22+
- save_cache:
23+
paths:
24+
- node_modules
25+
key: npm-dependencies-{{ checksum "package.json" }}
26+
27+
# run tests
28+
- run: yarn test --coverage --ci --silent
29+
30+
# upload coverage report
31+
- run: yarn codecov

.eslintrc.json

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
{
2-
"extends": [
3-
"plugin:react/recommended",
4-
"prettier",
5-
"prettier/react"
6-
],
7-
"plugins": [
8-
"react",
9-
"prettier"
10-
],
2+
"extends": ["plugin:react/recommended", "prettier", "prettier/react"],
3+
"plugins": ["react", "prettier"],
114
"parser": "babel-eslint",
125
"parserOptions": {
136
"sourceType": "module",
@@ -22,5 +15,8 @@
2215
},
2316
"rules": {
2417
"prettier/prettier": "error"
18+
},
19+
"globals": {
20+
"__DEV__": false
2521
}
2622
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ chrome-user-data
1313
.vscode
1414
*.swp
1515
*.swo
16+
.envrc

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88

99
## [Unreleased]
1010

11+
### Added
12+
- Added unit tests ([#6])
13+
14+
### Changed
15+
- Changed bundler from babel-cli to Rollup
16+
1117

1218
## [0.4.0] - 2018-02-28
1319

@@ -124,5 +130,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
124130
[#15]: https://github.com/michalochman/react-pixi-fiber/issues/15
125131
[#9]: https://github.com/michalochman/react-pixi-fiber/issues/9
126132
[#8]: https://github.com/michalochman/react-pixi-fiber/issues/8
133+
[#6]: https://github.com/michalochman/react-pixi-fiber/issues/6
127134
[#4]: https://github.com/michalochman/react-pixi-fiber/issues/4
128135
[#2]: https://github.com/michalochman/react-pixi-fiber/issues/2

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
# ReactPixiFiber – React Fiber renderer for PixiJS
1+
# ReactPixiFiber – React Fiber renderer for PixiJS
2+
[![npm](https://img.shields.io/npm/v/react-pixi-fiber.svg)](https://npmjs.com/package/react-pixi-fiber)
3+
[![npm](https://img.shields.io/github/license/michalochman/react-pixi-fiber.svg)](https://github.com/michalochman/react-pixi-fiber/blob/master/LICENSE)
4+
[![CircleCI](https://img.shields.io/circleci/project/github/michalochman/react-pixi-fiber/master.svg)](https://circleci.com/gh/michalochman/react-pixi-fiber/tree/master)
5+
[![codecov](https://img.shields.io/codecov/c/github/michalochman/react-pixi-fiber/master.svg)](https://codecov.io/gh/michalochman/react-pixi-fiber/branch/master)
6+
[![gitter](https://img.shields.io/gitter/room/react-pixi-fiber/Lobby.svg)](https://gitter.im/react-pixi-fiber/Lobby)
27

38
ReactPixiFiber is a JavaScript library for writing PixiJS applications using React declarative style in React 16.
49

@@ -233,7 +238,7 @@ import { render } from "react-pixi-fiber";
233238
import * as PIXI from "pixi.js";
234239
import Rectangle from "./components/Rectangle"
235240

236-
// Setup PIXI.js Application
241+
// Setup PixiJS Application
237242
const canvasElement = document.getElementById("container")
238243
const app = new PIXI.Application(800, 600, {
239244
view: canvasElement

config/rollup.alias.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import json from "rollup-plugin-json";
2+
const babel = require("rollup-plugin-babel");
3+
const commonjs = require("rollup-plugin-commonjs");
4+
const globals = require("rollup-plugin-node-globals");
5+
const replace = require("rollup-plugin-replace");
6+
const resolve = require("rollup-plugin-node-resolve");
7+
const uglify = require("rollup-plugin-uglify");
8+
9+
const NODE_ENV = process.env.NODE_ENV || "production";
10+
const isProduction = NODE_ENV === "production";
11+
12+
const outputFile = isProduction ? "cjs/react-pixi-alias.production.min.js" : "cjs/react-pixi-alias.development.js";
13+
14+
const plugins = [
15+
json({
16+
preferConst: true,
17+
indent: " ",
18+
}),
19+
resolve({
20+
browser: true,
21+
jsnext: true,
22+
main: true,
23+
}),
24+
babel({
25+
exclude: "node_modules/**",
26+
}),
27+
replace({
28+
__DEV__: isProduction ? "false" : "true",
29+
"process.env.NODE_ENV": isProduction ? "'production'" : "'development'",
30+
}),
31+
commonjs({
32+
ignoreGlobal: false,
33+
include: [
34+
"node_modules/fbjs/**",
35+
"node_modules/object-assign/**",
36+
"node_modules/performance-now/**",
37+
"node_modules/prop-types/**",
38+
"node_modules/react/**",
39+
"node_modules/react-dom/**",
40+
"node_modules/react-reconciler/**",
41+
],
42+
}),
43+
globals(),
44+
isProduction && uglify(),
45+
];
46+
47+
module.exports = {
48+
input: "src/react-pixi-alias/index.js",
49+
output: {
50+
file: outputFile,
51+
name: "ReactPixiFiber",
52+
exports: "named",
53+
format: "cjs",
54+
},
55+
plugins: plugins,
56+
external: ["pixi.js", "react", "react-dom", "react-pixi-fiber"],
57+
};

config/rollup.index.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import json from "rollup-plugin-json";
2+
const babel = require("rollup-plugin-babel");
3+
const commonjs = require("rollup-plugin-commonjs");
4+
const globals = require("rollup-plugin-node-globals");
5+
const replace = require("rollup-plugin-replace");
6+
const resolve = require("rollup-plugin-node-resolve");
7+
const uglify = require("rollup-plugin-uglify");
8+
9+
const NODE_ENV = process.env.NODE_ENV || "production";
10+
const isProduction = NODE_ENV === "production";
11+
12+
const outputFile = isProduction ? "cjs/react-pixi-fiber.production.min.js" : "cjs/react-pixi-fiber.development.js";
13+
14+
const plugins = [
15+
json({
16+
preferConst: true,
17+
indent: " ",
18+
}),
19+
resolve({
20+
browser: true,
21+
jsnext: true,
22+
main: true,
23+
}),
24+
babel({
25+
exclude: "node_modules/**",
26+
}),
27+
replace({
28+
__DEV__: isProduction ? "false" : "true",
29+
"process.env.NODE_ENV": isProduction ? "'production'" : "'development'",
30+
}),
31+
commonjs({
32+
ignoreGlobal: false,
33+
include: [
34+
"node_modules/fbjs/**",
35+
"node_modules/object-assign/**",
36+
"node_modules/performance-now/**",
37+
"node_modules/prop-types/**",
38+
"node_modules/react/**",
39+
"node_modules/react-dom/**",
40+
"node_modules/react-reconciler/**",
41+
],
42+
}),
43+
globals(),
44+
isProduction && uglify(),
45+
];
46+
47+
module.exports = {
48+
input: "src/index.js",
49+
output: {
50+
file: outputFile,
51+
name: "ReactPixiFiber",
52+
exports: "named",
53+
format: "cjs",
54+
},
55+
plugins: plugins,
56+
external: ["pixi.js", "react", "react-dom"],
57+
};

examples/src/AnimatedExample/AnimatedSprite.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Stage, Sprite } from "react-pixi-fiber";
1+
import { Sprite } from "react-pixi-fiber";
22
import Animated from "animated";
33

44
const AnimatedSprite = Animated.createAnimatedComponent(Sprite);

package.json

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
{
22
"name": "react-pixi-fiber",
33
"version": "0.4.0",
4-
"description": "React Fiber renderer for PIXI.js",
4+
"description": "React Fiber renderer for PixiJS",
55
"main": "index.js",
66
"author": "Michal Ochman",
77
"license": "MIT",
88
"repository": "github:michalochman/react-pixi-fiber",
99
"typings": "./index.d.ts",
10-
"files": [
11-
"LICENSE",
12-
"README.md",
13-
"index.d.ts",
14-
"index.js",
15-
"react-pixi-alias.js",
16-
"cjs/",
17-
"src/"
18-
],
10+
"files": ["LICENSE", "README.md", "index.d.ts", "index.js", "react-pixi-alias.js", "cjs/", "src/"],
1911
"dependencies": {
2012
"fbjs": "^0.8.0",
2113
"performance-now": "^2.1.0",
@@ -29,30 +21,59 @@
2921
"devDependencies": {
3022
"@types/pixi.js": "^4.4.0",
3123
"@types/react": "^16.0.0",
32-
"babel-cli": "^6.26.0",
24+
"babel-core": "^6.26.0",
3325
"babel-eslint": "^8.2.1",
26+
"babel-jest": "^22.4.1",
27+
"babel-plugin-external-helpers": "^6.22.0",
3428
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
3529
"babel-plugin-transform-object-rest-spread": "^6.26.0",
3630
"babel-plugin-transform-react-jsx": "^6.24.1",
3731
"babel-preset-env": "^1.6.1",
32+
"canvas-prebuilt": "^1.6.5-prerelease.1",
33+
"codecov": "^3.0.0",
3834
"eslint": "^4.17.0",
39-
"eslint-config-fbjs": "^2.0.1",
4035
"eslint-config-prettier": "^2.9.0",
4136
"eslint-plugin-babel": "^4.1.0",
4237
"eslint-plugin-import": "^2.8.0",
4338
"eslint-plugin-prettier": "^2.6.0",
4439
"eslint-plugin-promise": "^3.6.0",
4540
"eslint-plugin-react": "^7.6.1",
46-
"prettier": "^1.9.2"
41+
"jest": "^22.4.2",
42+
"pixi.js": "^4.4.0",
43+
"prettier": "^1.9.2",
44+
"react": "^16.0.0",
45+
"react-dom": "^16.0.0",
46+
"react-test-renderer": "^16.0.0",
47+
"rollup": "^0.56.3",
48+
"rollup-plugin-babel": "^3.0.3",
49+
"rollup-plugin-commonjs": "^8.3.0",
50+
"rollup-plugin-json": "^2.3.0",
51+
"rollup-plugin-node-globals": "^1.1.0",
52+
"rollup-plugin-node-resolve": "^3.0.3",
53+
"rollup-plugin-replace": "^2.0.0",
54+
"rollup-plugin-uglify": "^3.0.0"
4755
},
4856
"scripts": {
49-
"prebuild": "mkdir -p cjs",
50-
"build": "npm run build:dev && npm run build:alias",
51-
"build:alias": "babel src/react-pixi-alias/index.js -o cjs/react-pixi-alias.development.js",
52-
"build:dev": "babel src/ReactPixiFiber.js -o cjs/react-pixi-fiber.development.js",
57+
"build": "npm run build:prod && npm run build:dev",
58+
"build:dev": "npm run build:index:dev && npm run build:alias:dev",
59+
"build:prod": "npm run build:index:prod && npm run build:alias:prod",
60+
"build:alias:dev": "NODE_ENV=development rollup -c config/rollup.alias.js",
61+
"build:alias:prod": "rollup -c config/rollup.alias.js",
62+
"build:index:dev": "NODE_ENV=development rollup -c config/rollup.index.js",
63+
"build:index:prod": "rollup -c config/rollup.index.js",
5364
"eslint": "eslint src",
5465
"eslint-check": "eslint --print-config .eslintrc.json | eslint-config-prettier-check",
5566
"prepublish": "npm run build",
56-
"test": "echo \"Error: no test specified\" && exit 1"
67+
"test": "jest"
68+
},
69+
"jest": {
70+
"coverageDirectory": "coverage",
71+
"coverageReporters": ["lcov", "text-summary"],
72+
"collectCoverageFrom": ["src/**/*.js"],
73+
"globals": { "__DEV__": true },
74+
"setupFiles": ["./test/jest.setupPixi.js"],
75+
"transform": {
76+
"^.+\\.js$": "babel-jest"
77+
}
5778
}
5879
}

0 commit comments

Comments
 (0)