Skip to content

Commit

Permalink
fix(web-types): update web-types code generation to match schema (#4271)
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrtomiak authored and tmorehouse committed Oct 18, 2019
1 parent ff0be41 commit 009431e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
44 changes: 21 additions & 23 deletions scripts/create-web-types.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ let directiveGroups = {}


// Base web-types object // Base web-types object
const webTypes = { const webTypes = {
$schema: '', $schema: 'https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json',
framework: 'vue', framework: 'vue',
name: libraryName, name: libraryName,
version: libraryVersion, version: libraryVersion,
contributions: { contributions: {
html: { html: {
'types-syntax': 'typescript', 'types-syntax': 'typescript',
'description-markup': 'markdown',
// Components get placed here // Components get placed here
tags: [], tags: [],
// Directives get placed in here // 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 // 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 const componentName = meta.component


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


const tagName = kebabCase(componentName)

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


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


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


// Add in argument details // Add in argument details
if (arg) { if (arg) {
// TODO as this is missing from the schema def
// https://github.com/JetBrains/web-types/issues/7
attribute['vue-argument'] = { attribute['vue-argument'] = {
// RegExpr string pattern for argument // RegExpr string pattern for argument
pattern: arg.pattern, 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 // Process each component
componentsMeta.forEach(meta => { componentsMeta.forEach(meta => {
processComponentMeta(meta, groupRef, docUrl) processComponentMeta(meta, groupRef, groupMeta.description, docUrl)
}) })


// Process any directives provided in the meta // Process any directives provided in the meta
// These directives do not have their own package.json files // These directives do not have their own package.json files
directivesMeta.forEach(directiveMeta => { 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}/` const docUrl = `${baseDocs}/docs/directives/${groupSlug}/`


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


// Wrapped in a try/catch to handle any errors // 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 Original file line 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.", "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", "directive": "VBPopover",
"arg": { "arg": {
"pattern": "[a-zA-Z][a-ZA-Z0-9_\\-]*", "pattern": "[a-zA-Z][a-zA-Z0-9_\\-]*",
"description": "ID of element to append the popover markup when visible. Optional, defaults to the body" "description": "ID of element to append the popover markup when visible. Optional, defaults to the body",
"required": false
}, },
"expression": [ "expression": [
"String", "String",
Expand Down
5 changes: 3 additions & 2 deletions src/directives/scrollspy/package.json
Original file line number Original file line 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.", "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", "directive": "VBScrollspy",
"arg": { "arg": {
"pattern": "[a-zA-Z][a-ZA-Z0-9_\\-]*", "pattern": "[a-zA-Z][a-zA-Z0-9_\\-]*",
"description": "ID of element to monitor scrolling on (if not provided defaults to the body element)" "description": "ID of element to monitor scrolling on (if not provided defaults to the body element)",
"required": false
}, },
"expression": [ "expression": [
"String", "String",
Expand Down
5 changes: 3 additions & 2 deletions src/directives/tooltip/package.json
Original file line number Original file line 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.", "description": "Add custom BootstrapVue tooltips to any element. Tooltips can be triggered by hovering, focusing, or clicking an element.",
"directive": "VBTooltip", "directive": "VBTooltip",
"arg": { "arg": {
"pattern": "[a-zA-Z][a-ZA-Z0-9_\\-]*", "pattern": "[a-zA-Z][a-zA-Z0-9_\\-]*",
"description": "ID of element to append the tooltip markup when visible. Optional, defaults to the body" "description": "ID of element to append the tooltip markup when visible. Optional, defaults to the body",
"required": false
}, },
"expression": [ "expression": [
"String", "String",
Expand Down

0 comments on commit 009431e

Please sign in to comment.