Skip to content

Commit

Permalink
feat: add basic vue lib template
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwcx committed Sep 20, 2024
1 parent d922cb5 commit b6ad46a
Show file tree
Hide file tree
Showing 23 changed files with 395 additions and 0 deletions.
12 changes: 12 additions & 0 deletions suites/boilerplate/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default async ({
choices: [
{ title: 'Static Site', value: 'site' },
{ title: 'React Library', value: 'react' },
{ title: 'Vue Library', value: 'vue' },
{ title: 'Theme Package', value: 'theme' },
],
initial: 0,
Expand Down Expand Up @@ -75,6 +76,7 @@ export default async ({
const descriptions = {
site: 'A static site based on dumi',
react: 'A react library developed with dumi',
vue: 'A vue library developed with dumi',
theme: 'A theme package for dumi',
};
const questions: prompts.PromptObject[] = [
Expand Down Expand Up @@ -125,6 +127,16 @@ export default async ({
return 'NPM package name is required';
},
});
} else if (type === 'vue') {
questions.unshift({
name: 'name',
type: 'text',
message: 'Input NPM package name',
validate: (value: string) => {
if (value && value.trim()) return true;
return 'NPM package name is required';
},
});
}

const generator = new BaseGenerator({
Expand Down
13 changes: 13 additions & 0 deletions suites/boilerplate/templates/vue/.dumirc.ts.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineConfig } from 'dumi';

export default defineConfig({
apiParser: {},
resolve: {
entryFile: 'src/index.ts',
},
outputPath: 'docs-dist',
themeConfig: {
name: '{{{ name }}}',
},
presets: [require.resolve('@dumijs/preset-vue')],
});
13 changes: 13 additions & 0 deletions suites/boilerplate/templates/vue/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
14 changes: 14 additions & 0 deletions suites/boilerplate/templates/vue/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
extends: require.resolve('@umijs/lint/dist/config/eslint'),
parser: 'vue-eslint-parser',
parserOptions: {
parser: '@typescript-eslint/parser',
sourceType: 'module',
ecmaVersion: 2020,
ecmaFeatures: {
jsx: true,
},
},
extends: ['plugin:vue/vue3-recommended'],
rules: {},
};
6 changes: 6 additions & 0 deletions suites/boilerplate/templates/vue/.fatherrc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from 'father';

export default defineConfig({
// more father config: https://github.com/umijs/father/blob/master/docs/config.md
esm: { output: 'dist' },
});
6 changes: 6 additions & 0 deletions suites/boilerplate/templates/vue/.gitignore.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
/dist
.dumi/tmp
.dumi/tmp-test
.dumi/tmp-production
.DS_Store
4 changes: 4 additions & 0 deletions suites/boilerplate/templates/vue/.husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx commitlint --edit "${1}"
4 changes: 4 additions & 0 deletions suites/boilerplate/templates/vue/.husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
2 changes: 2 additions & 0 deletions suites/boilerplate/templates/vue/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/dist
*.yaml
19 changes: 19 additions & 0 deletions suites/boilerplate/templates/vue/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
pluginSearchDirs: false,
plugins: [
require.resolve('prettier-plugin-organize-imports'),
require.resolve('prettier-plugin-packagejson'),
],
printWidth: 80,
proseWrap: 'never',
singleQuote: true,
trailingComma: 'all',
overrides: [
{
files: '*.md',
options: {
proseWrap: 'preserve',
},
},
],
};
3 changes: 3 additions & 0 deletions suites/boilerplate/templates/vue/.stylelintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@umijs/lint/dist/config/stylelint"
}
21 changes: 21 additions & 0 deletions suites/boilerplate/templates/vue/LICENSE.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) {{{ author }}}

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
43 changes: 43 additions & 0 deletions suites/boilerplate/templates/vue/README.md.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# {{{ name }}}

[![NPM version](https://img.shields.io/npm/v/{{{ name }}}.svg?style=flat)](https://npmjs.org/package/{{{ name }}})
[![NPM downloads](http://img.shields.io/npm/dm/{{{ name }}}.svg?style=flat)](https://npmjs.org/package/{{{ name }}})

{{{ description }}}

## Usage

TODO

## Options

TODO

## Development

```bash
# install dependencies
$ {{ npmClient }} install

# develop library by docs demo
$ {{ npmClient }} start

# build library source code
$ {{ npmClient }} run build

# build library source code in watch mode
$ {{ npmClient }} run build:watch

# build docs
$ {{ npmClient }} run docs:build

# Locally preview the production build.
$ {{ npmClient }} run docs:preview

# check your project for potential problems
$ {{ npmClient }} run doctor
```

## LICENSE

MIT
1 change: 1 addition & 0 deletions suites/boilerplate/templates/vue/docs/guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a guide example.
22 changes: 22 additions & 0 deletions suites/boilerplate/templates/vue/docs/index.md.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
hero:
title: library
description: {{{ description }}}
actions:
- text: Hello
link: /
- text: Vue
link: /
features:
- title: Hello
emoji: 💎
description: Put hello description here
- title: Vue
emoji: 🌈
description: Put world description here
- title: '!'
emoji: 🚀
description: Put ! description here
---

{{{ name }}}
80 changes: 80 additions & 0 deletions suites/boilerplate/templates/vue/package.json.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"name": "{{{ name }}}",
"version": "0.0.1",
"description": "{{{ description }}}",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"start": "npm run dev",
"dev": "dumi dev",
"build": "father build",
"build:watch": "father dev",
"docs:build": "dumi build",
"docs:preview": "dumi preview",
"prepare": "husky install && dumi setup",
"doctor": "father doctor",
"lint": "npm run lint:es && npm run lint:css",
"lint:css": "stylelint \"{src,test}/**/*.{css,less}\"",
"lint:es": "eslint \"{src,test}/**/*.{js,jsx,ts,tsx}\"",
"prepublishOnly": "father doctor && npm run build"
},
"authors": [{{#author}}
"{{{ author }}}"
{{/author}}],
"repository": {
"type": "git"
},
"license": "MIT",
"files": [
"dist"
],
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"lint-staged": {
"*.{md,json}": [
"prettier --write --no-error-on-unmatched-pattern"
],
"*.{css,less}": [
"stylelint --fix",
"prettier --write"
],
"*.{js,jsx}": [
"eslint --fix",
"prettier --write"
],
"*.{ts,tsx}": [
"eslint --fix",
"prettier --parser=typescript --write"
]
},
"publishConfig": {
"access": "public"
},
"peerDependencies": {
"vue": ">=3.3.0"
},
"devDependencies": {
"@commitlint/cli": "^17.1.2",
"@commitlint/config-conventional": "^17.1.0",
"@dumijs/preset-vue": "^2",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@umijs/lint": "^4.0.0",
"dumi": "{{{ version }}}",
"eslint": "^8.23.0",
"eslint-plugin-vue": "^9.17.0",
"father": "^4.1.0",
"husky": "^8.0.1",
"lint-staged": "^13.0.3",
"prettier": "^2.7.1",
"prettier-plugin-organize-imports": "^3.0.0",
"prettier-plugin-packagejson": "^2.2.18",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"stylelint": "^14.9.1",
"vue": "^3.4.0"
}
}
47 changes: 47 additions & 0 deletions suites/boilerplate/templates/vue/src/Bar/RootBar.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<template>
<span
@click="handleClick"
>
<template v-if="icon">
{{icon}}
</template>
<slot v-else name="icon" /> <slot />
</span>
</template>

<style lang="css" scoped>
span {
border: 1px solid red;
border-radius: 4px;
padding: 4px;
}
</style>

<script setup lang="ts">
import { VNodeChild } from 'vue';
defineProps<{
/**
* 图标字符
*/
icon?: string;
}>();
defineSlots<{
/**
* 图标插槽
* @alpha
*/
icon?: VNodeChild;
default: VNodeChild,
}>();
const emit = defineEmits<{
(e: 'click', event: MouseEvent): void
}>();
function handleClick(e: MouseEvent) {
emit('click', e);
}
</script>
39 changes: 39 additions & 0 deletions suites/boilerplate/templates/vue/src/Bar/index.md.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Bar

This is an example component of Vue SFC.

```vue
<script setup>
import { ref } from 'vue';
import { Bar } from '{{{ name }}}';
const color = ref('red');
</script>

<template>
<p class="greeting">
<Bar icon="🤙">Hello Vue!</Bar>
</p>
</template>

<style>
.greeting {
color: v-bind('color');
font-size: 16px;
font-weight: bold;
}
</style>
```
## Bar API

### Props

<API id="Bar" type="props"></API>

### Slots

<API id="Bar" type="slots"></API>

### Events

<API id="Bar" type="events"></API>
1 change: 1 addition & 0 deletions suites/boilerplate/templates/vue/src/Bar/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as Bar } from './RootBar.vue';
9 changes: 9 additions & 0 deletions suites/boilerplate/templates/vue/src/Foo/index.md.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Foo

This is an example component of Vue JSX.

```jsx
import { Foo } from '{{{ name }}}';

export default () => <Foo title="Hello vue!" />
```
Loading

0 comments on commit b6ad46a

Please sign in to comment.