项目作者: BearJ

项目描述 :
根据你设置的filter,提取出你需要的log,从而生成changelog。 (Generate changelog from git log.)
高级语言: JavaScript
项目地址: git://github.com/BearJ/picklog.git
创建时间: 2019-02-12T09:35:37Z
项目社区:https://github.com/BearJ/picklog

开源协议:

下载


Picklog

npm version

根据你设置的filter,提取出你需要的log,从而生成changelog。可以生成JSONmarkdown

( Pickup the logs that you filter, so you can generation changelog from it. You can get JSON or markdown you want. )

快速上手 ( Usage )

  1. $ npm install -g picklog
  2. $ picklog init
  3. $ picklog -o CHANGELOG.md

运行完 picklog init 后,会在你的项目下生成.picklogrc.js文件。你可以通过修改.picklogrc.js文件里的规则来控制changelog的生成。

( After running picklog init, it generator a file .picklogrc.js in your project. You can modify .picklogrc.js to control the rules to generator changelog. Scroll up to see more detail. )

CLI

  • init

    生成配置文件.picklogrc.js ( Generator a setting file .picklogrc.js )

    e.g: picklog init

  • -w or --write

    把输出添加到指定文件 ( Append stdout to a file )

    e.g: picklog -w CHANGELOG.md

  • -o or --overwrite

    把输出覆盖到指定文件 ( Overwrite stdout to a file )

    e.g: picklog -o CHANGELOG.md

  • -l or --latest

    只获取距离上一次tag间的修改 ( Only pick latest changes after the last tag )

    e.g: picklog -l -w CHANGELOG.md

  • -g or --gitLogArgs

    透传给git log的参数,以英文逗号分隔 ( Pass the arg to “git log”. Splited by comma )

    e.g: picklog -g v2.0.0 -w CHANGELOG.md

  • -c or --config

    指定配置文件,默认是.picklogrc.js ( Custom config file. Default “.picklogrc” )

    e.g: picklog -c .picklogrc.dev.js

API

  1. const picklog = require('picklog');
  2. picklog({
  3. latest: true, // The same as CLI '--latest'
  4. gitLogArgs: 'v2.0.0', // The same as CLI '--gitLogArgs'
  5. }).then(function(markdownText){
  6. console.log(markdownText);
  7. });

.picklogrc.js

这是一个输出为json的demo。( Here is demo that the output is json. )

  1. module.exports = {
  2. filters: [
  3. {
  4. name: 'Features',
  5. regExp: /^(?:feat|add)/i,
  6. },
  7. {
  8. name: 'Bugfixes',
  9. regExp: /^fix/i,
  10. }
  11. ],
  12. parse(commits){
  13. return JSON.stringify(commits, null, 2);
  14. },
  15. tagFilter: /^v\d+\.\d+\.\d+$/, // Optional
  16. };
参数 (Args) 必填 (Required) 说明 (Introduction) 类型 (Type)
filters Yes 规定了选取log的正则,你也可以在output里获得它。( filters use regexp filter logs, you can alse get this in output. ) Array
parse Yes 你可以对你过滤的logs进行解析的函数。参数commits的结构可看这里。( parse is the function that you can parse your output with the logs you filter. Here is thecommits example. ) Function
tagFilter False 规定了选取tag的正则。( tagFilter use regexp filter tag. ) RegExp

我想要Markdown ( I want Markdown )

如果你需要输出为markdown,你可以用以下的 .picklogrc.js 。( If you want markdown output, you can use .picklogrc.js like this: )

  1. module.exports = {
  2. filters: [
  3. {
  4. name: 'Features',
  5. regExp: /^(?:feat|add)/i,
  6. },
  7. {
  8. name: 'Bugfixes',
  9. regExp: /^fix/i,
  10. }
  11. ],
  12. parse(commits){
  13. let output = '';
  14. commits.forEach((log) => {
  15. let date = new Date(log.timestamp * 1000);
  16. date = `${date.getFullYear()}-${('0' + (date.getMonth() + 1)).substr(-2)}-${('0' + date.getDate()).substr(-2)}`;
  17. output += `### ${log.tag} (${date})\n\n`;
  18. log.results.forEach((result) => {
  19. result.commits.forEach((commit) => {
  20. output += `* ${commit.s}(${commit.h})\n`;
  21. });
  22. output += '\n';
  23. });
  24. output += '\n\n';
  25. });
  26. return output;
  27. },
  28. tagFilter: /^v\d+\.\d+\.\d+$/, // Optional
  29. };

适配AngularJS推荐的Git Commit格式 ( AngularJS Git Commit Guidelines )

AngularJS Git Commit Guidelines

  1. const origin = '<%= GitURL %>';
  2. const comparePath = `${origin}/compare/`;
  3. const commitPath = `${origin}/commit/`;
  4. module.exports = {
  5. filters: [
  6. {
  7. name: 'Features',
  8. regExp: /^(?:feat|add)/i,
  9. },
  10. {
  11. name: 'Bugfixes',
  12. regExp: /^fix/i,
  13. }
  14. ],
  15. parse(commits){
  16. // RegExp.prototype.toJSON = RegExp.prototype.toString; // JSON.stringify会调用正则表达式的toJSON
  17. // return JSON.stringify(commits, null, 2); // output commits
  18. let output = '';
  19. commits.forEach((log) => {
  20. let date = new Date(log.timestamp * 1000);
  21. date = `${date.getFullYear()}-${('0' + (date.getMonth() + 1)).substr(-2)}-${('0' + date.getDate()).substr(-2)}`;
  22. let currentTag = log.tag || log.commits[0].h;
  23. let prevTag = log.previousTag || log.commits[log.commits.length - 1].h;
  24. output += `### [${currentTag}](${comparePath}${prevTag || ''}...${currentTag}) (${date})\n\n`;
  25. log.results.forEach((result) => {
  26. output += `#### ${result.filter.name}\n`;
  27. result.commits.forEach((commit) => {
  28. output += `* ${commit.s}([${commit.h}](${commitPath}${commit.h}))\n`;
  29. });
  30. output += '\n';
  31. });
  32. output += '\n\n';
  33. });
  34. return output;
  35. },
  36. tagFilter: /^v\d+\.\d+\.\d+$/, // Optional
  37. };