forked from leverich/swiftislikescala
-
Notifications
You must be signed in to change notification settings - Fork 0
/
readTree.coffee
38 lines (29 loc) · 850 Bytes
/
readTree.coffee
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
fs = require('fs')
readFileTree = require('readfiletree')
get = (cb) ->
readFileTree 'comparisons/', (err, tree) ->
if err
cb(err)
return
out = {}
order = ""
for title, comps of tree
if title is 'order.txt'
order = comps.trim().split('\n')
else
out[title] = {}
for name, comp of comps
if name is 'alternatives.txt'
name = '_alternatives'
if name is 'order.txt'
name = '_order'
out[title][name] = {}
if typeof comp isnt 'string'
for filename, code of comp
[version, ext] = filename.split '.'
out[title][name][version] ?= {}
out[title][name][version][ext] = code
else
out[title][name] = comp
cb null, out, order
module.exports = get