Skip to content

Commit aff0981

Browse files
committed
fix(docs): update web-types code generation to match schema
1 parent 30029e3 commit aff0981

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed

scripts/create-web-types.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ let directiveGroups = {}
2424

2525
// Base web-types object
2626
const webTypes = {
27-
$schema: '',
27+
$schema: 'https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json',
2828
framework: 'vue',
2929
name: libraryName,
3030
version: libraryVersion,
3131
contributions: {
3232
html: {
3333
'types-syntax': 'typescript',
34+
'description-markup': 'markdown',
3435
// Components get placed here
3536
tags: [],
3637
// Directives get placed in here
@@ -115,7 +116,7 @@ const computePropDefault = ({ default: def, type }) => {
115116
}
116117

117118
// Process a single component's meta and definition/class objects
118-
const processComponentMeta = (meta, groupRef, docUrl) => {
119+
const processComponentMeta = (meta, groupRef, groupDescription, docUrl) => {
119120
const componentName = meta.component
120121

121122
// Pull information from the component definition/class
@@ -138,17 +139,15 @@ const processComponentMeta = (meta, groupRef, docUrl) => {
138139
return obj
139140
}, {})
140141

141-
const tagName = kebabCase(componentName)
142-
143142
// Build the tag reference
144143
const tag = {
145144
name: componentName,
146145
source: {
147146
module: libraryName,
148147
symbol: componentName
149148
},
150-
'docs-url': docUrl,
151-
description: `'${componentName}' - BootstrapVue component '${tagName}'`,
149+
'doc-url': docUrl,
150+
description: groupDescription,
152151
attributes: []
153152
}
154153

@@ -170,14 +169,15 @@ const processComponentMeta = (meta, groupRef, docUrl) => {
170169
const prop = {
171170
name: propName,
172171
value: {
172+
kind: 'expression',
173173
type: type,
174-
default: computePropDefault($prop)
175174
},
175+
default: computePropDefault($prop),
176176
'doc-url': docUrl
177177
}
178178
// Add required prop is required
179179
if ($prop.required) {
180-
prop.value.required = true
180+
prop.required = true
181181
}
182182
if (type === 'boolean') {
183183
// Deprecated. Use 'value' property instead. Specify only if type is
@@ -215,10 +215,13 @@ const processComponentMeta = (meta, groupRef, docUrl) => {
215215
event.description = eventObj.description
216216
}
217217
if (Array.isArray(eventObj.args)) {
218-
event.arguments = eventObj.args.map(arg => {
218+
event.arguments = eventObj.args.map((arg, index) => {
219219
arg = typeof arg === 'object' ? arg : { arg: arg }
220+
let name = arg.arg
221+
|| (arg.type ? computePropType(arg) : undefined)
222+
|| "arg" + index
220223
const argument = {
221-
name: arg.arg,
224+
name: name.charAt(0).toLowerCase() + name.slice(1),
222225
'doc-url': docUrl
223226
}
224227
if (arg.description) {
@@ -278,7 +281,7 @@ const processComponentMeta = (meta, groupRef, docUrl) => {
278281
// Add the aliases
279282
$aliases.forEach(alias => {
280283
const aliasTag = { ...tag, name: alias, source: { ...tag.source, symbol: alias } }
281-
aliasTag.description = `'${alias}' '${kebabCase(alias)}' (Alias for ${tag.description})`
284+
aliasTag.description = `${tag.description}\n\n*Alias for ${tag.name}*`
282285
webTypes.contributions.html.tags.push(aliasTag)
283286
})
284287
}
@@ -310,12 +313,11 @@ const processDirectiveMeta = (directiveMeta, docUrl) => {
310313

311314
// Add in argument details
312315
if (arg) {
313-
// TODO as this is missing from the schema def
314-
// https://github.com/JetBrains/web-types/issues/7
315316
attribute['vue-argument'] = {
316317
// RegExpr string pattern for argument
317318
pattern: arg.pattern,
318-
description: arg.description
319+
description: arg.description,
320+
required: arg.required
319321
}
320322
}
321323

@@ -363,7 +365,7 @@ const processComponentGroup = groupSlug => {
363365

364366
// Process each component
365367
componentsMeta.forEach(meta => {
366-
processComponentMeta(meta, groupRef, docUrl)
368+
processComponentMeta(meta, groupRef, groupMeta.description, docUrl)
367369
})
368370

369371
// Process any directives provided in the meta

src/directives/popover/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
"description": "Add BootstrapVue popovers to any element on your site, using Bootstrap v4 CSS for styling and animations. Popovers are tooltips on steroids.",
77
"directive": "VBPopover",
88
"arg": {
9-
"pattern": "[a-zA-Z][a-ZA-Z0-9_\\-]*",
10-
"description": "ID of element to append the popover markup when visible. Optional, defaults to the body"
9+
"pattern": "[a-zA-Z][a-zA-Z0-9_\\-]*",
10+
"description": "ID of element to append the popover markup when visible. Optional, defaults to the body",
11+
"required": false
1112
},
1213
"expression": [
1314
"String",

src/directives/scrollspy/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
"description": "Automatically activate BootstrapVue navigation or list group components based on scroll position to indicate which link is currently active in the viewport.",
77
"directive": "VBScrollspy",
88
"arg": {
9-
"pattern": "[a-zA-Z][a-ZA-Z0-9_\\-]*",
10-
"description": "ID of element to monitor scrolling on (if not provided defaults to the body element)"
9+
"pattern": "[a-zA-Z][a-zA-Z0-9_\\-]*",
10+
"description": "ID of element to monitor scrolling on (if not provided defaults to the body element)",
11+
"required": false
1112
},
1213
"expression": [
1314
"String",

src/directives/tooltip/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
"description": "Add custom BootstrapVue tooltips to any element. Tooltips can be triggered by hovering, focusing, or clicking an element.",
77
"directive": "VBTooltip",
88
"arg": {
9-
"pattern": "[a-zA-Z][a-ZA-Z0-9_\\-]*",
10-
"description": "ID of element to append the tooltip markup when visible. Optional, defaults to the body"
9+
"pattern": "[a-zA-Z][a-zA-Z0-9_\\-]*",
10+
"description": "ID of element to append the tooltip markup when visible. Optional, defaults to the body",
11+
"required": false
1112
},
1213
"expression": [
1314
"String",

0 commit comments

Comments
 (0)