-
Notifications
You must be signed in to change notification settings - Fork 17
/
getSketchContents.js
32 lines (29 loc) · 965 Bytes
/
getSketchContents.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
const Task = require('folktale/concurrency/task')
const {List} = require('immutable-ext')
const getZipContents = require('./getZipContents')
const getFileFromZip = require('./getFileFromZip')
const listOfJSONFiles = zip => List(
Object.keys(zip.files)
.filter(path => path.slice(-5) === '.json')
)
module.exports = fileData =>
getZipContents(fileData)
.chain(zip =>
listOfJSONFiles(zip)
.traverse(Task.of, path => getFileFromZip(zip, path))
)
.map(parsedPairsList =>
parsedPairsList
.reduce((result, pair) => {
if (pair[0] === 'document.json') {
result.document = pair[1]
} else if (pair[0] === 'user.json') {
result.user = pair[1]
} else if (pair[0] === 'meta.json') {
result.meta = pair[1]
} else {
result.pages[pair[0].split('/')[1].slice(0, -5)] = pair[1]
}
return result
}, {pages: {}})
)