Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vue): web-types support #22428

Merged
merged 2 commits into from
Nov 5, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
"scripts": {
"lint": "echo add linter",
"test": "jest",
"build": "npm run clean && npm run copy && npm run copy.overlays && npm run compile && npm run bundle",
"build": "npm run clean && npm run copy && npm run copy.overlays && npm run compile && npm run bundle && npm run build.web-types",
"bundle": "rollup --config rollup.config.js",
"clean": "rimraf dist dist-transpiled",
"compile": "npm run tsc",
"tsc": "tsc -p .",
"build.web-types": "node ./scripts/build-web-types.js",
"copy": "node ./scripts/copy-css.js",
"copy.overlays": "node ./scripts/copy-overlays.js"
},
Expand Down Expand Up @@ -56,5 +57,6 @@
"dependencies": {
"@ionic/core": "5.4.1",
"ionicons": "^5.1.2"
}
},
"web-types": "dist/web-types.json"
}
83 changes: 83 additions & 0 deletions packages/vue/scripts/build-web-types.js
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))