Skip to content

Commit 4af7e03

Browse files
committed
added babel, karma, webpack, es6
- based the build on react-boostrap super build - migrated to es6
1 parent fea40f5 commit 4af7e03

File tree

17 files changed

+316
-30
lines changed

17 files changed

+316
-30
lines changed

.eslintrc

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"node": true
5+
},
6+
"ecmaFeatures": {
7+
"jsx": true
8+
},
9+
"parser": "babel-eslint",
10+
"plugins": [
11+
"react"
12+
],
13+
"rules": {
14+
"comma-dangle": "always",
15+
"comma-spacing": 1,
16+
"key-spacing": 0,
17+
"no-underscore-dangle": 0,
18+
"no-unused-vars": [1, { "vars": "all", "args": "none" }],
19+
"no-undef": 1,
20+
"no-var": 2,
21+
"quotes": [2, "double"],
22+
"react/display-name": 0,
23+
"react/jsx-uses-react": 1,
24+
"react/no-did-mount-set-state": 1,
25+
"react/no-did-update-set-state": 1,
26+
"react/no-multi-comp": 1,
27+
"react/prop-types": 1,
28+
"react/react-in-jsx-scope": 1,
29+
"react/self-closing-comp": 1,
30+
"react/wrap-multilines": 1,
31+
"strict": 0
32+
}
33+
}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
lib/
3+
*.log

.npmignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules/
2+
test/
3+
tools/
4+
.gitignore
5+
.travis.yml
6+
karma.conf.js

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
sudo: false
2+
language: node_js
3+
node_js:
4+
- "iojs"
5+
- "0.10"
6+
- "0.12"

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ The component also has some utility functions that can be called.
6363
- tests
6464
- examples
6565
- code coverage
66-
- eslint
66+
67+
*The build is highly inspired by [react-bootstrap][rb]*
6768

6869
[reCAPTCHA]: https://www.google.com/recaptcha
6970
[signup]: http://www.google.com/recaptcha/admin
7071
[docs]: https://developers.google.com/recaptcha
7172
[js_api]: https://developers.google.com/recaptcha/docs/display#js_api
73+
[rb]: https://github.com/react-bootstrap/react-bootstrap/

karma.conf.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/* eslint no-var: 0 */
2+
require("babel/register");
3+
4+
var webpackConfig = require("./webpack/test.config.js");
5+
var isCI = process.env.CONTINUOUS_INTEGRATION === "true";
6+
7+
module.exports = function (config) {
8+
config.set({
9+
10+
basePath: "",
11+
12+
frameworks: [
13+
"mocha",
14+
"chai",
15+
],
16+
17+
files: [
18+
"test/index.js"
19+
],
20+
21+
preprocessors: {
22+
"test/index.js": ["webpack", "sourcemap"]
23+
},
24+
25+
webpack: webpackConfig,
26+
27+
webpackMiddleware: {
28+
noInfo: isCI
29+
},
30+
31+
reporters: ["mocha", "chai"],
32+
33+
mochaReporter: {
34+
output: "autowatch"
35+
},
36+
37+
port: 9876,
38+
39+
colors: true,
40+
41+
logLevel: config.LOG_INFO,
42+
43+
autoWatch: true,
44+
45+
browsers: [ isCI ? "PhantomJS" : "PhantomJS" /*"Chrome"*/ ],
46+
47+
captureTimeout: 60000,
48+
browserNoActivityTimeout: 30000,
49+
50+
singleRun: isCI
51+
});
52+
};

package.json

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@
22
"name": "react-google-recaptcha",
33
"version": "0.0.1",
44
"description": "React Component Wrapper for Google reCAPTCHA",
5-
"main": "lib/recaptcha.jsx",
5+
"main": "lib/recaptcha.js",
6+
"directories": {
7+
"lib": "lib/"
8+
},
69
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
10+
"build": "node run-babel tools/build.js",
11+
"lint": "eslint src test tools webpack karma.conf.js",
12+
"test": "karma start --single-run"
813
},
914
"repository": {
1015
"type": "git",
1116
"url": "https://github.com/dozoisch/react-google-recaptcha.git"
1217
},
1318
"keywords": [
1419
"react",
20+
"react-component",
1521
"captcha",
1622
"recaptcha",
1723
"google-recaptcha"
@@ -25,5 +31,30 @@
2531
"peerDependencies": {
2632
"react": ">=0.13"
2733
},
28-
"devDependencies": {}
34+
"devDependencies": {
35+
"babel": "~5.0.10",
36+
"babel-core": "~5.0.10",
37+
"babel-eslint": "~2.0.2",
38+
"babel-loader": "~5.0.0",
39+
"chai": "^2.2.0",
40+
"child-process-promise": "~1.0.2",
41+
"colors": "~1.0.3",
42+
"es5-shim": "~4.1.0",
43+
"eslint": "~0.18.0",
44+
"eslint-plugin-react": "~2.1.0",
45+
"fs-promise": "~0.3.1",
46+
"karma": "~0.12.31",
47+
"karma-chai": "^0.1.0",
48+
"karma-cli": "~0.0.4",
49+
"karma-mocha": "~0.1.10",
50+
"karma-mocha-reporter": "~1.0.2",
51+
"karma-phantomjs-launcher": "~0.1.4",
52+
"karma-sourcemap-loader": "~0.3.4",
53+
"karma-webpack": "~1.5.0",
54+
"lodash": "~3.6.0",
55+
"mocha": "~2.2.3",
56+
"react": "~0.13.1",
57+
"webpack": "~1.8.0",
58+
"yargs": "~3.7.0"
59+
}
2960
}

run-babel

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env node
2+
/* eslint no-var: 0 */
3+
var path = require("path");
4+
require("babel/register");
5+
var mod = require(path.join(__dirname, process.argv[2]));
6+
7+
if (typeof mod === "function") {
8+
mod();
9+
}
Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1+
/*global grecaptcha*/
12
"use strict";
2-
var React = require("react");
3-
var PropTypes = React.PropTypes;
3+
import React from "react";
4+
const PropTypes = React.PropTypes;
45

5-
var ReCAPTCHA = React.createClass({
6+
const ReCAPTCHA = React.createClass({
67
displayName: "react-reCAPTCHA",
78
propTypes: {
89
sitekey: PropTypes.string.isRequired,
910
onChange: PropTypes.func.isRequired,
1011
onloadCallbackName: PropTypes.string.isRequired, // Name on the script tag onload query parameter
1112
theme: PropTypes.oneOf(["dark", "light"]),
1213
type: PropTypes.oneOf(["image", "audio"]),
14+
elementId: PropTypes.string,
1315
tabindex: PropTypes.number,
1416
onLoad: PropTypes.func,
1517
onExpired: PropTypes.func,
1618
},
1719

18-
getDefaultState: function () {
20+
getDefaultState() {
1921
return {};
2022
},
2123

22-
getDefaultProps: function () {
24+
getDefaultProps() {
2325
return {
2426
theme: "light",
2527
type: "image",
@@ -28,50 +30,51 @@ var ReCAPTCHA = React.createClass({
2830
};
2931
},
3032

31-
getValue: function () {
33+
getValue() {
3234
if (typeof grecaptcha !== "undefined" && this.state.widgetId) {
3335
return grecaptcha.getResponse(this.state.widgetId);
3436
}
3537
return null;
3638
},
3739

38-
reset: function () {
40+
reset() {
3941
if (typeof grecaptcha !== "undefined" && this.state.widgetId) {
40-
grecaptcha.reset(this.props.widgetId);
42+
grecaptcha.reset(this.state.widgetId);
4143
}
4244
},
4345

44-
handleExpired: function () {
46+
handleExpired() {
4547
if (this.props.onExpired) {
4648
this.props.onExpired();
4749
} else if (this.props.onChange) {
4850
this.props.onChange(null);
4951
}
5052
},
5153

52-
explicitRender: function () {
53-
var id = grecaptcha.render(this.refs.captcha.getDOMNode(), {
54-
sitekey: this.props.sitekey,
55-
callback: this.props.onChange,
56-
theme: this.props.theme,
57-
type: this.props.type,
58-
tabindex: this.props.tabindex,
59-
"expired-callback": this.handleExpired,
60-
});
61-
this.setState({
62-
widgetId: id,
63-
});
54+
explicitRender() {
55+
if (typeof grecaptcha !== "undefined") {
56+
let id = grecaptcha.render(this.refs.captcha.getDOMNode(), {
57+
sitekey: this.props.sitekey,
58+
callback: this.props.onChange,
59+
theme: this.props.theme,
60+
type: this.props.type,
61+
tabindex: this.props.tabindex,
62+
"expired-callback": this.handleExpired,
63+
});
64+
this.setState({
65+
widgetId: id,
66+
});
67+
}
6468
},
6569

66-
67-
handleLoad: function () {
70+
handleLoad() {
6871
this.explicitRender();
6972
if (this.props.onLoad) {
7073
this.props.onLoad();
7174
}
7275
},
7376

74-
componentDidMount: function () {
77+
componentDidMount() {
7578
// If script is not loaded, set the callback on window.
7679
if (typeof grecaptcha === "undefined") {
7780
window[this.props.onloadCallbackName] = this.handleLoad;
@@ -80,11 +83,11 @@ var ReCAPTCHA = React.createClass({
8083
}
8184
},
8285

83-
render: function () {
86+
render() {
8487
return (
8588
<div ref="captcha" id={this.props.elementId} />
8689
);
8790
}
8891
});
8992

90-
module.exports = ReCAPTCHA;
93+
export default ReCAPTCHA;

test/.eslintrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"env": {
3+
"mocha": true
4+
},
5+
"globals": {
6+
"assert": true,
7+
},
8+
"rules": {
9+
"no-script-url": 1,
10+
"no-unused-expressions": 0,
11+
"react/no-multi-comp": 0
12+
}
13+
}

0 commit comments

Comments
 (0)