パッケージの詳細

picklog

BearJ22MIT2.3.2

Pickup the logs that you filter, so you can generation changelog from it.

changelog, git log, log, generate log

readme

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 )

$ npm install -g picklog
$ picklog init
$ 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

const picklog = require('picklog');

picklog({
  latest: true, // The same as CLI '--latest'
  gitLogArgs: 'v2.0.0', // The same as CLI '--gitLogArgs'
}).then(function(markdownText){
  console.log(markdownText);
});

.picklogrc.js

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

module.exports = {
  filters: [
    {
      name: 'Features',
      regExp: /^(?:feat|add)/i,
    },
    {
      name: 'Bugfixes',
      regExp: /^fix/i,
    }
  ],
  parse(commits){
    return JSON.stringify(commits, null, 2);
  },
  tagFilter: /^v\d+\.\d+\.\d+$/, // Optional
};
参数 (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: )

module.exports = {
  filters: [
    {
      name: 'Features',
      regExp: /^(?:feat|add)/i,
    },
    {
      name: 'Bugfixes',
      regExp: /^fix/i,
    }
  ],
  parse(commits){
    let output = '';

    commits.forEach((log) => {
      let date = new Date(log.timestamp * 1000);
      date = `${date.getFullYear()}-${('0' + (date.getMonth() + 1)).substr(-2)}-${('0' + date.getDate()).substr(-2)}`;

      output += `### ${log.tag} (${date})\n\n`;

      log.results.forEach((result) => {
        result.commits.forEach((commit) => {
          output += `* ${commit.s}(${commit.h})\n`;
        });

        output += '\n';
      });

      output += '\n\n';
    });

    return output;
  },
  tagFilter: /^v\d+\.\d+\.\d+$/, // Optional
};

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

AngularJS Git Commit Guidelines

const origin = '<%= GitURL %>';
const comparePath = `${origin}/compare/`;
const commitPath = `${origin}/commit/`;

module.exports = {
  filters: [
    {
      name: 'Features',
      regExp: /^(?:feat|add)/i,
    },
    {
      name: 'Bugfixes',
      regExp: /^fix/i,
    }
  ],
  parse(commits){
    // RegExp.prototype.toJSON = RegExp.prototype.toString; // JSON.stringify会调用正则表达式的toJSON
    // return JSON.stringify(commits, null, 2); // output commits

    let output = '';

    commits.forEach((log) => {
      let date = new Date(log.timestamp * 1000);
      date = `${date.getFullYear()}-${('0' + (date.getMonth() + 1)).substr(-2)}-${('0' + date.getDate()).substr(-2)}`;

      let currentTag = log.tag || log.commits[0].h;
      let prevTag = log.previousTag || log.commits[log.commits.length - 1].h;
      output += `### [${currentTag}](${comparePath}${prevTag || ''}...${currentTag}) (${date})\n\n`;

      log.results.forEach((result) => {
        output += `#### ${result.filter.name}\n`;

        result.commits.forEach((commit) => {
          output += `* ${commit.s}([${commit.h}](${commitPath}${commit.h}))\n`;
        });

        output += '\n';
      });

      output += '\n\n';
    });

    return output;
  },
  tagFilter: /^v\d+\.\d+\.\d+$/, // Optional
};

更新履歴

v2.3.2 (2021-08-30)

Bugfixes

  • 如果没有上一个tag,则不需要迭代了。因为迭代会出很多过往的log,但其实并不是这次查log中需要的(6882d99)

v2.3.1 (2021-08-18)

Bugfixes

  • result为空的时候报错(4958c8a)

v2.3.0 (2021-08-18)

Features

  • 新增指定配置文件的能力(5f6590c)

v2.2.1 (2020-03-12)

Bugfixes

v2.2.0 (2019-11-05)

Features

  • 增加 tagFilter 来选取自己所需的 tag(1bb7b96)

Bugfixes

  • 当使用latest获取最近 logs 时,如果有合并分支,可能导致丢了某些 log 的问题(丢失特征:log的时间点比上一个tag还要旧)(7263516)

v2.1.4 (2019-09-26)

Bugfixes

  • 当第一次提交的时候没有tag,默认使用package.json的version(0bfd770)

v2.1.3 (2019-09-05)

Bugfixes

  • 当没有Changelog.md文件的时候会报错(5de6313)
  • 如果一开始项目没有tag的时候,报错找不到tag(f5d5f80)

v2.1.2 (2019-09-03)

Bugfixes

  • 读package.json的版本号的时候,必须格式要一致才能认(a3ba942)

v2.1.1 (2019-09-03)

v2.1.0 (2019-09-03)

Features

  • 当第一个tag分组找不到tag的时候,尝试从package.json里找(b0a43c1)

v2.0.1 (2019-07-13)

Features

  • 更新init生成的picklogrc,对新手更加友好(611e3fb)

v2.0.0 (2019-07-12)

Features

  • 增加picklog init来协助初始化 .picklogrc 文件(af06c37)
  • 使用git log来获取每个tag之间的commit,解决如果有merge的时候,commit会拉不全的问题。(080824b)

v1.2.3 (2019-07-5)

Bugfixes

  • 当tag是打在merge产生的commit的时候,会导致找不到tag的问题。因为git cherry不能提取merge的commit(d0a3453)

v1.2.2 (2019-05-22)

Bugfixes

  • 新项目在没有第一个的tag的时候,出现报错(3111693)

v1.2.1 (2019-03-15)

Bugfixes

  • 当使用--latest时,如果新内容有merge,那么会丢失比上一个tag还要早的commit的问题(ebe0f0c)

v1.2.0 (2019-02-19)

Features

  • 增加--latest参数,可以获得距离上一个tag提交的logs(ec1265c)

v1.1.2 (2019-02-18)

Bugfixes

Reverts

v1.1.1 (2019-02-18)

Bugfixes

  • --last参数最近一次提交没有tag时失效的问题(fe90439)

v1.1.0 (2019-02-18)

Features

  • 增加--last参数,用于获取距上一个tag的logs(8a43654)

Bugfixes

v1.0.1 (2019-02-17)

Bugfixes

  • 兼容没有.picklogrc的情况(843224b)
  • 兼容不传参数的情况(deba5dc)
  • result按filter的顺序来排列(3a940b6)

v1.0.0 (2019-02-15)

Features

  • Support string as argument(7131da0)

v0.3.2 (2019-02-13)

Bugfixes

v0.3.1 (2019-02-13)

v0.3.0 (2019-02-13)

v0.1.0 (2019-02-13)

v0.0.3 (2019-02-13)

Bugfixes

  • 要使用调用时的路径下的.picklog(ca5ce8a)

v0.0.2 (2019-02-12)