writer-opts.js 912 B

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict'
  2. const Q = require('q')
  3. const readFile = Q.denodeify(require('fs').readFile)
  4. const resolve = require('path').resolve
  5. module.exports = Q.all([
  6. readFile(resolve(__dirname, './templates/template.hbs'), 'utf-8'),
  7. readFile(resolve(__dirname, './templates/header.hbs'), 'utf-8'),
  8. readFile(resolve(__dirname, './templates/commit.hbs'), 'utf-8')
  9. ])
  10. .spread((template, header, commit) => {
  11. const writerOpts = getWriterOpts()
  12. writerOpts.mainTemplate = template
  13. writerOpts.headerPartial = header
  14. writerOpts.commitPartial = commit
  15. return writerOpts
  16. })
  17. function getWriterOpts () {
  18. return {
  19. transform: (commit) => {
  20. if (!commit.tag || typeof commit.tag !== 'string') {
  21. return
  22. }
  23. commit.shortHash = commit.hash.substring(0, 7)
  24. return commit
  25. },
  26. groupBy: 'tag',
  27. commitGroupsSort: 'title',
  28. commitsSort: ['tag', 'message']
  29. }
  30. }