forked from sizovs/mustread-data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateStats.js
28 lines (26 loc) · 1021 Bytes
/
generateStats.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
const dayjs = require('dayjs')
const GitFile = require('./classes/GitFile')
const commitMonth = rev => dayjs(rev.commit.date()).format('MMMM')
module.exports = books =>
Promise
.all(books
.map(book =>
new GitFile(book.location)
.revs()
.then(([firstRev]) => {
let isbn = book.objectID
if (!firstRev) {
console.warn('😵 Cannot get git history of ' + book.location)
return undefined
} else {
return { isbn: isbn.toString(), month: commitMonth(firstRev) }
}
})
)
)
.then(stats => stats
.filter(stat => stat)
.reduce((acc, curr) =>
Object.assign(acc, {[curr.month]: [curr.isbn].concat(acc[curr.month] || [])}), {}
))
.then(JSON.stringify)