-
Notifications
You must be signed in to change notification settings - Fork 711
/
writer-opts.js
45 lines (36 loc) · 1.15 KB
/
writer-opts.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
'use strict'
const { readFile } = require('fs').promises
const { resolve } = require('path')
module.exports = Promise.all([
readFile(resolve(__dirname, './templates/template.hbs'), 'utf-8'),
readFile(resolve(__dirname, './templates/header.hbs'), 'utf-8'),
readFile(resolve(__dirname, './templates/commit.hbs'), 'utf-8')
])
.then(([template, header, commit]) => {
const writerOpts = getWriterOpts()
writerOpts.mainTemplate = template
writerOpts.headerPartial = header
writerOpts.commitPartial = commit
return writerOpts
})
function getWriterOpts () {
return {
transform: (commit) => {
if (!commit.emoji || typeof commit.emoji !== 'string') {
return
}
commit.emoji = commit.emoji.substring(0, 72)
const emojiLength = commit.emoji.length
if (typeof commit.hash === 'string') {
commit.shortHash = commit.hash.substring(0, 7)
}
if (typeof commit.shortDesc === 'string') {
commit.shortDesc = commit.shortDesc.substring(0, 72 - emojiLength)
}
return commit
},
groupBy: 'emoji',
commitGroupsSort: 'title',
commitsSort: ['emoji', 'shortDesc']
}
}