UNPKG

1.33 kBJavaScriptView Raw
1'use strict'
2
3const { readFile } = require('fs').promises
4const { resolve } = require('path')
5
6module.exports = Promise.all([
7 readFile(resolve(__dirname, './templates/template.hbs'), 'utf-8'),
8 readFile(resolve(__dirname, './templates/header.hbs'), 'utf-8'),
9 readFile(resolve(__dirname, './templates/commit.hbs'), 'utf-8')
10])
11 .then(([template, header, commit]) => {
12 const writerOpts = getWriterOpts()
13
14 writerOpts.mainTemplate = template
15 writerOpts.headerPartial = header
16 writerOpts.commitPartial = commit
17
18 return writerOpts
19 })
20
21function getWriterOpts () {
22 return {
23 transform: (commit) => {
24 if (!commit.pr) {
25 return
26 }
27
28 if (commit.tag === 'BUGFIX') {
29 commit.tag = 'Bug Fixes'
30 } else if (commit.tag === 'CLEANUP') {
31 commit.tag = 'Cleanup'
32 } else if (commit.tag === 'FEATURE') {
33 commit.tag = 'Features'
34 } else if (commit.tag === 'DOC') {
35 commit.tag = 'Documentation'
36 } else if (commit.tag === 'SECURITY') {
37 commit.tag = 'Security'
38 } else {
39 return
40 }
41
42 if (typeof commit.hash === 'string') {
43 commit.shortHash = commit.hash.substring(0, 7)
44 }
45
46 return commit
47 },
48 groupBy: 'tag',
49 commitGroupsSort: 'title',
50 commitsSort: ['tag', 'taggedAs', 'message']
51 }
52}