From 95feeb51082aa93031174c4bb2ed4c1ff811a657 Mon Sep 17 00:00:00 2001 From: tolking Date: Tue, 27 Apr 2021 23:26:44 +0800 Subject: [PATCH 1/4] docs: updata --- README.md | 15 +++++++++++++++ package.json | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4b14e30..164bfe8 100644 --- a/README.md +++ b/README.md @@ -238,6 +238,21 @@ name for directives header description name for directives header type +### defaultValSeparators + +- Type: `[string, string]` +- Default: `[', ', '.']` + +config the punctuation of description for vetur + +### subtagsMap + +- Type: `Record` + +config the subtags for vetur + +For example: `{ 'app-button-group': ['app-button'] }` + ### titleRegExp - Type: `string` (**This is a regular string.**) diff --git a/package.json b/package.json index a1c845d..79acced 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "components-helper", - "version": "1.0.2", + "version": "1.0.3", "description": "Based on the docs to provide code prompt files for vue component library", "main": "lib/index.js", "module": "lib/index.es.js", From 3b4a82565ad3ae130261f1d871e27924233018fb Mon Sep 17 00:00:00 2001 From: tolking Date: Thu, 29 Apr 2021 22:57:21 +0800 Subject: [PATCH 2/4] refactor: add reVeturDescription --- src/config.ts | 1 - src/type.ts | 8 ++++++- src/vetur.ts | 59 +++++++++++++++++++++++---------------------------- 3 files changed, 33 insertions(+), 35 deletions(-) diff --git a/src/config.ts b/src/config.ts index bfbfff0..331d2fc 100644 --- a/src/config.ts +++ b/src/config.ts @@ -14,7 +14,6 @@ const config: Config = { propsDescription: 'Description', propsOptions: 'Options', propsDefault: 'Default', - defaultValSeparators: [', ', '.'], separator: '/', events: 'events', eventsName: 'Name', diff --git a/src/type.ts b/src/type.ts index 0bc9490..f8c50ee 100644 --- a/src/type.ts +++ b/src/type.ts @@ -9,6 +9,12 @@ type ReAttribute = ( title: string, ) => string | undefined +type ReVeturDescription = ( + description?: string, + defaultValue?: string, + docUrl?: string, +) => string + interface OptionsConfig { entry: string outDir: string @@ -18,6 +24,7 @@ interface OptionsConfig { reComponentName?: ReComponentName reDocUrl?: ReDocUrl reAttribute?: ReAttribute + reVeturDescription?: ReVeturDescription } export interface Config { @@ -33,7 +40,6 @@ export interface Config { propsDescription: string propsOptions: string propsDefault: string - defaultValSeparators: [string, string] separator: string events: string eventsName: string diff --git a/src/vetur.ts b/src/vetur.ts index 73ef5bc..729bb4d 100644 --- a/src/vetur.ts +++ b/src/vetur.ts @@ -1,4 +1,4 @@ -import { getComponentsName, getDocUrl, checkArray } from './utils' +import { getComponentsName, getDocUrl, checkArray, isFunction } from './utils' import type { Options, NormalizeData, Tags, Props } from './type' function vetur( @@ -17,6 +17,8 @@ function vetur( separator, eventsName, eventsDescription, + reVeturDescription, + subtagsMap, } = options const tagsList = {} as Tags const propsList = {} as Props @@ -49,6 +51,7 @@ function vetur( const _item = item[propsName] if (_item) { + const docUrl = getDocUrl(options, fileName, props?.title, path) const _name = name + '/' + _item const _type = item[propsType] || '' const _options = item[propsOptions] @@ -56,19 +59,19 @@ function vetur( /string/i.test(_type) && _options ? _options.split(separator).map((item) => item.trim()) : undefined + const _description = isFunction(reVeturDescription) + ? reVeturDescription( + item[propsDescription], + item[propsDefault], + docUrl, + ) + : reDescription(item[propsDescription], item[propsDefault], docUrl) tagsProps.push(_item) propsList[_name] = { type: item[propsType], options: _optionsList, - description: reDescription( - options, - fileName, - item[propsDescription], - props?.title, - item[propsDefault], - path, - ), + description: _description, } } }) @@ -77,34 +80,29 @@ function vetur( const _item = item[eventsName] if (_item) { + const docUrl = getDocUrl(options, fileName, events?.title, path) const _name = name + '/' + _item + const _description = isFunction(reVeturDescription) + ? reVeturDescription(item[eventsDescription], undefined, docUrl) + : reDescription(item[eventsDescription], undefined, docUrl) tagsProps.push(_item) propsList[_name] = { type: 'event', - description: reDescription( - options, - fileName, - item[eventsDescription], - events?.title, - item[propsDefault], - path, - ), + description: _description, } } }) + const docUrl = getDocUrl(options, fileName, events?.title, path) + const _description = isFunction(reVeturDescription) + ? reVeturDescription(description, undefined, docUrl) + : reDescription(description, undefined, docUrl) + tagsList[name] = { attributes: checkArray(tagsProps), - subtags: options.subtagsMap[name], - description: reDescription( - options, - fileName, - description, - title, - undefined, - path, - ), + subtags: subtagsMap[name], + description: _description, } } @@ -112,19 +110,14 @@ function vetur( } function reDescription( - options: Options, - fileName: string, description?: string, - header?: string, defaultVal?: string, - path?: string, + docUrl?: string, ): string | undefined { - const docUrl = getDocUrl(options, fileName, header, path) let str = description || '' - const separators = options.defaultValSeparators if (defaultVal) { - str += `${str ? separators[0] : ''}default: ${defaultVal}${separators[1]}` + str += `${str ? ', ' : ''}default: ${defaultVal}.` } if (docUrl) { str += `${str ? '\n\n' : ''}[Docs](${docUrl})` From ea64286e06148eb0ab9e3222122de364208e644d Mon Sep 17 00:00:00 2001 From: tolking Date: Sat, 1 May 2021 10:21:16 +0800 Subject: [PATCH 3/4] refactor: subtagsMap to slotsSubtags --- src/config.ts | 2 +- src/type.ts | 6 +----- src/vetur.ts | 17 +++++++++++++++-- test/button.md | 7 ++++--- test/index.js | 16 ++++++++++------ 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/config.ts b/src/config.ts index 331d2fc..ec674e5 100644 --- a/src/config.ts +++ b/src/config.ts @@ -21,11 +21,11 @@ const config: Config = { slots: 'slots', slotsName: 'Name', slotsDescription: 'Description', + slotsSubtags: 'Subtags', directives: 'directives', directivesName: 'Name', directivesType: 'Type', directivesDescription: 'Description', - subtagsMap: {}, } export default config diff --git a/src/type.ts b/src/type.ts index f8c50ee..eb5ebaa 100644 --- a/src/type.ts +++ b/src/type.ts @@ -47,11 +47,11 @@ export interface Config { slots: string slotsName: string slotsDescription: string + slotsSubtags: string directives: string directivesName: string directivesType: string directivesDescription: string - subtagsMap: SubTagsMap } export type InstallOptions = OptionsConfig & Partial @@ -159,7 +159,3 @@ export interface WebTypes { } } } - -export interface SubTagsMap { - [propName: string]: string[] -} diff --git a/src/vetur.ts b/src/vetur.ts index 729bb4d..7170f59 100644 --- a/src/vetur.ts +++ b/src/vetur.ts @@ -17,8 +17,8 @@ function vetur( separator, eventsName, eventsDescription, + slotsSubtags, reVeturDescription, - subtagsMap, } = options const tagsList = {} as Tags const propsList = {} as Props @@ -37,7 +37,9 @@ function vetur( const name = getComponentsName(options, title, fileName, path) const _props = props ? props.content : [] const _events = events ? events.content : [] + const _slots = slots ? slots.content : [] const tagsProps: string[] = [] + let subtags: string[] = [] if (children && children.length) { const { tags, attributes } = vetur(options, children) @@ -94,6 +96,17 @@ function vetur( } }) + _slots.forEach((item) => { + const _subtags = item[slotsSubtags] + const _subtagsList = _subtags + ? _subtags.split(separator).map((item) => item.trim()) + : undefined + + if (_subtagsList) { + subtags = subtags.concat(_subtagsList) + } + }) + const docUrl = getDocUrl(options, fileName, events?.title, path) const _description = isFunction(reVeturDescription) ? reVeturDescription(description, undefined, docUrl) @@ -101,7 +114,7 @@ function vetur( tagsList[name] = { attributes: checkArray(tagsProps), - subtags: subtagsMap[name], + subtags: checkArray(subtags), description: _description, } } diff --git a/test/button.md b/test/button.md index 761db8e..17d6dcd 100644 --- a/test/button.md +++ b/test/button.md @@ -34,6 +34,7 @@ Display multiple buttons as button groups ### ButtonGroup Slots -| Name | Description | -| ------ | ------------------ | -| default | customize button group content | +| Name | Description | Subtags | +| ------ | ------------------ | -- | +| default | customize button group content | Button / Test | +| other | some other slots || diff --git a/test/index.js b/test/index.js index 3b2d5e6..a0e5cce 100644 --- a/test/index.js +++ b/test/index.js @@ -1,8 +1,5 @@ // eslint-disable-next-line @typescript-eslint/no-var-requires const helper = require('../lib/index') -const subtagsMap = { - 'app-button-group': ['app-button'], -} helper({ name: 'test', @@ -12,7 +9,7 @@ helper({ reComponentName, reDocUrl, reAttribute, - subtagsMap, + space: 2, props: 'Attributes', propsName: 'Attribute', propsOptions: 'Accepted Values', @@ -29,7 +26,7 @@ function reDocUrl(fileName, header) { return docs + fileName + (_header ? '#' + header : '') } -function reAttribute(str) { +function reAttribute(str, key) { switch (str) { case '': case '-': @@ -38,6 +35,13 @@ function reAttribute(str) { case 'v-model': return 'model-value' default: - return str + if (key === 'Subtags') { + return str + .split('/') + .map((name) => reComponentName(name.trim())) + .join('/') + } else { + return str + } } } From ec35e03fb4c0a0ddb7d625bfa138b8879e401b6a Mon Sep 17 00:00:00 2001 From: tolking Date: Sat, 1 May 2021 11:01:39 +0800 Subject: [PATCH 4/4] docs: updata --- README.md | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 164bfe8..636e6a6 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,13 @@ rewriting the doc url of the component rewriting the attribute of the component +### reVeturDescription + +- Type: `(description?: string, defaultValue?: string, docUrl?: string) => string` +- Default: same like `${description}, default: ${defaultValue}.\n\n[Docs](${docUrl})` + +rewriting the description of vetur + ### space - Type: `number` | `string` @@ -119,6 +126,13 @@ name for attributes of the vetur name for web-types of the webstrom +### separator + +- Type: `string` +- Default: `/` + +the separator for propsOptions and slotsSubtags + ### props - Type: `string` (**This is a regular string and ignores case.**) @@ -154,13 +168,6 @@ name for props header type name for props header options -### separator - -- Type: `string` -- Default: `/` - -name for props options separator - ### propsDefault - Type: `string` @@ -210,6 +217,13 @@ name for slots header name name for slots header description +### slotsSubtags + +- Type: `string` +- Default: `Subtags` + +name for slots header subtags + ### directives - Type: `string` (**This is a regular string and ignores case.**) @@ -238,21 +252,6 @@ name for directives header description name for directives header type -### defaultValSeparators - -- Type: `[string, string]` -- Default: `[', ', '.']` - -config the punctuation of description for vetur - -### subtagsMap - -- Type: `Record` - -config the subtags for vetur - -For example: `{ 'app-button-group': ['app-button'] }` - ### titleRegExp - Type: `string` (**This is a regular string.**)