Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support vue tech stack #1922

Merged
merged 39 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
6d63caa
feat: add vue tech stack support
jeffwcx Sep 27, 2023
34698d8
docs: techstack related
jeffwcx Sep 28, 2023
2ba1b73
feat: add external api parser support
jeffwcx Oct 29, 2023
7c2660b
docs: api table support related
jeffwcx Oct 29, 2023
6ae0f0c
feat: add an option for changing tsconfig path
jeffwcx Oct 29, 2023
2776eee
refactor: give watcher creation rights to BaseAtomAssetsParser
jeffwcx Oct 29, 2023
15f3093
chore: merge remote branch 'dumi/master'
jeffwcx Oct 30, 2023
1f62fe9
docs: Update README.md
jeffwcx Oct 30, 2023
5b362cb
fix: type of function signature parameter needs to be string
jeffwcx Oct 31, 2023
9c8fb92
refactor: code structure adjustment
jeffwcx Nov 9, 2023
f32692b
fix: babel-plugin-iife type error
jeffwcx Nov 9, 2023
6f39fa1
chore: use umi prebundled babel dependencies
jeffwcx Nov 9, 2023
ac81c9d
Merge remote-tracking branch 'upstream/master'
jeffwcx Jan 3, 2024
92b1f64
feat: add onBlockLoad method for IDumiTechStack
jeffwcx Jan 3, 2024
0019aad
refactor: replace `babel-plugin-iife` with` transformDemoCode`
jeffwcx Jan 3, 2024
8008c6c
refactor: consolidate runtime related APIs into `IDumiTechStack`
jeffwcx Jan 4, 2024
48c7c3d
feat: add createApiParser
jeffwcx Jan 5, 2024
965303d
fix: createApiParser
jeffwcx Jan 5, 2024
c70cf88
docs: techstack related
jeffwcx Jan 7, 2024
9a1732d
refactor: add bundle-utils
jeffwcx Jan 7, 2024
4f4d6fd
fix: support html2sketch
jeffwcx Jan 7, 2024
4f917e9
fix: html comments FrontMatter
jeffwcx Jan 7, 2024
79455c7
Merge remote-tracking branch 'upstream/feature/2.3.0'
jeffwcx Jan 8, 2024
db314ff
feat: incorporate live demo into the techstack
jeffwcx Jan 11, 2024
90efd70
Merge remote-tracking branch 'upstream/feature/2.3.0'
jeffwcx Jan 11, 2024
7292825
fix: iframe mode
jeffwcx Jan 11, 2024
1e6c37d
fix: issue introduced by @vue/babel-plugin-jsx
jeffwcx Jan 11, 2024
369da5f
refactor: new design of techstack runtime options
jeffwcx Jan 19, 2024
1cf5168
Merge remote-tracking branch 'upstream/feature/2.3.0'
jeffwcx Jan 19, 2024
acd379c
fix: live demo loading
jeffwcx Jan 19, 2024
e619561
Merge remote-tracking branch 'upstream/feature/2.3.0'
jeffwcx Jan 23, 2024
68df182
feat: check vue version
jeffwcx Jan 25, 2024
034da65
refactor: flatten options of preset-vue
jeffwcx Jan 25, 2024
75a3d3b
Merge remote-tracking branch 'upstream/feature/2.3.0'
jeffwcx Jan 25, 2024
995322f
refactor: remove id
jeffwcx Jan 25, 2024
6682bf1
docs: preset-vue and techstack
jeffwcx Jan 25, 2024
b9402bb
refactor: remove id of IDemoData
jeffwcx Jan 25, 2024
ad559ce
fix: demo error
jeffwcx Jan 25, 2024
bc87ccc
fix: shoud pass id to useRenderer
jeffwcx Feb 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/dist
/compiled
/theme-default
/runtime
jeffwcx marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 12 additions & 0 deletions assets-types/typings/atom/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ export interface AtomComponentAsset extends AtomBaseAsset {
* props definition of component
*/
propsConfig: ObjectPropertySchema;
/**
* slots definition of component
*/
slotsConfig?: ObjectPropertySchema;
/**
* events definition of component
*/
eventsConfig?: ObjectPropertySchema;
/**
* methods definition of component
*/
methodsConfig?: ObjectPropertySchema;

/**
* available parent components of component
Expand Down
16 changes: 16 additions & 0 deletions assets-types/typings/atom/props/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,29 @@ export interface ObjectPropertySchema extends BasePropertySchema {
required?: string[];
}

export interface FunctionArgSchema {
key: string;
type: PropertySchema | string;
hasQuestionToken?: boolean;
}

export interface FunctionPropertySchema extends BasePropertySchema {
type: 'function';
signature: {
isAsync: boolean;
returnType: PropertySchema;
arguments: FunctionArgSchema[];
};
}

/**
* prop definition
*/
export type PropertySchema =
| BasePropertySchema
| ObjectPropertySchema
| ArrayPropertySchema
| FunctionPropertySchema
| StringPropertySchema
| NumberPropertySchema
| BooleanPropertySchema;
4 changes: 4 additions & 0 deletions assets-types/typings/example.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ export interface ExampleBlockAsset extends ExampleBaseAsset {
value: string;
}
>;
/**
* Entry file name, you can find the relevant entry file content from `dependencies`
*/
entry: string;
jeffwcx marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
27 changes: 26 additions & 1 deletion docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default () => '我会被编译,展示为组件';

### apiParser

- 类型:`{ unpkgHost?: 'https://unpkg.com'; resolveFilter?: (args: { id: string; ids: string; type: 'COMPONENT' | 'FUNCTION' }) => boolean }`
- 类型:`{ unpkgHost?: 'https://unpkg.com'; resolveFilter?: (args: { id: string; ids: string; type: 'COMPONENT' | 'FUNCTION' }) => boolean; customParser: ({ entryFile: string; resolveDir: string }) => BaseAtomAssetsParser }`
jeffwcx marked this conversation as resolved.
Show resolved Hide resolved
- 默认值:`undefined`

启用 API 自动解析功能,开启后可使用 `API` 全局组件,参考[指南 - 自动 API 表格](../guide/auto-api-table.md)。
Expand All @@ -98,6 +98,8 @@ export default () => '我会被编译,展示为组件';

`resolveFilter` 配置项用于跳过指定原子资产的解析以提升性能。部分组件属性或函数签名存在多层嵌套,甚至是循环引用时,会导致解析结果巨大,此时可以通过该配置项跳过解析。

`customParser` 配置项主要提供外部解析器支持,用户通过配置该项可以实现对其他框架 API 解析的支持,具体实现方法参考[插件 - 添加技术栈 - API Table 支持](../plugin/techstack.md#api-table-支持)

### autoAlias

- 类型:`boolean`
Expand Down Expand Up @@ -203,6 +205,29 @@ export default () => (
);
```

### resolveDemoModule
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的思路是否可以改成在 techStack 上新增 getEntryScriptCode 方法,该方法是可选的,Vue 技术栈会提取 .vue 中的 script 并返回,rehypeDemo 再将内容作为 entryPointCode 传给 parseBlockAsset 解析器

好处是不新增配置项,复杂度都集中在 techStack 内部

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已经在本地实现了,但是具体的传递模式还是得再讨论讨论


- 类型:`Record<string, { transform: ((text: string) => string) | 'html', loader: Loader }>`
- 默认值:`undefined`

在分析依赖和处理资源时如何解析 Demo 模块

`transform`可以是一个函数或一个`html`字面量。如果指定为`html`,程序将在内部提取所有`script`标签中内容。

`loader` 将指定模块类型来处理`transform`返回的内容。

以 Vue 为例,为了对.vue 文件进行依赖分析,可以这样配置:

```ts
export default {
resolveDemoModule: {
'.vue': { transform: 'html', loader: 'tsx' },
},
};
```

这意味着 vue 文件将被处理为 html,并且脚本中的内容将被提取出来,然后这些内容将作为 tsx 文件进行依赖分析。

## 主题配置项

通过 `themeConfig` 可配置传递给主题的配置项:
Expand Down
162 changes: 162 additions & 0 deletions docs/guide/vue-api-table.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
---
title: 自动 API 表格
group:
title: 使用vue
order: 1
order: 2
---

# Vue 的自动 API 表格

dumi 支持 Vue 组件的自动 API 表格生成,用户只需配置`entryFile`即可开始 API 表格的使用:

```ts
import { defineConfig } from 'dumi';

export default defineConfig({
resolve: {
// 配置入口文件路径,API 解析将从这里开始
entryFile: './src/index.ts',
},
});
```

不需要配置`apiParser`,因为`dumi-plugin-vue`已经自动配置了`customParser`。

## tsconfig 配置

Vue 组件的元信息提取主要使用 TypeScript 的 TypeChecker, 所以配置`tsconfig.json`时请务必将`strictNullChecks`设为`false`

```json
{
"compilerOptions": {
"strictNullChecks": false
}
}
```

如果项目中一定要使用`strictNullChecks`,你也可以为 Vue 解析专门配置一个`tsconfig.vue.json`文件

```ts
// .dumirc.ts
import * as path from 'path';
export default {
plugins: ['dumi-plugin-vue'],
themeConfig: {
vue: {
parserOptions: {
tsconfigPath: path.resolve(__dirname, './tsconfig.vue.json');
jeffwcx marked this conversation as resolved.
Show resolved Hide resolved
},
},
},
};

```

## JSDoc 编写

:::warning
推荐在 props 中定义组件的事件,这样可以获得完整的 JSDoc 支持
:::

插件主要支持以下 JSDoc 标签:

### @description

属性描述,可以在`props`, `slots`, `methods`中使用,例如:

```ts
export default defineComponent({
props: {
/**
* @description 标题
*/
title: {
type: String,
default: '',
},
},
});
```

### @default

当 prop 的`default`选项为函数时,`default`值不会被解析,这时可以使用`@default`来声明它

```ts
defineComponent({
props: {
/**
* @default {}
*/
foo: {
default() {
return {};
},
},
},
});
```

### @exposed/@expose

:::warning
组件实例的方法或是属性的暴露,必须使用@exposed/@expose 标识,单文件组件也不例外
:::

```ts
defineExpose({
/**
* @exposed
*/
focus() {},
});
```

JSX/TSX 的组件方法暴露比较麻烦,需要用户另外声明

```ts
export default Button as typeof Button & {
new (): {
/**
* The signature of the expose api should be obtained from here
* @exposed
*/
focus: () => void;
};
};
```

### @ignore

被`@ignore`标记的属性就会被忽略,不会被解析

## Markdown 编写

在 Markdown 文件编写时

```md
<API id="Button"></API>
```

只显示 Vue 组件的`props`部分,完整的显示应该这样编写:

```md
## Button API

### Props

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

### Slots

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

### Events

<API id="Button" type="events"></API>

### Methods

<API id="Button" type="methods"></API>
```
92 changes: 92 additions & 0 deletions docs/guide/vue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---
title: 安装插件
group:
title: 使用vue
order: 1
order: 1
---

# 安装 Vue 支持插件

dumi 中对 Vue 的支持主要通过`dumi-plugin-vue`插件实现, 目前只支持 Vue3
jeffwcx marked this conversation as resolved.
Show resolved Hide resolved

## 安装

```bash
pnpm i -D dumi-plugin-vue
```

## 配置

```ts
// .dumirc.ts
export default {
plugins: ['dumi-plugin-vue'],
};
```

## 插件选项

### parserOptions

Vue 组件元数据解析选项

例如,以下配置可以使得名称为`InternalType`的类型跳过检查

```ts
// .dumirc.ts
export default {
plugins: ['dumi-plugin-vue'],
themeConfig: {
vue: {
parserOptions: {
checkerOptions: {
schema: { ignore: ['InternalType'] },
},
},
},
},
};
```

默认情况下,从`node_modules`中引入所有类型不会被解析,这样可以有效避免元信息冗余,你也可以通过配置`exclude`来定制化类型引入

```ts
// .dumirc.ts
export default {
plugins: ['dumi-plugin-vue'],
themeConfig: {
vue: {
parserOptions: {
checkerOptions: {
schema: { exclude: [/node_modules/, /mylib/] },
},
},
},
},
};
```

### globalInject

全局脚本注入

Vue 的 UI 框架通常都有全局导入的功能,以 ElementPlus 为例,我们可以通过以下配置将 ElementPlus 全局导入

```ts
// .dumirc.ts
export default {
plugins: ['dumi-plugin-vue'],
themeConfig: {
vue: {
globalInject: {
imports: `
import ElementPlus from 'element-plus';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个不建议通过插件配置来增加导入,可以引导用户使用 global.ts: https://d.umijs.org/guide/project-structure#%E5%85%A8%E5%B1%80%E8%84%9A%E6%9C%AC

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

使用global.ts不一定可行,主要是因为这个是注入到demo当中的,不是应用当中的

import 'element-plus/dist/index.css';
`,
statements: `app.use(ElementPlus, { size: 'small', zIndex: 3000 });`,
},
},
},
};
```
Loading
Loading