-
Notifications
You must be signed in to change notification settings - Fork 1
/
versions_download.js
90 lines (41 loc) · 1.33 KB
/
versions_download.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const contentful = require('contentful-management');
const fs = require('fs');
const client = contentful.createClient({
accessToken: process.env.CMA_API_KEY,
});
const getData = async () => {
let allEntries = []
let entries = {}
let skip = 0
let total = 100
while (skip < total) {
entries = await client
.getSpace('knkzaf64jx5x')
.then((space) => space.getEnvironment('master'))
.then((env) => env.getEntries({ skip }))
.catch(console.error)
allEntries = [...allEntries, ...entries.items]
skip += entries.items.length
total = entries.total
}
const totalLenEntries = allEntries.length
console.log('Total Entries count', totalLenEntries)
const snapshots = {}
for (let index = 0; index < totalLenEntries; index++) {
console.log('Getting Snapshots Progress: %d%', (((index + 1) / totalLenEntries) * 100).toFixed(2))
const entry = allEntries[index]
await entry
.getSnapshots()
.then((data) => {
snapshots[entry.sys.id] = data;
})
.catch(console.error);
}
console.log('Total snapshots for entries', Object.keys(snapshots).length)
fs.writeFileSync('output/snapshots.json', JSON.stringify(snapshots), 'utf8', (err) => {
console.log(err)
if (err) throw err
console.log('complete')
})
}
getData()