mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-25 02:41:46 +08:00
chore(cli): add generator template
This commit is contained in:
parent
dac60c8a37
commit
38001e59f0
4
packages/vant-cli/generators/.eslintignore
Normal file
4
packages/vant-cli/generators/.eslintignore
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
es
|
||||||
|
lib
|
||||||
|
dist
|
||||||
|
node_modules
|
17
packages/vant-cli/generators/.gitignore
vendored
Normal file
17
packages/vant-cli/generators/.gitignore
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
*.log*
|
||||||
|
.cache
|
||||||
|
.DS_Store
|
||||||
|
.idea
|
||||||
|
.vscode
|
||||||
|
|
||||||
|
# npm
|
||||||
|
node_modules
|
||||||
|
package-lock.json
|
||||||
|
|
||||||
|
# dist file
|
||||||
|
es
|
||||||
|
lib
|
||||||
|
site
|
||||||
|
|
||||||
|
# test
|
||||||
|
test/coverage
|
3
packages/vant-cli/generators/babel.config.js
Normal file
3
packages/vant-cli/generators/babel.config.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
module.exports = {
|
||||||
|
presets: ['@vant/cli/preset']
|
||||||
|
};
|
11
packages/vant-cli/generators/docs/home.md
Normal file
11
packages/vant-cli/generators/docs/home.md
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# 介绍
|
||||||
|
|
||||||
|
### 关于
|
||||||
|
|
||||||
|
这是一段组件库的介绍
|
||||||
|
|
||||||
|
### 特性
|
||||||
|
|
||||||
|
- 特性一
|
||||||
|
- 特性二
|
||||||
|
- 特性三
|
15
packages/vant-cli/generators/docs/quickstart.md
Normal file
15
packages/vant-cli/generators/docs/quickstart.md
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# 快速上手
|
||||||
|
|
||||||
|
### 安装
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 通过 npm 安装
|
||||||
|
npm i vant -S
|
||||||
|
|
||||||
|
# 通过 yarn 安装
|
||||||
|
yarn add vant
|
||||||
|
```
|
||||||
|
|
||||||
|
### 引入组件
|
||||||
|
|
||||||
|
这是一段引入组件的介绍
|
68
packages/vant-cli/generators/package.json
Normal file
68
packages/vant-cli/generators/package.json
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
{
|
||||||
|
"name": "@youzan/demo-ui",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "lib/demo-ui.js",
|
||||||
|
"style": "lib/demo-ui.css",
|
||||||
|
"files": [
|
||||||
|
"lib",
|
||||||
|
"es"
|
||||||
|
],
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vant-cli dev",
|
||||||
|
"test": "vant-cli test",
|
||||||
|
"lint": "vant-cli lint",
|
||||||
|
"build": "vant-cli build",
|
||||||
|
"release": "vant-cli release",
|
||||||
|
"test:coverage": "open test/coverage/index.html",
|
||||||
|
"build-site": "vant-cli build-site && gh-pages -d site"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "MIT",
|
||||||
|
"husky": {
|
||||||
|
"hooks": {
|
||||||
|
"pre-commit": "lint-staged",
|
||||||
|
"commit-msg": "vant-cli commit-lint"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"lint-staged": {
|
||||||
|
"*.{ts,tsx,js,jsx,vue}": [
|
||||||
|
"eslint --fix",
|
||||||
|
"git add"
|
||||||
|
],
|
||||||
|
"*.{vue,css,less,scss}": [
|
||||||
|
"stylelint --fix",
|
||||||
|
"git add"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"vant": "^2.2.16",
|
||||||
|
"vue": "^2.6.11",
|
||||||
|
"vue-template-compiler": "^2.6.11"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@vant/cli": "^2.0.0",
|
||||||
|
"babel-plugin-import": "^1.13.0",
|
||||||
|
"vant": "^2.2.16",
|
||||||
|
"vue": "^2.6.11",
|
||||||
|
"vue-template-compiler": "^2.6.11"
|
||||||
|
},
|
||||||
|
"eslintConfig": {
|
||||||
|
"root": true,
|
||||||
|
"extends": [
|
||||||
|
"@vant"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"stylelint": {
|
||||||
|
"extends": [
|
||||||
|
"@vant/stylelint-config"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"prettier": {
|
||||||
|
"singleQuote": true
|
||||||
|
},
|
||||||
|
"browserslist": [
|
||||||
|
"Android >= 4.0",
|
||||||
|
"iOS >= 8"
|
||||||
|
]
|
||||||
|
}
|
49
packages/vant-cli/generators/src/my-button/README.md
Normal file
49
packages/vant-cli/generators/src/my-button/README.md
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
# MyButton 按钮
|
||||||
|
|
||||||
|
### 介绍
|
||||||
|
|
||||||
|
MyButton 是一个示例按钮组件
|
||||||
|
|
||||||
|
### 引入
|
||||||
|
|
||||||
|
``` javascript
|
||||||
|
import Vue from 'vue';
|
||||||
|
import { MyButton } from 'demo-ui';
|
||||||
|
|
||||||
|
Vue.use(MyButton);
|
||||||
|
```
|
||||||
|
|
||||||
|
## 代码演示
|
||||||
|
|
||||||
|
### 基础用法
|
||||||
|
|
||||||
|
```html
|
||||||
|
<my-button type="primary" />
|
||||||
|
```
|
||||||
|
|
||||||
|
### 自定义颜色
|
||||||
|
|
||||||
|
```html
|
||||||
|
<my-button color="#03a9f4" />
|
||||||
|
```
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
### Props
|
||||||
|
|
||||||
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
||||||
|
|------|------|------|------|------|
|
||||||
|
| type | 按钮类型 | *string* | `primary` | - |
|
||||||
|
| color | 按钮颜色 | *string* | - | 1.0.0 |
|
||||||
|
|
||||||
|
### Events
|
||||||
|
|
||||||
|
| 事件名 | 说明 | 回调参数 |
|
||||||
|
|------|------|------|
|
||||||
|
| click | 点击时触发 | event: Event |
|
||||||
|
|
||||||
|
### Slots
|
||||||
|
|
||||||
|
| 名称 | 说明 |
|
||||||
|
|------|------|
|
||||||
|
| default | 默认插槽 |
|
11
packages/vant-cli/generators/src/my-button/demo/index.vue
Normal file
11
packages/vant-cli/generators/src/my-button/demo/index.vue
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<template>
|
||||||
|
<demo-section>
|
||||||
|
<demo-block title="基础用法">
|
||||||
|
<my-button type="primary" style="margin-left: 15px;">按钮</my-button>
|
||||||
|
</demo-block>
|
||||||
|
|
||||||
|
<demo-block title="自定义颜色">
|
||||||
|
<my-button color="#03a9f4" style="margin-left: 15px;">按钮</my-button>
|
||||||
|
</demo-block>
|
||||||
|
</demo-section>
|
||||||
|
</template>
|
3
packages/vant-cli/generators/src/my-button/index.less
Normal file
3
packages/vant-cli/generators/src/my-button/index.less
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
.test {
|
||||||
|
color: red;
|
||||||
|
}
|
39
packages/vant-cli/generators/src/my-button/index.vue
Normal file
39
packages/vant-cli/generators/src/my-button/index.vue
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<template>
|
||||||
|
<van-button :type="type" :color="color" class="my-button">
|
||||||
|
<slot />
|
||||||
|
</van-button>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { Button } from 'vant';
|
||||||
|
import MyIcon from '../my-icon';
|
||||||
|
import { foo } from './utils';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'my-button',
|
||||||
|
|
||||||
|
components: {
|
||||||
|
[MyIcon.name]: MyIcon,
|
||||||
|
[Button.name]: Button
|
||||||
|
},
|
||||||
|
|
||||||
|
props: {
|
||||||
|
color: String,
|
||||||
|
type: {
|
||||||
|
type: String,
|
||||||
|
default: 'primary'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
foo
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="less">
|
||||||
|
.my-button {
|
||||||
|
min-width: 120px;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
</style>
|
@ -0,0 +1,3 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`render demo button 1`] = `<button class="my-button van-button van-button--primary van-button--normal"></button>`;
|
@ -0,0 +1,7 @@
|
|||||||
|
import { mount } from '@vue/test-utils';
|
||||||
|
import DemoButton from '..';
|
||||||
|
|
||||||
|
test('render demo button', () => {
|
||||||
|
const wrapper = mount(DemoButton);
|
||||||
|
expect(wrapper).toMatchSnapshot();
|
||||||
|
});
|
3
packages/vant-cli/generators/src/my-button/utils.ts
Normal file
3
packages/vant-cli/generators/src/my-button/utils.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export function foo() {
|
||||||
|
return 'bar';
|
||||||
|
}
|
49
packages/vant-cli/generators/src/my-cell/README.md
Normal file
49
packages/vant-cli/generators/src/my-cell/README.md
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
# MyCell 单元格
|
||||||
|
|
||||||
|
### 介绍
|
||||||
|
|
||||||
|
MyCell 是一个示例单元格组件
|
||||||
|
|
||||||
|
### 引入
|
||||||
|
|
||||||
|
``` javascript
|
||||||
|
import Vue from 'vue';
|
||||||
|
import { MyCell } from 'demo-ui';
|
||||||
|
|
||||||
|
Vue.use(MyCell);
|
||||||
|
```
|
||||||
|
|
||||||
|
## 代码演示
|
||||||
|
|
||||||
|
### 基础用法
|
||||||
|
|
||||||
|
```html
|
||||||
|
<my-cell title="单元格" />
|
||||||
|
```
|
||||||
|
|
||||||
|
### 显示箭头
|
||||||
|
|
||||||
|
```html
|
||||||
|
<my-cell title="单元格" is-link />
|
||||||
|
```
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
### Props
|
||||||
|
|
||||||
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
||||||
|
|------|------|------|------|------|
|
||||||
|
| title | 单元格标题 | *string* | `-` | - |
|
||||||
|
| is-link | 是否为可点击单元格 | *boolean* | `false` | - |
|
||||||
|
|
||||||
|
### Events
|
||||||
|
|
||||||
|
| 事件名 | 说明 | 回调参数 |
|
||||||
|
|------|------|------|
|
||||||
|
| click | 点击时触发 | event: Event |
|
||||||
|
|
||||||
|
### Slots
|
||||||
|
|
||||||
|
| 名称 | 说明 |
|
||||||
|
|------|------|
|
||||||
|
| default | 默认插槽 |
|
11
packages/vant-cli/generators/src/my-cell/demo/index.vue
Normal file
11
packages/vant-cli/generators/src/my-cell/demo/index.vue
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<template>
|
||||||
|
<demo-section>
|
||||||
|
<demo-block title="基础用法">
|
||||||
|
<my-cell title="单元格" />
|
||||||
|
</demo-block>
|
||||||
|
|
||||||
|
<demo-block title="显示箭头">
|
||||||
|
<my-cell title="单元格" is-link />
|
||||||
|
</demo-block>
|
||||||
|
</demo-section>
|
||||||
|
</template>
|
14
packages/vant-cli/generators/src/my-cell/index.jsx
Normal file
14
packages/vant-cli/generators/src/my-cell/index.jsx
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { Cell } from 'vant';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'my-cell',
|
||||||
|
|
||||||
|
props: {
|
||||||
|
title: String,
|
||||||
|
isLink: Boolean
|
||||||
|
},
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return <Cell class="my-cell" title={this.title} isLink={this.isLink} />;
|
||||||
|
}
|
||||||
|
};
|
8
packages/vant-cli/generators/src/my-cell/index.less
Normal file
8
packages/vant-cli/generators/src/my-cell/index.less
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
.my-cell {
|
||||||
|
padding: 16px;
|
||||||
|
font-weight: 500;
|
||||||
|
|
||||||
|
.van-cell__value {
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
}
|
37
packages/vant-cli/generators/src/my-icon/README.md
Normal file
37
packages/vant-cli/generators/src/my-icon/README.md
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
# MyIcon 图标
|
||||||
|
|
||||||
|
### 介绍
|
||||||
|
|
||||||
|
MyIcon 是一个示例图标组件
|
||||||
|
|
||||||
|
### 引入
|
||||||
|
|
||||||
|
``` javascript
|
||||||
|
import Vue from 'vue';
|
||||||
|
import { MyIcon } from 'demo-ui';
|
||||||
|
|
||||||
|
Vue.use(MyIcon);
|
||||||
|
```
|
||||||
|
|
||||||
|
## 代码演示
|
||||||
|
|
||||||
|
### 基础用法
|
||||||
|
|
||||||
|
```html
|
||||||
|
<my-icon name="success" />
|
||||||
|
```
|
||||||
|
|
||||||
|
### 显示箭头
|
||||||
|
|
||||||
|
```html
|
||||||
|
<my-icon name="success" dot />
|
||||||
|
```
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
### Props
|
||||||
|
|
||||||
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
||||||
|
|------|------|------|------|------|
|
||||||
|
| name | 图标名称 | *string* | `-` | - |
|
||||||
|
| dot | 是否展示红点 | *boolean* | `false` | - |
|
19
packages/vant-cli/generators/src/my-icon/demo/index.vue
Normal file
19
packages/vant-cli/generators/src/my-icon/demo/index.vue
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<template>
|
||||||
|
<demo-section>
|
||||||
|
<demo-block title="基础用法">
|
||||||
|
<my-icon name="success" />
|
||||||
|
</demo-block>
|
||||||
|
|
||||||
|
<demo-block title="显示红点">
|
||||||
|
<my-icon name="success" dot />
|
||||||
|
</demo-block>
|
||||||
|
</demo-section>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style lang="less">
|
||||||
|
.demo-my-icon {
|
||||||
|
.my-icon {
|
||||||
|
margin-left: 16px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
14
packages/vant-cli/generators/src/my-icon/index.jsx
Normal file
14
packages/vant-cli/generators/src/my-icon/index.jsx
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { Icon } from 'vant';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'my-icon',
|
||||||
|
|
||||||
|
props: {
|
||||||
|
name: String,
|
||||||
|
dot: Boolean
|
||||||
|
},
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return <Icon name={this.name} dot={this.dot} class="my-icon" />;
|
||||||
|
}
|
||||||
|
};
|
3
packages/vant-cli/generators/src/my-icon/index.less
Normal file
3
packages/vant-cli/generators/src/my-icon/index.less
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
.my-icon {
|
||||||
|
font-size: 32px;
|
||||||
|
}
|
5
packages/vant-cli/generators/src/style/base.less
Normal file
5
packages/vant-cli/generators/src/style/base.less
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
@import "./var.less";
|
||||||
|
|
||||||
|
body {
|
||||||
|
color: @text-color;
|
||||||
|
}
|
2
packages/vant-cli/generators/src/style/var.less
Normal file
2
packages/vant-cli/generators/src/style/var.less
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
@primary-color: #f44;
|
||||||
|
@text-color: #4a4a4a;
|
49
packages/vant-cli/generators/vant.config.js
Normal file
49
packages/vant-cli/generators/vant.config.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
module.exports = {
|
||||||
|
name: 'demo-ui',
|
||||||
|
build: {
|
||||||
|
site: {
|
||||||
|
publicPath: '/demo-ui/'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
site: {
|
||||||
|
title: 'Demo UI',
|
||||||
|
logo: 'https://img.yzcdn.cn/vant/logo.png',
|
||||||
|
nav: [
|
||||||
|
{
|
||||||
|
title: '开发指南',
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
path: 'home',
|
||||||
|
title: '介绍'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'quickstart',
|
||||||
|
title: '快速上手'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '基础组件',
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
path: 'my-button',
|
||||||
|
title: 'MyButton 按钮'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'my-icon',
|
||||||
|
title: 'MyIcon 图标'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '展示组件',
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
path: 'my-cell',
|
||||||
|
title: 'MyCell 单元格'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user