npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

picklog

v2.3.2

Published

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

Downloads

82

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
};