Skip to content

Commit 8b80c4a

Browse files
committed
init
add eslint (#1)
0 parents  commit 8b80c4a

File tree

146 files changed

+17081
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+17081
-0
lines changed

.babelrc

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"presets": [
3+
[
4+
"@babel/env",
5+
{
6+
"loose": true,
7+
"modules": false
8+
}
9+
],
10+
"@babel/react"
11+
],
12+
"include": "**/*.js",
13+
"exclude": "**/*.ts"
14+
}

.eslintignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
es
3+
lib
4+
tests
5+
6+
packages/icons/src

.eslintrc

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"extends": "@antfu",
3+
"overrides": [
4+
{
5+
"files": [
6+
"**/demo/**/*.ts",
7+
"**/demo/**/*.tsx",
8+
"**/demo/**/*.js",
9+
"**/demo/**/*.jsx"
10+
],
11+
"rules": {
12+
"no-console": "off"
13+
}
14+
}
15+
]
16+
}

.gitignore

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
.pnpm-debug.log*
9+
10+
# Coverage directory used by tools like istanbul
11+
coverage
12+
*.lcov
13+
14+
# Dependency directories
15+
node_modules
16+
17+
# dotenv environment variable files
18+
.env
19+
.env.development.local
20+
.env.test.local
21+
.env.production.local
22+
.env.local
23+
24+
# Idea
25+
.idea
26+
.vscode
27+
28+
# Build output
29+
dist
30+
es
31+
lib
32+
.umi

CONTRIBUTING.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# 组件库贡献不完全指南
2+
3+
> 非常高兴您愿意参与组件建设
4+
5+
## 前置条件
6+
7+
- [pnpm](https://pnpm.io/) 包管理器,嫌切换 yarn、npm、pnpm 麻烦可以使用 [@antfu/ni](https://github.com/antfu/ni) 快速切换。
8+
- `[email protected]`, 可以使用 `pnpm env use --global v14` 或者 [nvm](https://github.com/nvm-sh/nvm) 进行 Node 版本管理。
9+
10+
## 快速了解
11+
12+
```bash
13+
pnpm start // 启动组件文档
14+
```
15+
16+
稍等片刻后,本地浏览器打开 [http://localhost:8000/](http://localhost:8000/) 预览。
17+
18+
## 其他命令
19+
20+
> 下面出现的 `nr` 均表示 `pnpm run` 更多请看前置条件。
21+
22+
```bash
23+
nr clean // 移除构建产出
24+
nr start // 启动 dumi 开发文档
25+
nr build // 全部构建
26+
nr test // 运行所有测试用例
27+
```
28+
29+
**测试命令**更多命令查阅[Jest CLI 选项](https://jestjs.io/zh-Hans/docs/cli)
30+
31+
- `nr test packages/rc-ui/src/condition-input --watch` 表示监听并运行改目录下所有测试用例文件。
32+
- `nr test -u` 表示更新所有测试用例快照。
33+
34+
**依赖管理**更多命令查阅[pnpm CLI](https://pnpm.io/zh/pnpm-cli)
35+
36+
- `ni eslint -Dw` 表示安装开发依赖在 root 目录。
37+
- `nr -F @template-pro/icons build` 表示构建 @template-pro/icon 包。

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# @template-pro/react-ui-library
2+
3+
### Usage
4+
5+
> TODO:

config/config.ts

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import path from 'path'
2+
import type { IConfig } from 'dumi'
3+
import { menus } from './menus'
4+
import { navs } from './navs'
5+
6+
const resolvePath = (dir: string) => path.resolve(process.cwd(), dir)
7+
8+
const config: IConfig = {
9+
base: '/',
10+
publicPath: '/',
11+
exportStatic: {},
12+
nodeModulesTransform: {
13+
type: 'none',
14+
exclude: [],
15+
},
16+
forkTSChecker: {},
17+
alias: {
18+
'@template-pro/desktop-ui': path.join(__dirname, 'library/desktop-ui'),
19+
'@template-pro/mobile-ui': path.join(__dirname, 'library/mobile-ui'),
20+
'@template-pro/icons': resolvePath('packages/icons/src'),
21+
'@template-pro/rc-ui': resolvePath('packages/rc-ui/src'),
22+
'@template-pro/utils': resolvePath('packages/utils/src'),
23+
},
24+
extraBabelPlugins: [
25+
[
26+
'babel-plugin-import',
27+
{
28+
libraryName: 'antd',
29+
libraryDirectory: 'es',
30+
style: true,
31+
},
32+
'antd',
33+
],
34+
[
35+
'babel-plugin-import',
36+
{
37+
libraryName: 'antd-mobile',
38+
libraryDirectory: 'es',
39+
style: true,
40+
},
41+
'antd-mobile',
42+
],
43+
],
44+
chainWebpack(memo) {
45+
memo.module.rules.delete('svg')
46+
memo.module
47+
.rule('svg')
48+
.test(/\.svg$/)
49+
.use('svg')
50+
.loader('@svgr/webpack')
51+
},
52+
mode: 'site',
53+
title: 'react-ui-library',
54+
favicon: '/favicon.ico',
55+
logo: '/logo.svg',
56+
dynamicImport: {},
57+
manifest: {},
58+
hash: true,
59+
links: [
60+
{ rel: 'stylesheet', href: 'https://unpkg.com/reset-css/reset.css' },
61+
],
62+
resolve: {
63+
includes: ['docs', 'packages'],
64+
// passivePreview: true,
65+
},
66+
navs,
67+
menus,
68+
lessLoader: {
69+
modifyVars: {
70+
'@root-entry-name': 'default',
71+
},
72+
javascriptEnabled: true,
73+
},
74+
}
75+
76+
export default config

config/library/desktop-ui.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function pascalCase(name) {
2+
return name.charAt(0).toUpperCase() + name.slice(1).replace(/-(\w)/g, (_, n) => n.toUpperCase())
3+
}
4+
5+
const req = require.context('../../packages/desktop-ui/src', true, /^\.\/[^_][\w-]+\/style\/index\.less$/)
6+
7+
req.keys().forEach((mod) => {
8+
let v = req(mod)
9+
if (v && v.default)
10+
v = v.default
11+
12+
const match = mod.match(/^\.\/([^_][\w-]+)\/index\.less$/)
13+
if (match && match[1])
14+
exports[pascalCase(match[1])] = v
15+
})
16+
17+
module.exports = require('../../packages/desktop-ui/src')

config/library/mobile-ui.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function pascalCase(name) {
2+
return name.charAt(0).toUpperCase() + name.slice(1).replace(/-(\w)/g, (_, n) => n.toUpperCase())
3+
}
4+
5+
const req = require.context('../../packages/mobile-ui/src', true, /^\.\/[^_][\w-]+\/style\/index\.less$/)
6+
7+
req.keys().forEach((mod) => {
8+
let v = req(mod)
9+
if (v && v.default)
10+
v = v.default
11+
12+
const match = mod.match(/^\.\/([^_][\w-]+)\/index\.less$/)
13+
if (match && match[1])
14+
exports[pascalCase(match[1])] = v
15+
})
16+
17+
module.exports = require('../../packages/mobile-ui/src')

config/menus/desktop.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { ComponentMenus } from '.'
2+
3+
const desktopComponent: ComponentMenus = {
4+
common: [],
5+
layout: [],
6+
navigation: [],
7+
dataDisplay: [
8+
'src/select-trigger',
9+
'src/search-result',
10+
],
11+
dataEntry: [
12+
'src/ignore-emoji-input',
13+
'src/number-only-input',
14+
],
15+
feedback: [
16+
'src/base-modal',
17+
],
18+
guidance: [],
19+
other: [],
20+
}
21+
22+
export default desktopComponent

config/menus/icons.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default [
2+
{
3+
title: 'Icons',
4+
children: ['demo'],
5+
},
6+
]

config/menus/index.ts

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import desktopComponents from './desktop'
2+
import mobileComponents from './mobile'
3+
import utilsMenus from './utils'
4+
import rcUiMenus from './rcui'
5+
import iconsMenus from './icons'
6+
7+
const enumText = {
8+
common: '通用',
9+
layout: '布局',
10+
navigation: '导航',
11+
dataDisplay: '信息展示',
12+
dataEntry: '信息录入',
13+
feedback: '反馈',
14+
guidance: '引导提示',
15+
other: '其他',
16+
experimental: '试验性',
17+
} as const
18+
19+
export type MenusKeys = keyof typeof enumText
20+
export type ComponentMenus = {
21+
[key in MenusKeys]?: Array<string>
22+
}
23+
24+
function generateComponentMenus(menus: ComponentMenus, prefix: string) {
25+
const _menus: any[] = []
26+
Object.entries(menus).forEach(([key, value]) => {
27+
if (value.length)
28+
_menus.push({ title: enumText[key as MenusKeys], children: value })
29+
})
30+
return addPrefix(_menus, prefix)
31+
}
32+
33+
function addPrefix(menus: any[], prefix: string) {
34+
return menus.map((item) => {
35+
if (item.children)
36+
item.children = item.children.map((child: string) => `${prefix}/${child}`)
37+
38+
return item
39+
})
40+
}
41+
42+
export const desktopPrefix = 'desktop-ui'
43+
export const mobilePrefix = 'mobile-ui'
44+
export const utilsPrefix = 'utils'
45+
export const rcUiPrefix = 'rc-ui'
46+
export const iconsPrefix = 'icons'
47+
48+
export const menus = {
49+
[`/${desktopPrefix}`]: generateComponentMenus(desktopComponents, desktopPrefix),
50+
[`/${mobilePrefix}`]: generateComponentMenus(mobileComponents, mobilePrefix),
51+
[`/${utilsPrefix}`]: addPrefix(utilsMenus, utilsPrefix),
52+
[`/${rcUiPrefix}`]: addPrefix(rcUiMenus, rcUiPrefix),
53+
[`/${iconsPrefix}`]: addPrefix(iconsMenus, iconsPrefix),
54+
}

config/menus/mobile.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { ComponentMenus } from '.'
2+
3+
const mobileComponent: ComponentMenus = {
4+
common: [
5+
'src/button',
6+
],
7+
layout: [],
8+
navigation: [],
9+
dataDisplay: [],
10+
dataEntry: [],
11+
feedback: [],
12+
guidance: [],
13+
other: [],
14+
}
15+
export default mobileComponent

config/menus/rcui.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default [
2+
{
3+
title: 'General',
4+
children: [
5+
'src/condition-input',
6+
'src/icon',
7+
],
8+
},
9+
]

config/menus/utils.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const utilsMenu = [
2+
{
3+
title: 'General',
4+
children: ['src/with-default-props'],
5+
},
6+
{
7+
title: 'React Hooks',
8+
children: ['src/use-props-value'],
9+
},
10+
// {
11+
// title: "Date & Time",
12+
// children: [],
13+
// },
14+
// {
15+
// title: "String",
16+
// children: [],
17+
// },
18+
]
19+
20+
export default utilsMenu

config/navs.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { desktopPrefix, iconsPrefix, mobilePrefix, rcUiPrefix, utilsPrefix } from './menus'
2+
3+
export const navs = [
4+
{
5+
title: 'desktop',
6+
path: `/${desktopPrefix}`,
7+
},
8+
{
9+
title: 'mobile',
10+
path: `/${mobilePrefix}`,
11+
},
12+
{
13+
title: 'icons',
14+
path: `/${iconsPrefix}`,
15+
},
16+
{
17+
title: 'rc-ui',
18+
path: `/${rcUiPrefix}`,
19+
},
20+
{
21+
title: 'utils',
22+
path: `/${utilsPrefix}`,
23+
},
24+
]

0 commit comments

Comments
 (0)