Skip to content

Commit 51ffc1e

Browse files
author
jeromeZhang
committed
feat: add code
1 parent 4bd184d commit 51ffc1e

22 files changed

+26161
-0
lines changed

.babelrc.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
module.exports = {
3+
presets: [
4+
[
5+
"@babel/preset-env",
6+
{
7+
modules: false
8+
}
9+
],
10+
"@babel/preset-react",
11+
"@babel/preset-typescript"
12+
],
13+
plugins: [
14+
"@babel/plugin-transform-runtime",
15+
[
16+
"@babel/plugin-proposal-decorators",
17+
{
18+
legacy: true
19+
}
20+
],
21+
"@babel/plugin-proposal-class-properties",
22+
"@babel/plugin-proposal-object-rest-spread",
23+
"@babel/plugin-transform-modules-commonjs"
24+
]
25+
};

.czrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// path 用来指定适配器
2+
{ "path": "cz-conventional-changelog" }

.eslintignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
storybook-static/
2+
node_modules/
3+
.cache-loader/
4+
.history
5+
npm-error.log
6+
npm-debug.log
7+
debug.log
8+
yarn-error.log
9+
package-lock.json

.eslintrc.json

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
"parserOptions": {
4+
"ecmaVersion": 8,
5+
"sourceType": "module",
6+
"project": "./tsconfig.json"
7+
},
8+
"extends":[
9+
"standard",
10+
"plugin:react/recommended",
11+
"plugin:@typescript-eslint/recommended"
12+
],
13+
"plugins": [
14+
"import",
15+
"react",
16+
"jsx-a11y"
17+
],
18+
"settings": {
19+
"react": {
20+
"pragma": "React",
21+
"version": "16.6.3"
22+
}
23+
},
24+
"env": {
25+
"browser": true,
26+
"node": true,
27+
"es6": true
28+
},
29+
"globals": {
30+
"expect": true,
31+
"test": true,
32+
"describe": true,
33+
"beforeEach": true,
34+
"afterEach": true,
35+
"jest": true,
36+
"it": true
37+
},
38+
"rules": {
39+
"semi": 0,
40+
"strict": 0,
41+
"indent": [2, 4, { "SwitchCase": 1 }],
42+
"arrow-body-style": 0,
43+
"no-return-assign": 0,
44+
"no-useless-constructor": 0,
45+
"eqeqeq": 0,
46+
"no-console": 0,
47+
"no-param-reassign": 0,
48+
"@typescript-eslint/no-unused-vars": ["error", { "vars": "all", "args": "none", "ignoreRestSiblings": false }],
49+
"import/no-extraneous-dependencies": ["error", {"devDependencies": true, "optionalDependencies": false, "peerDependencies": false}],
50+
"react/display-name":[0],
51+
"react/sort-comp": 0,
52+
"react/jsx-uses-react": 1,
53+
"react/prefer-stateless-function": 0,
54+
"react/jsx-closing-bracket-location": 0,
55+
"jsx-a11y/no-static-element-interactions": 0,
56+
"react/prop-types": [0, {"ignore": ["children"]}],
57+
"react/jsx-filename-extension": [1, { "extensions": [".tsx", ".js", ".jsx"] }],
58+
"react/react-in-jsx-scope": 0,
59+
"@typescript-eslint/no-explicit-any": 0,
60+
"@typescript-eslint/explicit-member-accessibility": 0,
61+
"@typescript-eslint/explicit-function-return-type": 0,
62+
"@typescript-eslint/no-use-before-define": 0,
63+
"@typescript-eslint/no-var-requires": 0,
64+
"@typescript-eslint/interface-name-prefix":0,
65+
"@typescript-eslint/no-empty-interface":0,
66+
"@typescript-eslint/no-this-alias": [
67+
"error",
68+
{
69+
"allowDestructuring": true, // Allow `const { props, state } = this`; false by default
70+
"allowedNames": ["that"] // Allow `const self = this`; `[]` by default
71+
}
72+
],
73+
"prefer-const": 0,
74+
"no-var": 0,
75+
"prefer-rest-params": 0
76+
}
77+
}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
storybook-static
3+
lib

.gitlab-ci.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Read more: https://docs.gitlab.com/12.7/ee/ci/yaml/README.html
2+
cache:
3+
paths:
4+
- node_modules/
5+
stages:
6+
- install
7+
- lint
8+
- lintdoc
9+
- check-types
10+
- test
11+
- build_deploy
12+
# 当 merge_requests, master, dev, test 分支时会执行依赖安装
13+
install_dependencies:
14+
stage: install
15+
script:
16+
- npm install --unsafe-perm=true --allow-root
17+
only:
18+
- merge_requests
19+
- /master|(f|F)ix|(d|D)ev_|(f|F)eat|(i|I)ssue|ref|perf|next|test_/
20+
# 当 merge_requests 执行 eslint 检查
21+
code_quality:
22+
stage: lint
23+
script:
24+
- npm run lint
25+
only:
26+
- merge_requests
27+
- /(f|F)ix|(d|D)ev_|(f|F)eat|(i|I)ssue|ref|perf|next/
28+
# 当 merge_requests 执行 tsc 类型检查
29+
check_types:
30+
stage: check-types
31+
script:
32+
- npm run check-types
33+
only:
34+
- merge_requests
35+
- /(f|F)ix|(d|D)ev_|(f|F)eat|(i|I)ssue|ref|perf|next/
36+
# 当 merge_requests 有更时会执行单元测试任务
37+
test:
38+
stage: test
39+
script:
40+
- npm run test
41+
only:
42+
- merge_requests
43+
- /(f|F)ix|(d|D)ev_|(f|F)eat|(i|I)ssue|ref|perf|next/
44+
#执行 MD 文档校验, 为 doc 或者 master 命名当分支更新时才会触发
45+
doc_quality:
46+
stage: lintdoc
47+
script:
48+
- npm run lint-doc
49+
only:
50+
- /doc(s)|release/
51+
- master

.npmignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
storybook-static
2+
src
3+
node_modules
4+
scripts
5+
.storybook
6+
.babelrc.js
7+
.czrc
8+
.eslintignore
9+
.eslintrc.json
10+
.gitignore
11+
.gitlab-ci.yml
12+
commitlint.config.js
13+
jest.config.js
14+
package-lock.json
15+
setupTests.js
16+
storyshots.test.js
17+
tsconfig.build.json
18+
tsconfig.json

.storybook/.babelrc

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"presets": [
3+
[
4+
"@babel/preset-env",
5+
{
6+
"modules": false
7+
}
8+
],
9+
"@babel/preset-react",
10+
"@babel/preset-typescript"
11+
],
12+
"env": {
13+
"test": {
14+
"presets": [
15+
"@babel/preset-env",
16+
"@babel/preset-react",
17+
"@babel/preset-typescript"
18+
]
19+
}
20+
},
21+
"plugins": [
22+
[
23+
"import",
24+
{
25+
"libraryName": "antd",
26+
"style": true
27+
}
28+
],
29+
"@babel/transform-runtime",
30+
[
31+
"@babel/plugin-proposal-decorators",
32+
{
33+
"legacy": true
34+
}
35+
],
36+
"@babel/plugin-syntax-dynamic-import",
37+
"macros",
38+
"@babel/plugin-proposal-class-properties"
39+
],
40+
"babelrcRoots": [
41+
".",
42+
".storybook"
43+
]
44+
}

.storybook/addons.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import '@storybook/addon-storysource/register';
2+
import '@storybook/addon-notes/register';
3+
import '@storybook/addon-options/register';
4+
import '@storybook/addon-knobs/register';
5+
import '@storybook/addon-actions/register';

.storybook/config.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { configure, addDecorator, addParameters, setAddon } from '@storybook/react';
2+
// 避免jest识别webpack context 报错
3+
import requireContext from 'require-context.macro';
4+
import { withNotes } from '@storybook/addon-notes';
5+
import { withKnobs } from '@storybook/addon-knobs';
6+
import { withInfo } from '@storybook/addon-info';
7+
import { withOptions } from '@storybook/addon-options';
8+
import chaptersAddon from 'react-storybook-addon-chapters';
9+
import { repository, version } from "../package.json"
10+
setAddon(chaptersAddon);
11+
addDecorator(withNotes);
12+
addDecorator(withKnobs);
13+
// addReadme与withInfo不能共存
14+
addDecorator(withInfo);
15+
/**
16+
* 全局设置 info 样式
17+
* info-addons源样式
18+
* Overrides styles of addon. The object should follow this shape:
19+
* https://github.com/storybookjs/storybook/blob/master/addons/info/src/components/Story.js#L19
20+
*/
21+
addParameters({
22+
info: {
23+
inline: true,
24+
source: false,
25+
styles: stylesheet => ({
26+
// Setting the style with a function
27+
...stylesheet,
28+
infoBody: {
29+
...stylesheet.infoBody,
30+
padding: '20px 40px 20px'
31+
},
32+
header: {
33+
...stylesheet.header,
34+
h1: {
35+
...stylesheet.header.h1,
36+
},
37+
},
38+
}),
39+
}
40+
});
41+
42+
addDecorator(withOptions({
43+
name: `组件库 v${version}`,
44+
url: repository,
45+
sidebarAnimations: true,
46+
}))
47+
/**
48+
* 动态加载所有stories
49+
*/
50+
function loadStories() {
51+
const req = requireContext('../src/stories', true, /\.stories\.(ts|tsx)$/);
52+
const allExport = [require('../src/stories/index.stories')]; // 第一排序
53+
req.keys().forEach(fileName => allExport.push(req(fileName)));
54+
return allExport;
55+
}
56+
configure(loadStories, module);

0 commit comments

Comments
 (0)