-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
68 lines (53 loc) · 1.51 KB
/
index.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import walker from 'folder-walker'
import fs from 'fs'
import verovio from 'verovio'
const verovioOptions = {
"scale": 10,
"pageWidth": 1500,
"adjustPageHeight": true,
"adjustPageWidth": true,
"footer": "none",
"header":"none",
"openControlEvents": true,
"outputFormatRaw": true,
"removeIds": true,
"svgFormatRaw": true,
"svgHtml5": true,
"svgRemoveXlink": true,
"svgViewBox": true
}
/* Wait for verovio to load */
verovio.module.onRuntimeInitialized = () => {
const tk = new verovio.toolkit()
console.log('Using Verovio toolkit version: ' + tk.getVersion())
let stream = walker(['music-encoding/build/assets/images/GeneratedImages'])
let processFile = (path) => {
fs.readFile(path, 'utf-8', (err, data) => {
if (err) {
console.error(err)
return
}
try {
let svg = tk.renderData(data, verovioOptions);
fs.writeFile(path + '.svg', svg, writingError => {
if (err) {
console.error(writingError)
return
}
//file written successfully
})
console.log('\x1b[32m%s\x1b[0m', 'Successfully rendered ' + path)
} catch(renderError) {
console.log('Unable to render ' + path + ':')
//console.error(renderError)
}
//console.log(data)
});
}
stream.on('data', function (data) {
if (data.basename.endsWith('.mei') || data.basename.endsWith('.xml')) {
let path = data.filepath
processFile(path)
}
})
}