From 2dc4e463fdd7bd9e8f48ba9208815c8352591e30 Mon Sep 17 00:00:00 2001 From: qiang Date: Thu, 12 May 2022 10:59:16 +0800 Subject: [PATCH] chore(ci): optimizing the generated code hint file (#7634) --- docs/en-US/component/config-provider.md | 4 ++-- docs/en-US/component/select-v2.md | 4 ++-- docs/en-US/component/tree-v2.md | 8 +++---- internal/build/src/tasks/helper.ts | 30 +++++++++++++++++-------- 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/docs/en-US/component/config-provider.md b/docs/en-US/component/config-provider.md index f6b538c6d8..e1aaae8074 100644 --- a/docs/en-US/component/config-provider.md +++ b/docs/en-US/component/config-provider.md @@ -51,13 +51,13 @@ In this section, you can learn how to use Config Provider to provide experimenta | message | message related configuration, [see the following table](#message-attributes) | MessageGlobalConfig | - | see the following table | | experimental-features | features at experimental stage to be added, all features are default to be set to false | Object | - | - | -## Button Attributes +## Button Attribute | Attribute | Description | Type | Accepted Values | Default | | --------------- | ----------------------------------------------------------- | ------- | --------------- | ------- | | autoInsertSpace | automatically insert a space between two chinese characters | boolean | - | false | -## Message Attributes +## Message Attribute | Attribute | Description | Type | Accepted Values | Default | | --------- | --------------------------------------------------------------------- | ------ | --------------- | ------- | diff --git a/docs/en-US/component/select-v2.md b/docs/en-US/component/select-v2.md index bb73988be6..4db73ee6cc 100644 --- a/docs/en-US/component/select-v2.md +++ b/docs/en-US/component/select-v2.md @@ -127,7 +127,7 @@ select-v2/remote-search ## SelectV2 Attributes -| Param | Description | Type | Accepted Values | Default | +| Attribute | Description | Type | Accepted Values | Default | | --------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- | ------------------- | ------------- | | model-value / v-model | biding value | string / number / boolean / object | — | — | | multiple | is multiple | boolean | — | false | @@ -178,7 +178,7 @@ select-v2/remote-search ## SelectV2 Slots -| name | Description | +| Name | Description | | ------- | ----------------------------- | | default | Option renderer | | empty | content when options is empty | diff --git a/docs/en-US/component/tree-v2.md b/docs/en-US/component/tree-v2.md index adc9426b5e..1f4b38e3a7 100644 --- a/docs/en-US/component/tree-v2.md +++ b/docs/en-US/component/tree-v2.md @@ -67,7 +67,7 @@ tree-v2/filter ::: -## Attributes +## TreeV2 Attributes | Attribute | Description | Type | Default | | --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------- | @@ -95,7 +95,7 @@ tree-v2/filter | children | specify which node object is used as the node's subtree | string | children | | disabled | specify which key of node object represents if node's checkbox is disabled | string | disabled | -## Method +## TreeV2 Method `Tree` has the following method, which returns the currently selected array of nodes. | Method | Description | Parameters | @@ -112,7 +112,7 @@ tree-v2/filter | setCurrentKey | set highlighted node by key | `(key: TreeKey)` | | setData | When the data is very large, using reactive data will cause the poor performance, so we provide a way to avoid this situation | `(data: TreeData)` | -## Events +## TreeV2 Events | Event Name | Description | Parameters | | ---------------- | ---------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- | @@ -124,7 +124,7 @@ tree-v2/filter | node-expand | triggers when current node open | `(data: TreeNodeData, node: TreeNode)` | | node-collapse | triggers when current node close | `(data: TreeNodeData, node: TreeNode)` | -## Slots +## TreeV2 Slots | Name | Description | | ---- | ---------------------------------------------------------------------------------------------- | diff --git a/internal/build/src/tasks/helper.ts b/internal/build/src/tasks/helper.ts index fdf8ebe91a..9ba2e18d39 100644 --- a/internal/build/src/tasks/helper.ts +++ b/internal/build/src/tasks/helper.ts @@ -8,22 +8,27 @@ import { } from '@element-plus/build-utils' import type { TaskFunction } from 'gulp' -import type { InstallOptions } from 'components-helper' +import type { + ReAttribute, + ReComponentName, + ReDocUrl, + ReWebTypesSource, +} from 'components-helper' -const reComponentName: InstallOptions['reComponentName'] = (title: string) => +const reComponentName: ReComponentName = (title: string) => `el-${title .replace(/\B([A-Z])/g, '-$1') .replace(/[ ]+/g, '-') .toLowerCase()}` -const reDocUrl: InstallOptions['reDocUrl'] = (fileName, header) => { +const reDocUrl: ReDocUrl = (fileName, header) => { const docs = 'https://element-plus.org/en-US/component/' const _header = header ? header.replaceAll(/\s+/g, '-').toLowerCase() : '' return `${docs}${fileName}.html${_header ? '#' : ''}${_header}` } -const reWebTypesSource: InstallOptions['reWebTypesSource'] = (title) => { +const reWebTypesSource: ReWebTypesSource = (title) => { const symbol = `El${title .replaceAll(/-/g, ' ') .replaceAll(/^\w|\s+\w/g, (item) => { @@ -33,9 +38,11 @@ const reWebTypesSource: InstallOptions['reWebTypesSource'] = (title) => { return { symbol } } -const reAttribute: InstallOptions['reAttribute'] = (value, key) => { - const _value = value.match(/^\*\*(.*)\*\*$/) - const str = _value ? _value[1] : value +const reAttribute: ReAttribute = (value, key) => { + const str = value + .replace(/^\*\*(.*)\*\*$/, (_, item) => item) + .replace(/^`(.*)`$/, (_, item) => item) + .replaceAll(/.*<\/del>/g, '') if (key === 'Name' && /^(-|—)$/.test(str)) { return 'default' @@ -47,7 +54,12 @@ const reAttribute: InstallOptions['reAttribute'] = (value, key) => { } else if (key === 'Attribute' && /v-model/.test(str)) { return 'model-value' } else if (key === 'Attribute') { - return str.replace(/\B([A-Z])/g, '-$1').toLowerCase() + return str + .replaceAll(/\s*[\\*]\s*/g, '') + .replaceAll(/\s*<.*>\s*/g, '') + .replaceAll(/\s*\(.*\)\s*/g, '') + .replaceAll(/\B([A-Z])/g, '-$1') + .toLowerCase() } else if (key === 'Type') { return str .replace(/\s*\/\s*/g, '|') @@ -98,7 +110,7 @@ export const buildHelper: TaskFunction = (done) => { propsOptions: 'Accepted Values', eventsName: 'Event Name', tableRegExp: - '#+\\s+(.*\\s*Attributes|.*\\s*Events|.*\\s*Slots|.*\\s*Directives)\\s*\\n+(\\|?.+\\|.+)\\n\\|?\\s*:?-+:?\\s*\\|.+((\\n\\|?.+\\|.+)+)', + /#+\s+(.*\s*Attributes|.*\s*Events|.*\s*Slots|.*\s*Directives)\s*\n+(\|?.+\|.+)\n\|?\s*:?-+:?\s*\|.+((\n\|?.+\|.+)+)/g, }) done()