chore: auto generate web-types.json to provide autocomplete for JetBrains IDEs #7906
chore: auto generate web-types.json to provide autocomplete for JetBrains IDEs #7906vaibhavhrt wants to merge 8 commits intovuetifyjs:masterfrom
Conversation
Travis tests have failedHey @vaibhavhrt, Node.js: 12yarn run lintTravisBuddy Request Identifier: 0597de10-ddec-11e9-8141-977217faf2ea |
Codecov Report
@@ Coverage Diff @@
## next #7906 +/- ##
=========================================
+ Coverage 85.77% 85.8% +0.02%
=========================================
Files 334 334
Lines 9092 9095 +3
Branches 2413 2418 +5
=========================================
+ Hits 7799 7804 +5
+ Misses 1205 1203 -2
Partials 88 88
Continue to review full report at Codecov.
|
vaibhavhrt
left a comment
There was a problem hiding this comment.
@KaelWD take a look please.
vaibhavhrt
left a comment
There was a problem hiding this comment.
case of name fixed too, should now match web-types.json from JetBrains.
|
@KaelWD what are we going to do about the schema. Also can you please review. |
|
Added the schema, the json generated is not even close to the schema, will investigate later. Meanwhile any help is appreciated, @KaelWD @piotrtomiak |
| writeApiFile({ ...components, ...directives }, 'dist/api.js') | ||
|
|
||
| // Create web-types.json to provide autocomplete in JetBrains IDEs | ||
| const webTypes = { |
There was a problem hiding this comment.
@vaibhavhrt Here is code, which satisfies the schema when it comes to component attributes and directives:
// Create web-types.json to provide autocomplete in JetBrains IDEs
const webTypes = {
$schema: "https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json",
framework: 'vue',
name: 'vuetify',
version: pkg.version,
contributions: {
html: {
'types-syntax': 'typescript',
tags: [],
attributes: []
},
},
}
components['$vuetify'] = map['$vuetify']
components['internationalization'] = map['internationalization']
writeApiFile({ ...components, ...directives }, 'dist/api.js')
delete components['$vuetify']
delete components['internationalization']
Object.keys(components).forEach(function (key) {
const name = capitalize(camelize(key))
const attributes = transformAttributes(components[key].props)
const events = components[key].events
const slots = components[key].slots
const tag = { name, attributes, events, slots }
webTypes.contributions.html.tags.push(tag)
function transformAttributes(attributes) {
const result = []
for (let attr of attributes) {
attr = removeProperties(attr, "source")
if (attr["type"]) {
attr["value"] = {
kind: "expression",
type: attr["type"]
}
if (attr["type"] !== "boolean") {
delete attr["type"]
}
}
if (attr["default"]) {
attr["default"] = JSON.stringify(attr["default"])
}
result.push(attr)
}
return result
}
function removeProperties(obj, ...names) {
const result = {}
Object.keys(obj).forEach(function(name) {
if (names.indexOf(name) < 0) {
result[name] = obj[name]
}
})
return result
}
})
Object.keys(directives).forEach(function (key) {
const name = capitalize(camelize(key))
const directive = { name }
webTypes.contributions.html.attributes.push(directive)
})
writeJsonFile(webTypes, 'dist/web-types.json')You need to make similar transformations for slots and events.
There was a problem hiding this comment.
wow, thanks. I will update it as soon as I find some time.
There was a problem hiding this comment.
I've actually had some time to write other transformations:
// Create web-types.json to provide autocomplete in JetBrains IDEs
const webTypes = {
$schema: "https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json",
framework: 'vue',
name: 'vuetify',
version: pkg.version,
contributions: {
html: {
'types-syntax': 'typescript',
tags: [],
attributes: []
},
},
}
components['$vuetify'] = map['$vuetify']
components['internationalization'] = map['internationalization']
writeApiFile({...components, ...directives}, 'dist/api.js')
delete components['$vuetify']
delete components['internationalization']
Object.keys(components).forEach(function (key) {
const name = capitalize(camelize(key))
const attributes = mapArray(components[key].props, transformAttribute)
const events = mapArray(components[key].events, transformEvent)
const slots = mapArray(components[key].slots, transformSlot)
const tag = {name, attributes, events, slots}
webTypes.contributions.html.tags.push(tag)
function mapArray(arr, mapper) {
return arr !== undefined ? arr.map(mapper) : undefined
}
function transformAttribute(attr) {
attr = copyObject(attr)
delete attr["source"]
if (attr["type"]) {
attr["value"] = {
kind: "expression",
type: attr["type"]
}
if (attr["type"] !== "boolean") {
delete attr["type"]
}
}
if (attr["default"] !== undefined) {
attr["default"] = JSON.stringify(attr["default"])
}
delete attr["example"]
return attr
}
function transformEvent(event) {
event = copyObject(event)
if (event["value"] !== undefined) {
let type = event["value"]
event.arguments = [{
name: "argument",
type: typeof type === "string" ? type : JSON.stringify(type)
}]
}
delete event["value"]
delete event['source']
return event
}
function transformSlot(slot) {
slot = copyObject(slot)
if (slot["props"] !== undefined) {
const props = []
Object.keys(slot["props"]).forEach(function (name) {
let type = slot['props'][name]
props.push({
name,
type: typeof type === "string" ? type : JSON.stringify(type)
})
})
slot["vue-properties"] = props
}
delete slot["props"]
delete slot['source']
return slot
}
function copyObject(obj) {
const result = {}
if (typeof obj === "string") {
result["name"] = obj
} else {
Object.keys(obj).forEach(function (name) {
result[name] = obj[name]
})
}
return result
}
})
Object.keys(directives).forEach(function (key) {
const name = capitalize(camelize(key))
const directive = {name}
webTypes.contributions.html.attributes.push(directive)
})
writeJsonFile(webTypes, 'dist/web-types.json')The web-types JSON generated with this code is fully compatible with the schema :)
There was a problem hiding this comment.
There is however some polishing required to properly generate types - some of them require processing instead of simple JSON.stringify.
There was a problem hiding this comment.
@vaibhavhrt Any chances for getting this change integrated into build this week?
There was a problem hiding this comment.
sorry, been too busy with work. I will update my PR tomorrow.
There was a problem hiding this comment.
@vaibhavhrt I've created a PR #9440 with all of my changes on top of your work.
|
Closing in favor of #9440 |
Follow up to [WIP] Auto generate web-types.json to provide autocomplete for JetBrains IDEs #7905