-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vue): web-types support (#22428)
resolves #19522
- Loading branch information
1 parent
7512c90
commit 639314a
Showing
2 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
const fs = require("fs") | ||
|
||
// Web-types build require docs to be built first | ||
const docs = require("@ionic/core/dist/docs.json") | ||
|
||
const components = [] | ||
|
||
function toCamelCase(name) { | ||
return name.split("-").map(n => n[0].toUpperCase() + n.substr(1)).join("") | ||
} | ||
|
||
for (const component of docs.components) { | ||
if (!component.usage.vue) continue | ||
const attributes = [] | ||
const slots = [] | ||
const events = [] | ||
const componentName = toCamelCase(component.tag) | ||
const docUrl = "https://ionicframework.com/docs/api/" + component.tag.substr(4) | ||
|
||
for (const prop of component.props || []) { | ||
attributes.push({ | ||
name: prop.attr || prop.name, | ||
description: prop.docs, | ||
required: prop.required, | ||
default: prop.default, | ||
value: { | ||
kind: "expression", | ||
type: prop.type | ||
} | ||
}) | ||
} | ||
|
||
for (const event of component.events || []) { | ||
let eventName = event.event; | ||
if (eventName.toLowerCase().startsWith(componentName.toLowerCase())) { | ||
eventName = "on" + eventName.substr(componentName.length); | ||
} | ||
events.push({ | ||
name: eventName, | ||
description: event.docs, | ||
arguments: [{ | ||
name: "detail", | ||
type: event.detail | ||
}] | ||
}) | ||
} | ||
|
||
for (const slot of component.slots || []) { | ||
slots.push({ | ||
name: slot.name === "" ? "default" : slot.name, | ||
description: slot.docs | ||
}) | ||
} | ||
|
||
components.push({ | ||
name: componentName, | ||
"doc-url": docUrl, | ||
description: component.docs, | ||
source: { | ||
module: "@ionic/core/" + component.filePath.replace("./src/", "dist/types/").replace(".tsx", ".d.ts"), | ||
symbol: componentName.substr(3) | ||
}, | ||
attributes, | ||
slots, | ||
events | ||
}) | ||
} | ||
|
||
const webTypes = { | ||
$schema: "http://json.schemastore.org/web-types", | ||
framework: "vue", | ||
name: "@ionic/vue", | ||
version: require("../package.json").version, | ||
contributions: { | ||
html: { | ||
"types-syntax": "typescript", | ||
"description-markup": "markdown", | ||
tags: components | ||
} | ||
} | ||
} | ||
|
||
fs.writeFileSync("dist/web-types.json", JSON.stringify(webTypes, null, 2)) |