UNPKG

845 BJavaScriptView Raw
1const fs = require('fs')
2const log = console.log
3
4module.exports = {
5 parse(path) {
6 let src = fs.readFileSync(path, 'utf-8')
7 let toc = { lua: [], xml: [] }
8
9 src
10 .split('\r')
11 .map(x => x.trim())
12 .forEach(line => {
13 line = line.trim()
14
15 if (line.match(/^##/)) {
16 let pair = line
17 .substring(2)
18 .split(':')
19 .map(x => x.trim())
20
21 if (!pair[1]) return
22
23 toc[pair[0]] =
24 pair[0] === 'Dependencies' || pair[0] === 'SavedVariables'
25 ? pair[1].split(',').map(x => x.trim())
26 : pair[1]
27 } else if (line.match(/^#/)) return
28 else if (line.match(/\.lua/)) {
29 toc.lua.push(line)
30 } else if (line.match(/\.xml/)) {
31 toc.xml.push(line)
32 }
33 })
34
35 return toc
36 }
37}