-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
43 lines (39 loc) · 1.04 KB
/
example.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 {
downloadDoc,
getTeamStyles,
getDocStyles
} = require('./index')
const fs = require('fs')
const { FILE_ID, API_KEY, TEAM_ID } = process.env
const example = async () => {
const doc = await downloadDoc(API_KEY, FILE_ID)
fs.writeFileSync('figma.json', JSON.stringify(doc, 0, 2))
// const doc = JSON.parse(fs.readFileSync('figma.json', 'utf-8'))
const styles = await getDocStyles(doc, await getTeamStyles(API_KEY, TEAM_ID, { page_size: 1000 }))
console.log('styles', arrangeByPages(styles))
}
const arrangeByPages = doc => {
const pages = {}
const {
name,
lastModified,
version,
...styles
} = doc
// console.log('====>', styles)
Object.keys(styles).map(type => {
Object.keys(styles[type]).map(id => {
const item = styles[type][id]
pages[item.page] = pages[item.page] || {}
pages[item.page][type] = pages[item.page][type] || {}
pages[item.page][type][id] = item
})
})
return {
name,
lastModified,
version,
pages
}
}
example().catch(err => console.error(err))