-
Notifications
You must be signed in to change notification settings - Fork 0
/
summarize_props.js
44 lines (38 loc) · 1.29 KB
/
summarize_props.js
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
const path = require('path')
const {readDir, readFile, writeFile, ROOT} = require('./fs_util.js')
const SHEETS = path.join(ROOT, 'specs', 'new', 'props')
async function main () {
const sheetNames = await readDir(SHEETS)
const tags = (await Promise.all(sheetNames
.map(sheetName => readFile(path.join(SHEETS, sheetName), 'utf8'))))
.map(sheet => sheet.split('\n').map(row => {
let [tag, description] = row.split(',').map(value => value.trim())
tag = tag.slice(0, 2)
return [tag, description]
}))
.reduce((tags, sheet, i) => {
const types = []
sheet.forEach(([tag, description]) => {
switch (tag) {
case 'TY':
return types.push(sheetNames[i].slice(0, -4) + ' - ' + description.replace(/`/g, ''))
case 'ER':
return
default:
if (!(tag in tags)) { tags[tag] = {} }
if (!(description in tags[tag])) { tags[tag][description] = [] }
tags[tag][description].push(...types)
return
}
})
return tags
}, {})
for (let tag in tags) {
for (let description in tags[tag]) {
tags[tag][description].sort()
}
}
console.log(tags)
writeFile(path.join(ROOT, 'specs', 'new', 'prop_summary.json'), JSON.stringify(tags, null, 2))
}
main()