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

chore: use father #85

Merged
merged 21 commits into from Sep 1, 2020
16 changes: 16 additions & 0 deletions .eslintrc.js
@@ -0,0 +1,16 @@
const base = require('@umijs/fabric/dist/eslint');

module.exports = {
...base,
rules: {
...base.rules,
'no-template-curly-in-string': 0,
'prefer-promise-reject-errors': 0,
'react/no-array-index-key': 0,
'react/sort-comp': 0,
'@typescript-eslint/no-explicit-any': 0,
'jsx-a11y/role-supports-aria-props': 0,
'jsx-a11y/no-noninteractive-tabindex': 0,
'import/no-extraneous-dependencies': 0,
},
};
9 changes: 9 additions & 0 deletions .fatherrc.js
@@ -0,0 +1,9 @@
export default {
cjs: "babel",
esm: { type: "babel", importLibToEs: true },
preCommit: {
eslint: true,
prettier: true,
},
runtimeHelpers: true,
};
5 changes: 4 additions & 1 deletion .gitignore
Expand Up @@ -27,4 +27,7 @@ build
lib
es
coverage/
yarn.lock
yarn.lock
package-lock.json
.storybook
.doc
6 changes: 6 additions & 0 deletions .prettierrc
@@ -0,0 +1,6 @@
{
"singleQuote": true,
"trailingComma": "all",
"proseWrap": "never",
"printWidth": 100
}
7 changes: 4 additions & 3 deletions .travis.yml
Expand Up @@ -5,11 +5,9 @@ sudo: false
notifications:
email:
- yiminghe@gmail.com
- afc163@gmail.com
- yesmeck@gmail.com

node_js:
- 10
- 12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

升级了就好了。

现在就剩下覆盖率的问题了。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用例 转了下写法 就下降了 。。。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以补两个用例

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

之前的dialog 和 upload 咋没有覆盖率检查结果显示呢?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

版本的原因吧,那2个都是10


script:
- |
Expand All @@ -19,7 +17,10 @@ script:
else
npm run $TEST_TYPE
fi

env:
matrix:
- TEST_TYPE=lint
- TEST_TYPE=test
- TEST_TYPE=coverage
- TEST_TYPE=compile
Empty file removed assets/index.less
Empty file.
1 change: 0 additions & 1 deletion examples/fast-progress.html

This file was deleted.

6 changes: 2 additions & 4 deletions examples/fast-progress.js → examples/fast-progress.tsx
@@ -1,7 +1,5 @@
import 'rc-progress/assets/index.less';
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import { Line, Circle } from 'rc-progress';
import { Line, Circle } from '..';

class App extends Component {
constructor() {
Expand Down Expand Up @@ -49,4 +47,4 @@ class App extends Component {
}
}

ReactDOM.render(<App />, document.getElementById('__react-content'));
export default App;
1 change: 0 additions & 1 deletion examples/gap.html

This file was deleted.

8 changes: 4 additions & 4 deletions examples/gap.js → examples/gap.tsx
@@ -1,12 +1,12 @@
import 'rc-progress/assets/index.less';
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import { Circle } from 'rc-progress';
import { Circle } from '..';

const colorMap = ['#3FC7FA', '#85D262', '#FE8C6A'];

function getColor(index) {
return colorMap[(index + colorMap.length) % colorMap.length];
}

class Example extends Component {
constructor() {
super();
Expand Down Expand Up @@ -87,4 +87,4 @@ class Example extends Component {
}
}

ReactDOM.render(<Example />, document.getElementById('__react-content'));
export default Example;
1 change: 0 additions & 1 deletion examples/gradient-circle.html

This file was deleted.

7 changes: 3 additions & 4 deletions examples/gradient-circle.js → examples/gradient-circle.tsx
@@ -1,14 +1,13 @@
import 'rc-progress/assets/index.less';
import React from 'react';
import ReactDOM from 'react-dom';
import { Circle } from 'rc-progress';
import { Circle } from '..';

const Example = () => {
const circleContainerStyle = {
width: '250px',
height: '250px',
display: 'inline-block',
};

return (
<div>
<h3>Circle Progress {90}%</h3>
Expand Down Expand Up @@ -54,4 +53,4 @@ const Example = () => {
);
};

ReactDOM.render(<Example />, document.getElementById('__react-content'));
export default Example;
1 change: 0 additions & 1 deletion examples/simple.html

This file was deleted.

6 changes: 2 additions & 4 deletions examples/simple.js → examples/simple.tsx
@@ -1,7 +1,5 @@
import 'rc-progress/assets/index.less';
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import { Line, Circle } from 'rc-progress';
import { Line, Circle } from '..';

class Example extends Component {
constructor() {
Expand Down Expand Up @@ -57,4 +55,4 @@ class Example extends Component {
}
}

ReactDOM.render(<Example />, document.getElementById('__react-content'));
export default Example;
2 changes: 1 addition & 1 deletion index.js
@@ -1,4 +1,4 @@
import Progress, { Line, Circle } from './src/';
import Progress, { Line, Circle } from './src';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个文件应该没用了


export {
Line,
Expand Down
4 changes: 4 additions & 0 deletions jest.config.js
@@ -0,0 +1,4 @@
module.exports = {
setupFiles: ["./tests/setup.js"],
snapshotSerializers: [require.resolve("enzyme-to-json/serializer")],
};
11 changes: 11 additions & 0 deletions now.json
@@ -0,0 +1,11 @@
{
"version": 2,
"name": "rc-progress",
"builds": [
{
"src": "package.json",
"use": "@now/static-build",
"config": { "distDir": ".doc" }
}
]
}
71 changes: 32 additions & 39 deletions package.json
Expand Up @@ -17,57 +17,50 @@
"url": "http://github.com/react-component/progress/issues"
},
"license": "MIT",
"main": "lib/index",
"module": "es/index",
"types": "./typings/index.d.ts",
"main": "./lib/index",
"module": "./es/index",
"types": "./lib/index.d.ts",
"files": [
"dist",
"lib",
"assets/*.css",
"es",
"typings/index.d.ts"
],
"config": {
"port": 8000,
"entry": {
"rc-progress": [
"./src/index.js",
"./assets/index.less"
]
}
},
"scripts": {
"dist": "rc-tools run dist",
"build": "rc-tools run build",
"gh-pages": "rc-tools run gh-pages",
"start": "rc-tools run server",
"compile": "rc-tools run compile",
"pub": "rc-tools run pub",
"lint": "rc-tools run lint",
"lint:fix": "rc-tools run lint --fix",
"prettier": "rc-tools run prettier",
"test": "rc-tools run test",
"prepublish": "rc-tools run guard",
"coverage": "rc-tools run test --coverage",
"pre-commit": "rc-tools run pre-commit",
"lint-staged": "lint-staged"
"start": "cross-env NODE_ENV=development father doc dev --storybook",
"build": "father doc build --storybook",
"compile": "father build",
"gh-pages": "npm run build && father doc deploy",
"prepublishOnly": "npm run compile && np --yolo --no-publish",
"lint": "eslint src/ --ext .ts,.tsx,.jsx,.js,.md",
"prettier": "prettier --write \"**/*.{ts,tsx,js,jsx,json,md}\"",
"test": "father test",
"coverage": "father test --coverage"
},
"devDependencies": {
"lint-staged": "^10.0.1",
"pre-commit": "1.x",
"rc-tools": "9.x",
"peerDependencies": {
"react": "^16.0.0",
"react-dom": "^16.0.0"
},
"pre-commit": [
"lint-staged"
],
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"npm run pre-commit"
]
},
"dependencies": {
"@babel/runtime": "^7.10.1",
"classnames": "^2.2.6"
},
"devDependencies": {
"@types/classnames": "^2.2.9",
"@types/jest": "^26.0.0",
"@types/react": "^16.9.2",
"@types/react-dom": "^16.9.0",
"@umijs/fabric": "^2.0.0",
"cross-env": "^7.0.0",
"enzyme": "^3.1.1",
"enzyme-adapter-react-16": "^1.0.1",
"enzyme-to-json": "^3.1.2",
"eslint": "^7.6.0",
"father": "^2.29.6",
"np": "^6.5.0",
"prettier": "^2.1.1",
"react": "^16.9.0",
"react-dom": "^16.9.0",
"typescript": "^4.0.2"
}
}
File renamed without changes.
1 change: 1 addition & 0 deletions src/Line.js → src/Line.tsx
Expand Up @@ -16,6 +16,7 @@ const Line = ({
transition,
...restProps
}) => {
// eslint-disable-next-line no-param-reassign
delete restProps.gapPosition;
const percentList = Array.isArray(percent) ? percent : [percent];
const strokeColorList = Array.isArray(strokeColor) ? strokeColor : [strokeColor];
Expand Down
1 change: 1 addition & 0 deletions src/common.js
Expand Up @@ -13,6 +13,7 @@ export const defaultProps = {
};

export const useTransitionDuration = percentList => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const paths = percentList.map(() => useRef());
const prevTimeStamp = useRef();
useEffect(() => {
Expand Down
50 changes: 17 additions & 33 deletions tests/index.spec.js
@@ -1,24 +1,10 @@
/* eslint-disable react/no-render-return-value */
// eslint-disable-next-line max-classes-per-file
import React from 'react';
import ReactDOM from 'react-dom';
import { mount } from 'enzyme';
import { Line, Circle } from '../src';

function getGradientIdFromDef(def) {
return def.firstElementChild.attributes.getNamedItem('id').value;
}

describe('Progress', () => {
let div = null;
beforeEach(() => {
div = document.createElement('div');
document.body.appendChild(div);
});

afterEach(() => {
ReactDOM.unmountComponentAtNode(div);
document.body.removeChild(div);
});

describe('Line', () => {
it('change with animation', () => {
class Demo extends React.Component {
Expand All @@ -31,12 +17,12 @@ describe('Progress', () => {
return <Line percent={percent} strokeWidth="1" />;
}
}
const line = ReactDOM.render(<Demo />, div);
expect(line.state.percent).toBe('0');
line.setState({
percent: '30',
});
expect(line.state.percent).toBe('30');

const line = mount(<Demo />);
expect(line.state().percent).toBe('0');
line.setState({ percent: '30' });
expect(line.state().percent).toBe('30');
line.unmount();
});
});

Expand All @@ -52,16 +38,15 @@ describe('Progress', () => {
return <Circle percent={percent} strokeWidth="1" />;
}
}
const circle = ReactDOM.render(<Demo />, div);
expect(circle.state.percent).toBe('0');
circle.setState({
percent: '30',
});
expect(circle.state.percent).toBe('30');
const circle = mount(<Demo />);
expect(circle.state().percent).toBe('0');
circle.setState({ percent: '30' });
expect(circle.state().percent).toBe('30');
circle.unmount();
});

it('should gradient works and circles have different gradient IDs', () => {
ReactDOM.render(
const c = mount(
<>
<Circle
percent={90}
Expand All @@ -82,12 +67,11 @@ describe('Progress', () => {
}}
/>
</>,
div,
);

const gradientDefs = div.querySelectorAll('defs');
const idFirst = getGradientIdFromDef(gradientDefs[0]);
const idSecond = getGradientIdFromDef(gradientDefs[1]);
const gradientDefs = c.find('defs');
const idFirst = gradientDefs.at(0).props().children.props.id;
const idSecond = gradientDefs.at(1).props().children.props.id;
const idRE = /^rc-progress-gradient-\d{1,}$/;
expect(idFirst).toMatch(idRE);
expect(idSecond).toMatch(idRE);
Expand Down
6 changes: 6 additions & 0 deletions tests/setup.js
@@ -0,0 +1,6 @@
global.requestAnimationFrame = cb => setTimeout(cb, 0);

const Enzyme = require('enzyme');
const Adapter = require('enzyme-adapter-react-16');

Enzyme.configure({ adapter: new Adapter() });
3 changes: 3 additions & 0 deletions typings/index.d.ts
@@ -1,4 +1,6 @@
/* tslint:disable */
/* eslint-disable react/prefer-stateless-function */
// eslint-disable-next-line max-classes-per-file
declare module 'rc-progress' {
export interface RCProgressProps {
strokeWidth?: number;
Expand All @@ -13,6 +15,7 @@ declare module 'rc-progress' {
gapDegree?: number;
gapPosition?: 'top' | 'right' | 'bottom' | 'left';
}

export class Line extends React.Component<RCProgressProps, {}> {}
export class Circle extends React.Component<RCProgressProps, {}> {}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改成 ts 后应该不需要这个文件了。