-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathgenerateData.js
More file actions
189 lines (162 loc) · 5.12 KB
/
generateData.js
File metadata and controls
189 lines (162 loc) · 5.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
const fs = require('fs')
const path = require('path')
const bcd = require('@mdn/browser-compat-data')
/*---------------------------------------------------------------------------------------------
* Tags
*--------------------------------------------------------------------------------------------*/
const htmlTags = require('./htmlTags.json')
const htmlTagDescriptions = require('./mdnTagDescriptions.json')
htmlTags.forEach(t => {
const matchingTagDescription = htmlTagDescriptions.find(td => td.name === t.name)
if (matchingTagDescription) {
t.attributes.forEach(a => {
const matchingAttrDescription =
matchingTagDescription.attributes.filter(ad => ad.name === a.name && ad.description)
.map(ad => ad.description)
.join('\n');
if (matchingAttrDescription) {
a.description = {
kind: 'markdown',
value: matchingAttrDescription
}
}
})
const moreAttrs = []
matchingTagDescription.attributes.forEach(ad => {
if (!t.attributes.some(a => a.name === ad.name)) {
moreAttrs.push(ad)
}
})
t.attributes = t.attributes.concat(moreAttrs)
}
})
htmlTags.forEach(t => {
if (t.description) {
t.description = {
kind: 'markdown',
value: t.description
}
}
})
const bcdHTMLElements = bcd.html.elements
htmlTags.forEach(t => {
if (bcdHTMLElements[t.name]) {
const bcdMatchingTag = bcdHTMLElements[t.name]
if (bcdMatchingTag.__compat && bcdMatchingTag.__compat.mdn_url) {
if (!t.references) {
t.references = []
}
t.references.push({
name: 'MDN Reference',
url: bcdMatchingTag.__compat.mdn_url
})
}
}
})
/*---------------------------------------------------------------------------------------------
* Global Attributes
*--------------------------------------------------------------------------------------------*/
const htmlGlobalAttributes = require('./htmlGlobalAttributes.json')
const bcdGlobalAttributes = bcd.html.global_attributes
htmlGlobalAttributes.forEach(a => {
if (a.description) {
a.description = {
kind: 'markdown',
value: a.description
}
}
if (
bcdGlobalAttributes[a.name] &&
bcdGlobalAttributes[a.name].__compat &&
bcdGlobalAttributes[a.name].__compat.mdn_url
) {
if (!a.references) {
a.references = []
}
a.references.push({
name: 'MDN Reference',
url: bcdGlobalAttributes[a.name].__compat.mdn_url
})
}
})
/*---------------------------------------------------------------------------------------------
* Events
*--------------------------------------------------------------------------------------------*/
const htmlEvents = require('./htmlEvents.json')
/**
* Todo@Pine Clean up new HTML events and drop the old events
*/
const oldEvents = require('./oldEvents.json')
oldEvents.forEach(e => {
const match = htmlEvents.find(x => x.name === e.name)
if (match) {
if (match.description) {
e.description = {
kind: 'markdown',
value: match.description
}
}
}
});
/*---------------------------------------------------------------------------------------------
* Aria
*--------------------------------------------------------------------------------------------*/
const ariaData = require('./ariaData.json')
const ariaSpec = require('./ariaSpec.json')
ariaSpec.forEach(ariaItem => {
if (ariaItem.description) {
ariaItem.description = {
kind: 'markdown',
value: ariaItem.description
}
}
})
const ariaMap = {}
ariaData.forEach(ad => {
ariaMap[ad.name] = {
...ad,
references: [
{
name: 'WAI-ARIA Reference',
url: `https://www.w3.org/TR/wai-aria-1.1/#${ad.name}`
}
]
}
})
ariaSpec.forEach(as => {
if (!ariaMap[as.name]) {
ariaMap[as.name] = {
...as
}
} else {
ariaMap[as.name] = {
...ariaMap[as.name],
...as
}
}
})
const ariaOut = []
for (let a in ariaMap) {
ariaOut.push(ariaMap[a])
}
/*---------------------------------------------------------------------------------------------
* Value Sets
*--------------------------------------------------------------------------------------------*/
const valueSets = require('./valueSets.json')
/*---------------------------------------------------------------------------------------------
* Synthesize
*--------------------------------------------------------------------------------------------*/
const customDataObject = {
version: 1.1,
tags: htmlTags,
globalAttributes: [...htmlGlobalAttributes, ...oldEvents, ...ariaOut],
valueSets: valueSets
}
const outPath = path.resolve(__dirname, '../data/browsers.html-data.json')
console.log('Writing custom data to: ' + outPath)
fs.writeFileSync(outPath, JSON.stringify(customDataObject, null, 2))
console.log('Done')