Skip to content

Commit

Permalink
feat: add code
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromeZhang committed Jul 8, 2020
1 parent 4bd184d commit 51ffc1e
Show file tree
Hide file tree
Showing 22 changed files with 26,161 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

module.exports = {
presets: [
[
"@babel/preset-env",
{
modules: false
}
],
"@babel/preset-react",
"@babel/preset-typescript"
],
plugins: [
"@babel/plugin-transform-runtime",
[
"@babel/plugin-proposal-decorators",
{
legacy: true
}
],
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-object-rest-spread",
"@babel/plugin-transform-modules-commonjs"
]
};
2 changes: 2 additions & 0 deletions .czrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// path 用来指定适配器
{ "path": "cz-conventional-changelog" }
9 changes: 9 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
storybook-static/
node_modules/
.cache-loader/
.history
npm-error.log
npm-debug.log
debug.log
yarn-error.log
package-lock.json
77 changes: 77 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 8,
"sourceType": "module",
"project": "./tsconfig.json"
},
"extends":[
"standard",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended"
],
"plugins": [
"import",
"react",
"jsx-a11y"
],
"settings": {
"react": {
"pragma": "React",
"version": "16.6.3"
}
},
"env": {
"browser": true,
"node": true,
"es6": true
},
"globals": {
"expect": true,
"test": true,
"describe": true,
"beforeEach": true,
"afterEach": true,
"jest": true,
"it": true
},
"rules": {
"semi": 0,
"strict": 0,
"indent": [2, 4, { "SwitchCase": 1 }],
"arrow-body-style": 0,
"no-return-assign": 0,
"no-useless-constructor": 0,
"eqeqeq": 0,
"no-console": 0,
"no-param-reassign": 0,
"@typescript-eslint/no-unused-vars": ["error", { "vars": "all", "args": "none", "ignoreRestSiblings": false }],
"import/no-extraneous-dependencies": ["error", {"devDependencies": true, "optionalDependencies": false, "peerDependencies": false}],
"react/display-name":[0],
"react/sort-comp": 0,
"react/jsx-uses-react": 1,
"react/prefer-stateless-function": 0,
"react/jsx-closing-bracket-location": 0,
"jsx-a11y/no-static-element-interactions": 0,
"react/prop-types": [0, {"ignore": ["children"]}],
"react/jsx-filename-extension": [1, { "extensions": [".tsx", ".js", ".jsx"] }],
"react/react-in-jsx-scope": 0,
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/explicit-member-accessibility": 0,
"@typescript-eslint/explicit-function-return-type": 0,
"@typescript-eslint/no-use-before-define": 0,
"@typescript-eslint/no-var-requires": 0,
"@typescript-eslint/interface-name-prefix":0,
"@typescript-eslint/no-empty-interface":0,
"@typescript-eslint/no-this-alias": [
"error",
{
"allowDestructuring": true, // Allow `const { props, state } = this`; false by default
"allowedNames": ["that"] // Allow `const self = this`; `[]` by default
}
],
"prefer-const": 0,
"no-var": 0,
"prefer-rest-params": 0
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
storybook-static
lib
51 changes: 51 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Read more: https://docs.gitlab.com/12.7/ee/ci/yaml/README.html
cache:
paths:
- node_modules/
stages:
- install
- lint
- lintdoc
- check-types
- test
- build_deploy
# 当 merge_requests, master, dev, test 分支时会执行依赖安装
install_dependencies:
stage: install
script:
- npm install --unsafe-perm=true --allow-root
only:
- merge_requests
- /master|(f|F)ix|(d|D)ev_|(f|F)eat|(i|I)ssue|ref|perf|next|test_/
# 当 merge_requests 执行 eslint 检查
code_quality:
stage: lint
script:
- npm run lint
only:
- merge_requests
- /(f|F)ix|(d|D)ev_|(f|F)eat|(i|I)ssue|ref|perf|next/
# 当 merge_requests 执行 tsc 类型检查
check_types:
stage: check-types
script:
- npm run check-types
only:
- merge_requests
- /(f|F)ix|(d|D)ev_|(f|F)eat|(i|I)ssue|ref|perf|next/
# 当 merge_requests 有更时会执行单元测试任务
test:
stage: test
script:
- npm run test
only:
- merge_requests
- /(f|F)ix|(d|D)ev_|(f|F)eat|(i|I)ssue|ref|perf|next/
#执行 MD 文档校验, 为 doc 或者 master 命名当分支更新时才会触发
doc_quality:
stage: lintdoc
script:
- npm run lint-doc
only:
- /doc(s)|release/
- master
18 changes: 18 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
storybook-static
src
node_modules
scripts
.storybook
.babelrc.js
.czrc
.eslintignore
.eslintrc.json
.gitignore
.gitlab-ci.yml
commitlint.config.js
jest.config.js
package-lock.json
setupTests.js
storyshots.test.js
tsconfig.build.json
tsconfig.json
44 changes: 44 additions & 0 deletions .storybook/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"presets": [
[
"@babel/preset-env",
{
"modules": false
}
],
"@babel/preset-react",
"@babel/preset-typescript"
],
"env": {
"test": {
"presets": [
"@babel/preset-env",
"@babel/preset-react",
"@babel/preset-typescript"
]
}
},
"plugins": [
[
"import",
{
"libraryName": "antd",
"style": true
}
],
"@babel/transform-runtime",
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
],
"@babel/plugin-syntax-dynamic-import",
"macros",
"@babel/plugin-proposal-class-properties"
],
"babelrcRoots": [
".",
".storybook"
]
}
5 changes: 5 additions & 0 deletions .storybook/addons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import '@storybook/addon-storysource/register';
import '@storybook/addon-notes/register';
import '@storybook/addon-options/register';
import '@storybook/addon-knobs/register';
import '@storybook/addon-actions/register';
56 changes: 56 additions & 0 deletions .storybook/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { configure, addDecorator, addParameters, setAddon } from '@storybook/react';
// 避免jest识别webpack context 报错
import requireContext from 'require-context.macro';
import { withNotes } from '@storybook/addon-notes';
import { withKnobs } from '@storybook/addon-knobs';
import { withInfo } from '@storybook/addon-info';
import { withOptions } from '@storybook/addon-options';
import chaptersAddon from 'react-storybook-addon-chapters';
import { repository, version } from "../package.json"
setAddon(chaptersAddon);
addDecorator(withNotes);
addDecorator(withKnobs);
// addReadme与withInfo不能共存
addDecorator(withInfo);
/**
* 全局设置 info 样式
* info-addons源样式
* Overrides styles of addon. The object should follow this shape:
* https://github.com/storybookjs/storybook/blob/master/addons/info/src/components/Story.js#L19
*/
addParameters({
info: {
inline: true,
source: false,
styles: stylesheet => ({
// Setting the style with a function
...stylesheet,
infoBody: {
...stylesheet.infoBody,
padding: '20px 40px 20px'
},
header: {
...stylesheet.header,
h1: {
...stylesheet.header.h1,
},
},
}),
}
});

addDecorator(withOptions({
name: `组件库 v${version}`,
url: repository,
sidebarAnimations: true,
}))
/**
* 动态加载所有stories
*/
function loadStories() {
const req = requireContext('../src/stories', true, /\.stories\.(ts|tsx)$/);
const allExport = [require('../src/stories/index.stories')]; // 第一排序
req.keys().forEach(fileName => allExport.push(req(fileName)));
return allExport;
}
configure(loadStories, module);
43 changes: 43 additions & 0 deletions .storybook/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

const path = require('path');
module.exports = async ({ config, mode }) => {
config.module.rules.push({
test: /\.(ts|tsx)$/,
loader: require.resolve('babel-loader'),
options: {
presets: [['react-app', { flow: false, typescript: true }]],
plugins: [
['import', { libraryName: "antd", style: true }]
]
}
}, {
test: /\.stories\.(ts|tsx)$/,
loaders: [require.resolve('@storybook/addon-storysource/loader')],
enforce: 'pre',
}, {
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
include: path.resolve(__dirname, '../'),
}, {
test: /\.less$/,
use: ['style-loader', 'css-loader', {
loader: "less-loader",
options: {
javascriptEnabled: true
}
}],
include: [/[\\/]node_modules[\\/].*antd/],
}, {
test: /\.(jpg|png|gif)$/,
loader: ["file-loader", "url-loader?limit=100000"]
}, {
test: /\.(eot|woff|svg|ttf|woff2|gif|appcache|webp)(\?|$)/,
loader: [
"file-loader?name=[name].[ext]",
"url-loader?limit=100000"
]
});
config.resolve.extensions.push(".ts", ".tsx", ".js", ".jsx", ".scss", ".css");
// Return the altered config
return config;
};
Empty file added CHANGELOG.md
Empty file.
7 changes: 7 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
extends: ['@commitlint/config-angular'],
'rules': {
'type-case': [2, 'always', 'lower-case'],
'scope-case': [0, 'always']
}
};
21 changes: 21 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

module.exports = {
name: 'storybook-ts-boilerplate',
globals: {
},
setupFilesAfterEnv: ["./setupTests.js"],
transformIgnorePatterns: ["/node_modules/", "lib", "dist"],
testPathIgnorePatterns: ['/node_modules/'],
transform: {
"^.+\\.[jt]s?(x)$": "babel-jest"
},
testMatch: [
'**/__tests__/**/(*.)+(spec|test).[jt]s?(x)',
'**/test/**/(*.)+(spec|test).[jt]s?(x)'
],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/mock/fileMock.js',
'\\.(css|scss|less)$': '<rootDir>/mock/styleMock.js'
}
};
Loading

0 comments on commit 51ffc1e

Please sign in to comment.