Skip to content

Commit bd6e355

Browse files
authored
Adds enterprise grade monitoring and testing tools (#6)
* Code formatting with prettier * Code validation with eslint * Complete 100% code coverage * Codecov report integration * Travis CI build report integration
1 parent 2af17a8 commit bd6e355

12 files changed

+877
-78
lines changed

.eslintrc

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"extends": ["edited", "prettier", "prettier/react"],
3+
"plugins": ["prettier"],
4+
"parserOptions": {
5+
"ecmaVersion": 6,
6+
"sourceType": "module",
7+
"ecmaFeatures": {
8+
"jsx": true
9+
}
10+
},
11+
"settings": {
12+
"import/resolver": {
13+
"node": {
14+
"extensions": [".js", ".jsx"]
15+
}
16+
}
17+
},
18+
"rules": {
19+
"react/prefer-es6-class": [2, "always"],
20+
"prettier/prettier": [
21+
"error",
22+
{
23+
"trailingComma": "es5",
24+
"tabWidth": 4,
25+
"printWidth": 100
26+
}
27+
]
28+
}
29+
}

.prettierignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
__snapshots__/
2+
node_modules/
3+
dist/
4+
lib/
5+
coverage/
6+
package.json

.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"trailingComma": "es5",
3+
"tabWidth": 4,
4+
"printWidth": 100
5+
}

.travis.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
language: node_js
3+
4+
node_js:
5+
- 8
6+
7+
cache:
8+
yarn: true
9+
directories:
10+
- ".eslintcache"
11+
- node_modules
12+
13+
script:
14+
- yarn ci

CONTRIBUTING.md

+10-7
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,27 @@ Before opening an issue, please search the [issue tracker](https://github.com/br
1111
Visit the [Issue tracker](https://github.com/braposo/graphql-css/issues) to find a list of open issues that need attention.
1212

1313
Fork, then clone the repo:
14+
1415
```
1516
git clone https://github.com/your-username/graphql-css.git
1617
```
1718

1819
Build package for dev mode. It will automatically watch any changes in `src/` forlder:
20+
1921
```
2022
yarn run dev
2123
```
2224

23-
2425
### Building and testing
2526

2627
Build package:
28+
2729
```
2830
yarn run build
2931
```
3032

3133
To run the tests:
34+
3235
```
3336
yarn run test
3437
```
@@ -39,14 +42,14 @@ Please open an issue with a proposal for a new feature or refactoring before sta
3942

4043
## Submitting Changes
4144

42-
* Open a new issue in the [Issue tracker](https://github.com/braposo/graphql-css/issues).
43-
* Fork the repo.
44-
* Create a new feature branch based off the `master` branch.
45-
* Make sure all tests pass and there are no linting errors.
46-
* Submit a pull request, referencing any issues it addresses.
45+
* Open a new issue in the [Issue tracker](https://github.com/braposo/graphql-css/issues).
46+
* Fork the repo.
47+
* Create a new feature branch based off the `master` branch.
48+
* Make sure all tests pass and there are no linting errors.
49+
* Submit a pull request, referencing any issues it addresses.
4750

4851
Please try to keep your pull request focused in scope and avoid including unrelated commits.
4952

5053
After you have submitted your pull request, we'll try to get back to you as soon as possible. We may suggest some changes or improvements.
5154

52-
Thank you for contributing!
55+
Thank you for contributing!

README.md

+24-15
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@
44

55
Comes with a bunch of utilities so it's easy to integrate with your favourite way of building components.
66

7+
[![Build Status][build-badge]][travis]
8+
[![Code Coverage][coverage-badge]][coverage]
79
[![npm version][version-badge]][npm]
810
[![npm downloads][downloads-badge]][npm]
911
[![gzip size][size-badge]][size]
1012
[![MIT License][license-badge]][license]
13+
14+
![Module format][modules-badge]
15+
![Prettier format][prettier-badge]
1116
[![PRs Welcome][prs-badge]][prs]
1217
![Blazing Fast][fast-badge]
1318
![Modern][modern-badge]
1419
![Enterprise Grade][enterprise-badge]
1520

16-
1721
## Installation
1822

1923
```bash
@@ -75,11 +79,11 @@ Playground: https://codesandbox.io/s/jq22wyqm3
7579

7680
It works with the following format `gqlCSS(styles)(query, element)`:
7781

78-
| Arg | Type | Default | Definition |
79-
| ------ | ------------------- | ------- | ------------------------------------------------------------------- |
80-
| styles | object | | The styleguide object with all the rules |
81-
| query | gql | | The gql query to get the styles |
82-
| component | string \|\| node \|\| boolean | "div" | HTML element or React component to be displayed. If set to false only styles are returned. |
82+
| Arg | Type | Default | Definition |
83+
| --------- | ----------------------------- | ------- | ------------------------------------------------------------------------------------------ |
84+
| styles | object | | The styleguide object with all the rules |
85+
| query | gql | | The gql query to get the styles |
86+
| component | string \|\| node \|\| boolean | "div" | HTML element or React component to be displayed. If set to false only styles are returned. |
8387

8488
Here's how you can use it:
8589

@@ -120,11 +124,11 @@ const styles = gqlCSS(styles)(query, false);
120124

121125
`<GqlCSS>` component allows for a more declarative API and accepts these props:
122126

123-
| Prop | Type | Default | Definition |
124-
| ------ | ------ | ------- | ---------------------------------------- |
125-
| styles | object | | The styleguide object with all the rules |
126-
| query | gql | | The gql query to get the styles |
127-
| component | string \|\| node | "div" | HTML element or React component to be displayed |
127+
| Prop | Type | Default | Definition |
128+
| --------- | ---------------- | ------- | ----------------------------------------------- |
129+
| styles | object | | The styleguide object with all the rules |
130+
| query | gql | | The gql query to get the styles |
131+
| component | string \|\| node | "div" | HTML element or React component to be displayed |
128132

129133
All the remaining props are passed to the generated component so you can still use `glamorous` API. Here are some examples:
130134

@@ -197,7 +201,7 @@ export myHOC(query)(Component);
197201
The styles object is a valid JSON object that is used to define the styleguide of your project. Usually it includes definitions for colors, spacing, typography, etc.
198202

199203
```js
200-
const base = 4
204+
const base = 4;
201205
const styles = {
202206
typography: {
203207
scale: {
@@ -207,7 +211,7 @@ const styles = {
207211
l: base * 9,
208212
xl: base * 13,
209213
xxl: base * 20,
210-
unit: "px"
214+
unit: "px",
211215
},
212216
weight: {
213217
thin: 300,
@@ -294,7 +298,7 @@ const h1Styles = gql`
294298
}
295299
}
296300
}
297-
`
301+
`;
298302

299303
const otherH1Styles = gql`
300304
${h1Styles}
@@ -375,7 +379,6 @@ Please follow our [contributing guidelines](https://github.com/braposo/graphql-c
375379
[license]: https://github.com/braposo/graphql-css/blob/master/LICENSE
376380
[prs]: http://makeapullrequest.com
377381
[size]: https://unpkg.com/graphql-css/dist/graphql-css.min.js
378-
379382
[version-badge]: https://img.shields.io/npm/v/graphql-css.svg?style=flat-square
380383
[downloads-badge]: https://img.shields.io/npm/dm/graphql-css.svg?style=flat-square
381384
[license-badge]: https://img.shields.io/npm/l/graphql-css.svg?style=flat-square
@@ -384,3 +387,9 @@ Please follow our [contributing guidelines](https://github.com/braposo/graphql-c
384387
[enterprise-badge]: https://img.shields.io/badge/🏢-Enterprise%20Grade-999999.svg?style=flat-square
385388
[prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square
386389
[size-badge]: http://img.badgesize.io/https://unpkg.com/graphql-css/dist/graphql-css.min.js?compression=gzip&style=flat-square
390+
[prettier-badge]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square
391+
[build-badge]: https://img.shields.io/travis/braposo/graphql-css.svg?style=flat-square
392+
[travis]: https://travis-ci.org/braposo/graphql-css
393+
[coverage-badge]: https://img.shields.io/codecov/c/github/braposo/graphql-css.svg?style=flat-square
394+
[coverage]: https://codecov.io/github/braposo/graphql-css
395+
[modules-badge]: https://img.shields.io/badge/module%20formats-umd%2C%20cjs%2C%20esm-green.svg?style=flat-square

examples/styleguide.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ const styles = {
4040
fontSize: baseStyles.typography.scale.l,
4141
backgroundColor: baseStyles.colors.red,
4242
padding: baseStyles.spacing.l,
43-
cursor: "pointer"
43+
cursor: "pointer",
4444
},
4545
},
4646
done: {
4747
button: {
4848
fontSize: baseStyles.typography.scale.l,
4949
backgroundColor: baseStyles.colors.green,
5050
padding: baseStyles.spacing.l,
51-
cursor: "pointer"
51+
cursor: "pointer",
5252
},
5353
},
5454
},

package.json

+25-4
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@
1010
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src -d lib --ignore '**/*.test.js'",
1111
"build:umd": "cross-env BABEL_ENV=commonjs NODE_ENV=development webpack src/index.js --output dist/graphql-css.js --mode development",
1212
"build:umd:min": "cross-env BABEL_ENV=commonjs NODE_ENV=production webpack src/index.js --output dist/graphql-css.min.js --mode production",
13-
"clean": "rimraf lib dist es",
13+
"clean": "rimraf lib dist es coverage",
1414
"dev": "yarn run clean && cross-env BABEL_ENV=commonjs babel src -d lib --watch",
1515
"dev:server": "cross-env NODE_ENV=dev-server webpack-dev-server examples --config webpack.config.js --content-base examples --inline --hot --mode development",
16+
"format": "prettier --write \"**/*.{js,md,ts,json}\" *.{js,md,ts,json}",
1617
"lint": "eslint src/ --ext .js,.jsx",
17-
"prepublishOnly": "yarn run clean && yarn run build",
18-
"test": "jest --coverage",
19-
"test:watch": "jest --watchAll --coverage"
18+
"precommit": "lint-staged",
19+
"prepublishOnly": "yarn run clean && yarn run test && yarn run build",
20+
"test": "jest --no-cache",
21+
"test:watch": "jest --watchAll --coverage",
22+
"ci": "scripts/ci.sh"
2023
},
2124
"repository": {
2225
"type": "git",
@@ -52,17 +55,29 @@
5255
"devDependencies": {
5356
"babel-cli": "^6.26.0",
5457
"babel-core": "^6.26.0",
58+
"babel-eslint": "^8.2.2",
5559
"babel-loader": "^7.1.4",
5660
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
5761
"babel-plugin-transform-object-rest-spread": "^6.26.0",
5862
"babel-preset-env": "^1.6.1",
5963
"babel-preset-react": "^6.24.1",
64+
"codecov": "^3.0.0",
6065
"cross-env": "^5.1.4",
66+
"eslint": "^4.19.1",
67+
"eslint-config-edited": "^1.0.0",
68+
"eslint-config-prettier": "^2.9.0",
69+
"eslint-plugin-import": "^2.9.0",
70+
"eslint-plugin-prettier": "^2.6.0",
71+
"eslint-plugin-react": "^7.7.0",
6172
"glamor": "^2.20.40",
6273
"graphql": "^0.13.1",
6374
"graphql-tag": "^2.8.0",
75+
"husky": "^0.14.3",
6476
"jest": "^22.4.2",
6577
"jest-glamor-react": "^4.2.0",
78+
"lint-staged": "^7.0.0",
79+
"prettier": "^1.11.1",
80+
"prop-types": "^15.6.1",
6681
"react": "^16.2.0",
6782
"react-dom": "^16.2.0",
6883
"react-testing-library": "^1.3.0",
@@ -75,5 +90,11 @@
7590
"glamor": "^2.20.40",
7691
"graphql": "^0.13.1",
7792
"graphql-tag": "^2.8.0"
93+
},
94+
"lint-staged": {
95+
"*.{js,md,ts,json}": [
96+
"prettier --write",
97+
"git add"
98+
]
7899
}
79100
}

scripts/ci.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
set -e
2+
3+
echo "Building project"
4+
yarn build
5+
echo "\n\n"
6+
7+
echo "Linting"
8+
yarn lint
9+
echo "\n\n"
10+
11+
echo "Running tests"
12+
yarn test --coverage && codecov
13+
echo "\n\n"

src/index.js

+26-20
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import React from "react";
22
import graphql from "graphql-anywhere";
33
import glamorous from "glamorous";
44
import { Broadcast, Subscriber } from "react-broadcast";
5+
import PropTypes from "prop-types";
56

6-
const smoosh = object => {
7-
return Object.assign(
7+
const smoosh = object =>
8+
Object.assign(
89
{},
9-
...(function _flatten(objectBit, path = "") {
10+
...(function _flatten(objectBit) {
1011
return [].concat(
1112
...Object.keys(objectBit).map(
1213
key =>
@@ -17,7 +18,6 @@ const smoosh = object => {
1718
);
1819
})(object)
1920
);
20-
};
2121

2222
const resolver = (fieldName, root, args, context, { resultKey }) => {
2323
// if it's an aliased query add alias as prop
@@ -68,15 +68,19 @@ const gqlCSS = styles => (query, component = "div", variables) => {
6868
};
6969

7070
// Also export component for more declarative API
71-
export const GqlCSS = ({ styles, query, component = "div", variables, ...rest }) => {
72-
return (
73-
<Subscriber quiet={true} channel="graphqlcss">
74-
{contextStyles => {
75-
const Component = gqlCSS(styles || contextStyles || "")(query, component, variables);
76-
return <Component {...rest} />;
77-
}}
78-
</Subscriber>
79-
);
71+
export const GqlCSS = ({ styles, query, component = "div", variables, ...rest }) => (
72+
<Subscriber quiet={true} channel="graphqlcss">
73+
{contextStyles => {
74+
const Component = gqlCSS(styles || contextStyles || "")(query, component, variables);
75+
return <Component {...rest} />;
76+
}}
77+
</Subscriber>
78+
);
79+
GqlCSS.propTypes = {
80+
styles: PropTypes.object,
81+
query: PropTypes.object,
82+
variables: PropTypes.object,
83+
component: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
8084
};
8185

8286
// Export provider to broadcast styles to child GqlCSS components
@@ -85,15 +89,17 @@ export const GqlCSSProvider = ({ styles, children }) => (
8589
<span>{children}</span>
8690
</Broadcast>
8791
);
92+
GqlCSSProvider.propTypes = {
93+
styles: PropTypes.object,
94+
children: PropTypes.node,
95+
};
8896

8997
// Export HOC - uses render props underneath, because it's awesome
90-
export const withGqlCSS = (styles, query, variables) => Component => props => {
91-
return (
92-
<WithGqlCSS styles={styles} query={query} variables={variables}>
93-
{({ gqlStyles }) => <Component {...props} gqlStyles={gqlStyles} />}
94-
</WithGqlCSS>
95-
);
96-
};
98+
export const withGqlCSS = (styles, query, variables) => Component => props => (
99+
<WithGqlCSS styles={styles} query={query} variables={variables}>
100+
{({ gqlStyles }) => <Component {...props} gqlStyles={gqlStyles} />}
101+
</WithGqlCSS>
102+
);
97103

98104
// Export render props component
99105
export const WithGqlCSS = ({ styles, query, variables, children, ...rest }) => {

0 commit comments

Comments
 (0)