With the WebStorm support of Volar, you may no longer need this library.
It is more recommended that you use Volar's code prompt by improving the type declaration.
If you still need this library, you can continue to use it, but this library will no longer have new feature updates.
Based on the documents to provide code prompt files for vue component library
Reference documents format reference test files
yarn add components-helper -D
# or
npm i components-helper --save-dev
const { main } = require('components-helper')
main({
// Options
})
then in package.json
{
"scripts": {
+ "build:helper": "node helper/file.js"
},
+ "vetur": {
+ "tags": "config outDir/tags.json",
+ "attributes": "config outDir/attributes.json"
+ },
+ "web-types": "config outDir/web-types.json"
}
TOC
- entry (required)
- fastGlobConfig
- outDir (required)
- name (required)
- version (required)
- space
- separator
- reComponentName
- reDocUrl
- reAttribute
- reVeturDescription
- reWebTypesSource
- reWebTypesType
- tags
- attributes
- webTypes
- props
- propsName
- propsDescription
- propsType
- propsOptions
- propsDefault
- events
- eventsName
- eventsDescription
- slots
- slotsName
- slotsDescription
- slotsType
- slotsSubtags
- directives
- directivesName
- directivesDescription
- directivesType
- titleRegExp
- tableRegExp
- fileNameRegExp
- Required:
true
- Type:
string
|string[]
Specify the entry directory. refer: fast-glob
for example:
docs/*.md
-- matches all files in the docsdocs/(a|b).md
-- matches filesa.md
andb.md
docs/!(a|b).md
-- matches files except fora.md
andb.md
- Type:
object
The config of fast-glob
- Required:
true
- Type:
string
Specify the output directory. For example, `lib``
- Required:
true
- Type:
string
name of the component library.
- Required:
true
- Type:
string
the version of the component library.
- Type:
number
|string
Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read
- Type:
string
- Default:
/
the separator for propsOptions, slotsSubtags, type ...
- Type:
(title: string, fileName: string, path: string) => string
- Defult:
hyphenate(title || fileName)
rewriting the name of the component
for example (title) => 'prefix-' + title.replace(/\B([A-Z])/g, '-$1').toLowerCase()
- Type:
(fileName: string, header?: string, path: string) => string | undefind
rewriting the doc url of the component
- Type:
(value: string, key: string, row: string[], title: string) => string | undefined
- value: current value
- key: the key value of the current column
- row: all values of the current row
- title: the title of current tabel
rewriting the attribute of the component
- Type:
(description?: string, defaultValue?: string, docUrl?: string) => string
- Default: same like
${description}, default: ${defaultValue}.\n\n[Docs](${docUrl})
rewriting the description of vetur
- Type:
(title: string, fileName: string, path: string) => Source
rewriting the source of web-types. (the name of export from the component library)
- Type:
(type: string) => undefined | string | BaseContribution
Only some common types are processed internally, and the rest are exported from the component library by default. If your document also references types in third-party libraries, you can choose to override the relevant behavior through this function
- Type:
string
- Default:
tags.json
name for tags of the vetur
- Type:
string
- Default:
attributes.json
name for attributes of the Vetur
- Type:
string
- Default:
web-types.json
name for web-types of the WebStorm
- Type:
string
(This is a regular string and ignores case.) - Default:
props
The title of the props table. other string in the header will be identified as sub-component
- Type:
string
- Default:
Name
The header name of the Name
in the props table
- Type:
string
- Default:
Description
The header name of the Description
in the props table
- Type:
string
- Default:
Type
The header name of the Type
in the props table
- Type:
string
- Default:
Options
The header name of the Options
in the props table
- Type:
string
- Default:
Default
The header name of the Default
in the props table
- Type:
string
(This is a regular string and ignores case.) - Default:
events
The title of the events table. other string in the header will be identified as sub-component
- Type:
string
- Default:
Name
The header name of the Name
in the events table
- Type:
string
- Default:
Description
The header name of the Description
in the events table
- Type:
string
(This is a regular string and ignores case.) - Default:
slots
The title of the slots table. other string in the header will be identified as sub-component
- Type:
string
- Default:
Name
The header name of the Name
in the slots table
- Type:
string
- Default:
Description
The header name of the Description
in the slots table
- Type:
string
- Default:
Type
The header name of the Type
in the slots table
- Type:
string
- Default:
Subtags
The header name of the Subtags
in the slots table
- Type:
string
(This is a regular string and ignores case.) - Default:
directives
The title of the directives table. other string in the header will be identified as sub-component
- Type:
string
- Default:
Name
The header name of the Name
in the directives table
- Type:
string
- Default:
Description
The header name of the Description
in the directives table
- Type:
string
- Default:
Type
The header name of the Type
in the directives table
- Type:
RegExp
|string
(This is a regular string.) - Default:
/#+\s+(.*)\n+([^(#|\n)]*)/g
matches the title and description information from docs
- Type:
RegExp
|string
(This is a regular string.) - Default:
/#+\s+(.*)\n+(\|?.+\|.+)\n\|?\s*:?-+:?\s*\|.+((\n\|?.+\|.+)+)/g
matches the title and table header and the table contains information from docs
- Type:
RegExp
|string
(This is a regular string.) - Default:
/\/((\w|-)+)\.\w+$/
matches the file name from the path
matches the first format information in the docs
/#+\s+(.*
)\n+([^(#|\n)]*
)/
title
description
and
title
matches other formats, For example:
/#+\s+(.*
)\n+>\s*([^(#|\n)]*
)/g
title
description
matches the format information in the docs
/#+\s+(.*
)\n+(\|?.+\|.+
)\n|?\s*:?-+:?\s*|.+((\n\|?.+\|.+)+
)/g
title
| header |
| column |
| column |
and
sub-component title
| header |
| column |
| column |
by default matches all tables, Optimize it through tableRegExp, For example:
/#+\s+(.*\s*Props|.*\s*Events|.*\s*Slots|.*\s*Directives
)\n+(\|?.+\|.+
)\n|?\s*:?-+:?\s*|.+((\n\|?.+\|.+)+
)/g
Props / Events / Slots / Directives
| header |
| column |
| column |
and
sub-component Props
| header |
| column |
| column |
When this document does not include the primary title or Props
Events
Slots
and Directives
, this component is not created.