-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.js
43 lines (37 loc) · 952 Bytes
/
build.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
const fs = require('fs')
const {join} = require('path')
const sgf = require('@sabaki/sgf')
let root = sgf.parseFile(join(__dirname, 'library', 'library.sgf'))[0]
let library = []
for (let node of root.children) {
let anchors = node.data.MA.map(x => [
sgf.parseVertex(x),
node.data.AB.includes(x) ? 1 : -1,
])
let vertices = ['AW', 'CR', 'AB']
.map((x, i) => (node.data[x] || []).map(y => [sgf.parseVertex(y), i - 1]))
.reduce((acc, x) => [...acc, ...x], [])
let data = {}
if (node.data.C != null) {
for (let [key, ...values] of node.data.C[0]
.trim()
.split('\n')
.map(x => x.trim().slice(2).split(':'))) {
data[key.trim()] = values.join(':').trim()
}
}
library.push(
Object.assign(
{
name: node.data.N[0],
anchors,
vertices,
},
data
)
)
}
fs.writeFileSync(
join(__dirname, 'library', 'library.json'),
JSON.stringify(library)
)