Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 21 additions & 23 deletions scripts/create-web-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ let directiveGroups = {}

// Base web-types object
const webTypes = {
$schema: '',
$schema: 'https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json',
framework: 'vue',
name: libraryName,
version: libraryVersion,
contributions: {
html: {
'types-syntax': 'typescript',
'description-markup': 'markdown',
// Components get placed here
tags: [],
// Directives get placed in here
Expand Down Expand Up @@ -115,7 +116,7 @@ const computePropDefault = ({ default: def, type }) => {
}

// Process a single component's meta and definition/class objects
const processComponentMeta = (meta, groupRef, docUrl) => {
const processComponentMeta = (meta, groupRef, groupDescription, docUrl) => {
const componentName = meta.component

// Pull information from the component definition/class
Expand All @@ -128,27 +129,23 @@ const processComponentMeta = (meta, groupRef, docUrl) => {
const $events = meta.events || []
const $slots = meta.slots || []
const $aliases = meta.aliases || []
// This doesn't exist yet (for prop descriptions, info)
// For description (and possibly more) for props docs
// source is array format, so we convert to a hash object
// Pull in any prop info from the meta (i.e. description)
const $propsExtra = (meta.props || []).reduce((obj, p) => {
if (p && p.prop) {
obj[p.prop] = p
}
return obj
}, {})

const tagName = kebabCase(componentName)

// Build the tag reference
const tag = {
name: componentName,
source: {
module: libraryName,
symbol: componentName
},
'docs-url': docUrl,
description: `'${componentName}' - BootstrapVue component '${tagName}'`,
'doc-url': docUrl,
description: groupDescription,
attributes: []
}

Expand All @@ -170,14 +167,15 @@ const processComponentMeta = (meta, groupRef, docUrl) => {
const prop = {
name: propName,
value: {
type: type,
default: computePropDefault($prop)
kind: 'expression',
type: type
},
default: computePropDefault($prop),
'doc-url': docUrl
}
// Add required prop is required
if ($prop.required) {
prop.value.required = true
prop.required = true
}
if (type === 'boolean') {
// Deprecated. Use 'value' property instead. Specify only if type is
Expand Down Expand Up @@ -215,10 +213,11 @@ const processComponentMeta = (meta, groupRef, docUrl) => {
event.description = eventObj.description
}
if (Array.isArray(eventObj.args)) {
event.arguments = eventObj.args.map(arg => {
event.arguments = eventObj.args.map((arg, index) => {
arg = typeof arg === 'object' ? arg : { arg: arg }
const name = arg.arg || (arg.type ? computePropType(arg) : undefined) || 'arg' + index
const argument = {
name: arg.arg,
name: name.charAt(0).toLowerCase() + name.slice(1),
'doc-url': docUrl
}
if (arg.description) {
Expand Down Expand Up @@ -278,14 +277,14 @@ const processComponentMeta = (meta, groupRef, docUrl) => {
// Add the aliases
$aliases.forEach(alias => {
const aliasTag = { ...tag, name: alias, source: { ...tag.source, symbol: alias } }
aliasTag.description = `'${alias}' '${kebabCase(alias)}' (Alias for ${tag.description})`
aliasTag.description = `${tag.description}\n\n*Alias for ${tag.name}*`
webTypes.contributions.html.tags.push(aliasTag)
})
}
}

// Process a single directive meta object
const processDirectiveMeta = (directiveMeta, docUrl) => {
const processDirectiveMeta = (directiveMeta, directiveDescription, docUrl) => {
// Process the directive meta
// String (PascalCase)
const name = directiveMeta.directive
Expand All @@ -304,18 +303,17 @@ const processDirectiveMeta = (directiveMeta, docUrl) => {
symbol: name
},
required: false,
description: `${name} - BootstrapVue directive '${kebabCase(name)}'`,
description: directiveDescription,
'doc-url': docUrl
}

// Add in argument details
if (arg) {
// TODO as this is missing from the schema def
// https://github.com/JetBrains/web-types/issues/7
attribute['vue-argument'] = {
// RegExpr string pattern for argument
pattern: arg.pattern,
description: arg.description
description: arg.description,
required: arg.required
}
}

Expand Down Expand Up @@ -363,13 +361,13 @@ const processComponentGroup = groupSlug => {

// Process each component
componentsMeta.forEach(meta => {
processComponentMeta(meta, groupRef, docUrl)
processComponentMeta(meta, groupRef, groupMeta.description, docUrl)
})

// Process any directives provided in the meta
// These directives do not have their own package.json files
directivesMeta.forEach(directiveMeta => {
processDirectiveMeta(directiveMeta, docUrl)
processDirectiveMeta(directiveMeta, groupMeta.description, docUrl)
})
}

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

// Process the directive meta
processDirectiveMeta(directiveMeta, docUrl)
processDirectiveMeta(directiveMeta, directiveMeta.description, docUrl)
}

// Wrapped in a try/catch to handle any errors
Expand Down
5 changes: 3 additions & 2 deletions src/directives/popover/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
"description": "Add BootstrapVue popovers to any element on your site, using Bootstrap v4 CSS for styling and animations. Popovers are tooltips on steroids.",
"directive": "VBPopover",
"arg": {
"pattern": "[a-zA-Z][a-ZA-Z0-9_\\-]*",
"description": "ID of element to append the popover markup when visible. Optional, defaults to the body"
"pattern": "[a-zA-Z][a-zA-Z0-9_\\-]*",
"description": "ID of element to append the popover markup when visible. Optional, defaults to the body",
"required": false
},
"expression": [
"String",
Expand Down
5 changes: 3 additions & 2 deletions src/directives/scrollspy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
"description": "Automatically activate BootstrapVue navigation or list group components based on scroll position to indicate which link is currently active in the viewport.",
"directive": "VBScrollspy",
"arg": {
"pattern": "[a-zA-Z][a-ZA-Z0-9_\\-]*",
"description": "ID of element to monitor scrolling on (if not provided defaults to the body element)"
"pattern": "[a-zA-Z][a-zA-Z0-9_\\-]*",
"description": "ID of element to monitor scrolling on (if not provided defaults to the body element)",
"required": false
},
"expression": [
"String",
Expand Down
5 changes: 3 additions & 2 deletions src/directives/tooltip/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
"description": "Add custom BootstrapVue tooltips to any element. Tooltips can be triggered by hovering, focusing, or clicking an element.",
"directive": "VBTooltip",
"arg": {
"pattern": "[a-zA-Z][a-ZA-Z0-9_\\-]*",
"description": "ID of element to append the tooltip markup when visible. Optional, defaults to the body"
"pattern": "[a-zA-Z][a-zA-Z0-9_\\-]*",
"description": "ID of element to append the tooltip markup when visible. Optional, defaults to the body",
"required": false
},
"expression": [
"String",
Expand Down