Skip to content

Commit 009431e

Browse files
piotrtomiaktmorehouse
authored andcommitted
fix(web-types): update web-types code generation to match schema (#4271)
1 parent ff0be41 commit 009431e

File tree

4 files changed

+30
-29
lines changed

4 files changed

+30
-29
lines changed

scripts/create-web-types.js

Lines changed: 21 additions & 23 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
@@ -128,27 +129,23 @@ const processComponentMeta = (meta, groupRef, docUrl) => {
128129
const $events = meta.events || []
129130
const $slots = meta.slots || []
130131
const $aliases = meta.aliases || []
131-
// This doesn't exist yet (for prop descriptions, info)
132-
// For description (and possibly more) for props docs
133-
// source is array format, so we convert to a hash object
132+
// Pull in any prop info from the meta (i.e. description)
134133
const $propsExtra = (meta.props || []).reduce((obj, p) => {
135134
if (p && p.prop) {
136135
obj[p.prop] = p
137136
}
138137
return obj
139138
}, {})
140139

141-
const tagName = kebabCase(componentName)
142-
143140
// Build the tag reference
144141
const tag = {
145142
name: componentName,
146143
source: {
147144
module: libraryName,
148145
symbol: componentName
149146
},
150-
'docs-url': docUrl,
151-
description: `'${componentName}' - BootstrapVue component '${tagName}'`,
147+
'doc-url': docUrl,
148+
description: groupDescription,
152149
attributes: []
153150
}
154151

@@ -170,14 +167,15 @@ const processComponentMeta = (meta, groupRef, docUrl) => {
170167
const prop = {
171168
name: propName,
172169
value: {
173-
type: type,
174-
default: computePropDefault($prop)
170+
kind: 'expression',
171+
type: type
175172
},
173+
default: computePropDefault($prop),
176174
'doc-url': docUrl
177175
}
178176
// Add required prop is required
179177
if ($prop.required) {
180-
prop.value.required = true
178+
prop.required = true
181179
}
182180
if (type === 'boolean') {
183181
// Deprecated. Use 'value' property instead. Specify only if type is
@@ -215,10 +213,11 @@ const processComponentMeta = (meta, groupRef, docUrl) => {
215213
event.description = eventObj.description
216214
}
217215
if (Array.isArray(eventObj.args)) {
218-
event.arguments = eventObj.args.map(arg => {
216+
event.arguments = eventObj.args.map((arg, index) => {
219217
arg = typeof arg === 'object' ? arg : { arg: arg }
218+
const name = arg.arg || (arg.type ? computePropType(arg) : undefined) || 'arg' + index
220219
const argument = {
221-
name: arg.arg,
220+
name: name.charAt(0).toLowerCase() + name.slice(1),
222221
'doc-url': docUrl
223222
}
224223
if (arg.description) {
@@ -278,14 +277,14 @@ const processComponentMeta = (meta, groupRef, docUrl) => {
278277
// Add the aliases
279278
$aliases.forEach(alias => {
280279
const aliasTag = { ...tag, name: alias, source: { ...tag.source, symbol: alias } }
281-
aliasTag.description = `'${alias}' '${kebabCase(alias)}' (Alias for ${tag.description})`
280+
aliasTag.description = `${tag.description}\n\n*Alias for ${tag.name}*`
282281
webTypes.contributions.html.tags.push(aliasTag)
283282
})
284283
}
285284
}
286285

287286
// Process a single directive meta object
288-
const processDirectiveMeta = (directiveMeta, docUrl) => {
287+
const processDirectiveMeta = (directiveMeta, directiveDescription, docUrl) => {
289288
// Process the directive meta
290289
// String (PascalCase)
291290
const name = directiveMeta.directive
@@ -304,18 +303,17 @@ const processDirectiveMeta = (directiveMeta, docUrl) => {
304303
symbol: name
305304
},
306305
required: false,
307-
description: `${name} - BootstrapVue directive '${kebabCase(name)}'`,
306+
description: directiveDescription,
308307
'doc-url': docUrl
309308
}
310309

311310
// Add in argument details
312311
if (arg) {
313-
// TODO as this is missing from the schema def
314-
// https://github.com/JetBrains/web-types/issues/7
315312
attribute['vue-argument'] = {
316313
// RegExpr string pattern for argument
317314
pattern: arg.pattern,
318-
description: arg.description
315+
description: arg.description,
316+
required: arg.required
319317
}
320318
}
321319

@@ -363,13 +361,13 @@ const processComponentGroup = groupSlug => {
363361

364362
// Process each component
365363
componentsMeta.forEach(meta => {
366-
processComponentMeta(meta, groupRef, docUrl)
364+
processComponentMeta(meta, groupRef, groupMeta.description, docUrl)
367365
})
368366

369367
// Process any directives provided in the meta
370368
// These directives do not have their own package.json files
371369
directivesMeta.forEach(directiveMeta => {
372-
processDirectiveMeta(directiveMeta, docUrl)
370+
processDirectiveMeta(directiveMeta, groupMeta.description, docUrl)
373371
})
374372
}
375373

@@ -380,7 +378,7 @@ const processDirectiveGroup = groupSlug => {
380378
const docUrl = `${baseDocs}/docs/directives/${groupSlug}/`
381379

382380
// Process the directive meta
383-
processDirectiveMeta(directiveMeta, docUrl)
381+
processDirectiveMeta(directiveMeta, directiveMeta.description, docUrl)
384382
}
385383

386384
// Wrapped in a try/catch to handle any errors

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)