Simple email application for Android. Original source code: https://framagit.org/dystopia-project/simple-email
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

370 lines
12 KiB

  1. # [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage Status][coveralls-image]][coveralls-url]
  2. > Write logs based on conventional commits and templates
  3. ## Install
  4. ```sh
  5. $ npm install --save conventional-changelog-writer
  6. ```
  7. ## Usage
  8. ```js
  9. var conventionalChangelogWriter = require('conventional-changelog-writer');
  10. conventionalChangelogWriter(context, options);
  11. ```
  12. It returns a transform stream.
  13. It expects an object mode upstream that looks something like this:
  14. ```js
  15. { hash: '9b1aff905b638aa274a5fc8f88662df446d374bd',
  16. header: 'feat(scope): broadcast $destroy event on scope destruction',
  17. type: 'feat',
  18. scope: 'scope',
  19. subject: 'broadcast $destroy event on scope destruction',
  20. body: null,
  21. footer: 'Closes #1',
  22. notes: [],
  23. references: [ { action: 'Closes', owner: null, repository: null, issue: '1', raw: '#1' } ] }
  24. { hash: '13f31602f396bc269076ab4d389cfd8ca94b20ba',
  25. header: 'feat(ng-list): Allow custom separator',
  26. type: 'feat',
  27. scope: 'ng-list',
  28. subject: 'Allow custom separator',
  29. body: 'bla bla bla',
  30. footer: 'BREAKING CHANGE: some breaking change',
  31. notes: [ { title: 'BREAKING CHANGE', text: 'some breaking change' } ],
  32. references: [] }
  33. ```
  34. Each chunk should be a commit. Json object is also **valid**. Parts of the objects will be formatted and combined into a log based on the handlebars context, templates and options.
  35. The downstream might look something like this:
  36. ```js
  37. ## 0.0.1 "this is a title" (2015-05-29)
  38. ### Features
  39. * **ng-list:** Allow custom separator ([13f3160](https://github.com/a/b/commits/13f3160))
  40. * **scope:** broadcast $destroy event on scope destruction ([9b1aff9](https://github.com/a/b/commits/9b1aff9)), closes [#1](https://github.com/a/b/issues/1)
  41. ### BREAKING CHANGES
  42. * some breaking change
  43. ```
  44. ## API
  45. ### conventionalChangelogWriter([context, [options]])
  46. Returns a transform stream.
  47. #### context
  48. Variables that will be interpolated to the template. This object contains, but not limits to the following fields.
  49. ##### version
  50. Type: `string`
  51. Version number of the up-coming release. If `version` is found in the last commit before generating logs, it will be overwritten.
  52. ##### title
  53. Type: `string`
  54. ##### isPatch
  55. Type: `boolean` Default: `semver.patch(context.version) !== 0`
  56. By default, this value is true if `version`'s patch is `0`.
  57. ##### host
  58. Type: `string`
  59. The hosting website. Eg: `'https://github.com'` or `'https://bitbucket.org'`
  60. ##### owner
  61. Type: `string`
  62. The owner of the repository. Eg: `'stevemao'`.
  63. ##### repository
  64. Type: `string`
  65. The repository name on `host`. Eg: `'conventional-changelog-writer'`.
  66. ##### repoUrl
  67. Type: `string`
  68. The whole repository url. Eg: `'https://github.com/conventional-changelog/conventional-changelog-writer'`.
  69. The should be used as a fallback when `context.repository` doesn't exist.
  70. ##### linkReferences
  71. Type: `boolean` Default: `true` if (`context.repository` or `context.repoUrl`), `context.commit` and `context.issue` are truthy
  72. Should all references be linked?
  73. ##### commit
  74. Type: `string` Default: `'commits'`
  75. Commit keyword in the url if `context.linkReferences === true`.
  76. ##### issue
  77. Type: `string` Default: `'issues'`
  78. Issue or pull request keyword in the url if `context.linkReferences === true`.
  79. ##### date
  80. Type: `string` Default: `dateFormat(new Date(), 'yyyy-mm-dd', true)`
  81. Default to formatted (`'yyyy-mm-dd'`) today's date. [dateformat](https://github.com/felixge/node-dateformat) is used for formatting the date. If `version` is found in the last commit, `committerDate` will overwrite this.
  82. #### options
  83. Type: `object`
  84. ##### transform
  85. Type: `object` or `function` Default: get the first 7 digits of hash, and `committerDate` will be formatted as `'yyyy-mm-dd'`.
  86. Replace with new values in each commit.
  87. If this is an object, the keys are paths to a nested object property. the values can be a string (static) and a function (dynamic) with the old value and path passed as arguments. This value is merged with your own transform object.
  88. If this is a function, the commit chunk will be passed as the argument and the returned value would be the new commit object. This is a handy function if you can't provide a transform stream as an upstream of this one. If returns a falsy value this commit is ignored.
  89. a `raw` object that is originally poured form upstream is attached to `commit`.
  90. ##### groupBy
  91. Type: `string` Default: `'type'`
  92. How to group the commits. EG: based on the same type. If this value is falsy, commits are not grouped.
  93. ##### commitGroupsSort
  94. Type: `function`, `string` or `array`
  95. A compare function used to sort commit groups. If it's a string or array, it sorts on the property(ies) by `localeCompare`. Will not sort if this is a falsy value.
  96. The string can be a dot path to a nested object property.
  97. ##### commitsSort
  98. Type: `function`, `string` or `array` Default: `'header'`
  99. A compare function used to sort commits. If it's a string or array, it sorts on the property(ies) by `localeCompare`. Will not sort if this is a falsy value.
  100. The string can be a dot path to a nested object property.
  101. ##### noteGroupsSort
  102. Type: `function`, `string` or `array` Default: `'title'`
  103. A compare function used to sort note groups. If it's a string or array, it sorts on the property(ies) by `localeCompare`. Will not sort if this is a falsy value.
  104. The string can be a dot path to a nested object property.
  105. ##### notesSort
  106. Type: `function`, `string` or `array` Default: `'text'`
  107. A compare function used to sort note groups. If it's a string or array, it sorts on the property(ies) by `localeCompare`. Will not sort if this is a falsy value.
  108. The string can be a dot path to a nested object property.
  109. ##### generateOn
  110. Type: `function`, `string` or `any` Default: if `commit.version` is a valid semver.
  111. When the upstream finishes pouring the commits it will generate a block of logs if `doFlush` is `true`. However, you can generate more than one block based on this criteria (usually a version) even if there are still commits from the upstream.
  112. ###### generateOn(commit, commits, context, options)
  113. ####### commit
  114. Current commit.
  115. ####### commits
  116. Current collected commits.
  117. ####### context
  118. The generated context based on original input `context` and `options`.
  119. ####### options
  120. Normalized options.
  121. **NOTE**: It checks on the transformed commit chunk instead of the original one (you can check on the original by access the `raw` object on the `commit`). However, if the transformed commit is ignored it falls back to the original commit.
  122. If this value is a `string`, it checks the existence of the field. Set to other type to disable it.
  123. ##### finalizeContext
  124. Type: `function` Default: pass through
  125. Last chance to modify your context before generating a changelog.
  126. ###### finalizeContext(context, options, commits, keyCommit)
  127. ####### context
  128. The generated context based on original input `context` and `options`.
  129. ####### options
  130. Normalized options.
  131. ####### commits
  132. Filtered commits from your git metadata.
  133. ####### keyCommit
  134. The commit that triggers to generate the log.
  135. ##### debug
  136. Type: `function` Default: `function() {}`
  137. A function to get debug information.
  138. ##### reverse
  139. Type: `boolean` Default: `false`
  140. The normal order means reverse chronological order. `reverse` order means chronological order. Are the commits from upstream in the reverse order? You should only worry about this when generating more than one blocks of logs based on `generateOn`. If you find the last commit is in the wrong block inverse this value.
  141. ##### includeDetails
  142. Type: `boolean` Default: `false`
  143. If this value is `true`, instead of emitting strings of changelog, it emits objects containing the details the block.
  144. *NOTE:* The downstream must be in object mode if this is `true`.
  145. ##### ignoreReverted
  146. Type: `boolean` Default: `true`
  147. If `true`, reverted commits will be ignored.
  148. ##### doFlush
  149. Type: `boolean` Default: `true`
  150. If `true`, the stream will flush out the last bit of commits (could be empty) to changelog.
  151. ##### mainTemplate
  152. Type: `string` Default: [template.hbs](templates/template.hbs)
  153. The main handlebars template.
  154. ##### headerPartial
  155. Type: `string` Default: [header.hbs](templates/header.hbs)
  156. ##### commitPartial
  157. Type: `string` Default: [commit.hbs](templates/commit.hbs)
  158. ##### footerPartial
  159. Type: `string` Default: [footer.hbs](templates/footer.hbs)
  160. ##### partials
  161. Type: `object`
  162. Partials that used in the main template, if any. The key should be the partial name and the value should be handlebars template strings. If you are using handlebars template files, read files by yourself.
  163. ## Customization Guide
  164. It is possible to customize this the changelog to suit your needs. Templates are written in [handlebars](http://handlebarsjs.com). You can customize all partials or the whole template. Template variables are from either `upstream` or `context`. The following are a suggested way of defining variables.
  165. ### upstream
  166. Variables in upstream are commit specific and should be used per commit. Eg: *commit date* and *commit username*. You can think of them as "local" or "isolate" variables. A "raw" commit message (original commit poured from upstream) is attached to `commit`. `transform` can be used to modify a commit.
  167. ### context
  168. context should be module specific and can be used across the whole log. Thus these variables should not be related to any single commit and should be generic information of the module or all commits. Eg: *repository url* and *author names*, etc. You can think of them as "global" or "root" variables.
  169. Basically you can make your own templates and define all your template context. Extra context are based on commits from upstream and `options`. For more details, please checkout [handlebars](http://handlebarsjs.com) and the source code of this module. `finalizeContext` can be used at last to modify context before generating a changelog.
  170. ## CLI
  171. ```sh
  172. $ npm install --global conventional-changelog-writer
  173. $ conventional-changelog-writer --help # for more details
  174. ```
  175. It works with [Line Delimited JSON](http://en.wikipedia.org/wiki/Line_Delimited_JSON).
  176. If you have commits.ldjson
  177. ```js
  178. {"hash":"9b1aff905b638aa274a5fc8f88662df446d374bd","header":"feat(ngMessages): provide support for dynamic message resolution","type":"feat","scope":"ngMessages","subject":"provide support for dynamic message resolution","body":"Prior to this fix it was impossible to apply a binding to a the ngMessage directive to represent the name of the error.","footer":"BREAKING CHANGE: The `ngMessagesInclude` attribute is now its own directive and that must be placed as a **child** element within the element with the ngMessages directive.\nCloses #10036\nCloses #9338","notes":[{"title":"BREAKING CHANGE","text":"The `ngMessagesInclude` attribute is now its own directive and that must be placed as a **child** element within the element with the ngMessages directive."}],"references":[{"action":"Closes","owner",null,"repository":null,"issue":"10036","raw":"#10036"},{"action":"Closes","owner":null,"repository":null,"issue":"9338","raw":"#9338"}]}
  179. ```
  180. And you run
  181. ```sh
  182. $ conventional-changelog-writer commits.ldjson -o options.js
  183. ```
  184. The output might look something like this
  185. ```md
  186. # 1.0.0 (2015-04-09)
  187. ### Features
  188. * **ngMessages:** provide support for dynamic message resolution 9b1aff9, closes #10036 #9338
  189. ### BREAKING CHANGES
  190. * The `ngMessagesInclude` attribute is now its own directive and that must be placed as a **child** element within the element with the ngMessages directive.
  191. ```
  192. It is printed to stdout.
  193. ## License
  194. MIT © [Steve Mao](https://github.com/stevemao)
  195. [npm-image]: https://badge.fury.io/js/conventional-changelog-writer.svg
  196. [npm-url]: https://npmjs.org/package/conventional-changelog-writer
  197. [travis-image]: https://travis-ci.org/conventional-changelog/conventional-changelog-writer.svg?branch=master
  198. [travis-url]: https://travis-ci.org/conventional-changelog/conventional-changelog-writer
  199. [daviddm-image]: https://david-dm.org/conventional-changelog/conventional-changelog-writer.svg?theme=shields.io
  200. [daviddm-url]: https://david-dm.org/conventional-changelog/conventional-changelog-writer
  201. [coveralls-image]: https://coveralls.io/repos/conventional-changelog/conventional-changelog-writer/badge.svg
  202. [coveralls-url]: https://coveralls.io/r/conventional-changelog/conventional-changelog-writer