Skip to content

Commit 611e3fb

Browse files
committed
feat: 更新init生成的picklogrc,对新手更加友好
1 parent 6885c12 commit 611e3fb

File tree

3 files changed

+80
-45
lines changed

3 files changed

+80
-45
lines changed

.picklogrc.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ module.exports = {
2121
regExp: /^revert(\(.*?\))?:\s/i,
2222
},
2323
],
24-
parse(picklog) {
24+
parse(commits) {
2525
// RegExp.prototype.toJSON = RegExp.prototype.toString; // JSON.stringify会调用正则表达式的toJSON
26-
// return JSON.stringify(picklog, null, 2);
26+
// return JSON.stringify(commits, null, 2);
2727

2828
let output = '';
2929

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

README.md

Lines changed: 68 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,32 @@ $ picklog -o CHANGELOG.md
2121
- **`init`**
2222

2323
生成配置文件`.picklogrc.js` ( Generator a setting file `.picklogrc.js` )
24-
24+
2525
e.g: `picklog init`
2626

2727
- **`-w` or `--write`**
2828

2929
把输出添加到指定文件 ( Append stdout to a file )
30-
30+
3131
e.g: `picklog -w CHANGELOG.md`
32-
32+
3333
- **`-o` or `--overwrite`**
34-
34+
3535
把输出覆盖到指定文件 ( Overwrite stdout to a file )
36-
36+
3737
e.g: `picklog -o CHANGELOG.md`
38-
38+
3939
- **`-l` or `--latest`**
40-
40+
4141
只获取距离上一次tag间的修改 ( Only pick latest changes after the last tag )
42-
42+
4343
e.g: `picklog -l -w CHANGELOG.md`
44-
44+
4545

4646
- **`-g` or `--gitLogArgs`**
47-
47+
4848
透传给`git log`的参数,以英文逗号分隔 ( Pass the arg to "git log". Splited by **comma** )
49-
49+
5050
e.g: `picklog -g v2.0.0 -w CHANGELOG.md`
5151

5252

@@ -79,8 +79,8 @@ module.exports = {
7979
regExp: /^fix/i,
8080
}
8181
],
82-
parse(picklog){
83-
return JSON.stringify(picklog, null, 2);
82+
parse(commits){
83+
return JSON.stringify(commits, null, 2);
8484
},
8585
};
8686
```
@@ -106,13 +106,13 @@ module.exports = {
106106
regExp: /^fix/i,
107107
}
108108
],
109-
parse(picklog){
109+
parse(commits){
110110
let output = '';
111111

112-
picklog.forEach((log) => {
112+
commits.forEach((log) => {
113113
let date = new Date(log.timestamp * 1000);
114114
date = `${date.getFullYear()}-${('0' + (date.getMonth() + 1)).substr(-2)}-${('0' + date.getDate()).substr(-2)}`;
115-
115+
116116
output += `### ${log.tag} (${date})\n\n`;
117117

118118
log.results.forEach((result) => {
@@ -130,3 +130,55 @@ module.exports = {
130130
}
131131
};
132132
```
133+
134+
### 适配AngularJS推荐的Git Commit格式 ( AngularJS Git Commit Guidelines )
135+
136+
[AngularJS Git Commit Guidelines](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#commits)
137+
138+
```javascript
139+
const origin = '<%= GitURL %>';
140+
const comparePath = `${origin}/compare/`;
141+
const commitPath = `${origin}/commit/`;
142+
143+
module.exports = {
144+
filters: [
145+
{
146+
name: 'Features',
147+
regExp: /^(?:feat|add)/i,
148+
},
149+
{
150+
name: 'Bugfixes',
151+
regExp: /^fix/i,
152+
}
153+
],
154+
parse(commits){
155+
// RegExp.prototype.toJSON = RegExp.prototype.toString; // JSON.stringify会调用正则表达式的toJSON
156+
// return JSON.stringify(commits, null, 2); // output commits
157+
158+
let output = '';
159+
160+
commits.forEach((log) => {
161+
let date = new Date(log.timestamp * 1000);
162+
date = `${date.getFullYear()}-${('0' + (date.getMonth() + 1)).substr(-2)}-${('0' + date.getDate()).substr(-2)}`;
163+
164+
let currentTag = log.tag || log.commits[0].h;
165+
let prevTag = log.previousTag || log.commits[log.commits.length - 1].h;
166+
output += `### [${currentTag}](${comparePath}${prevTag || ''}...${currentTag}) (${date})\n\n`;
167+
168+
log.results.forEach((result) => {
169+
output += `#### ${result.filter.name}\n`;
170+
171+
result.commits.forEach((commit) => {
172+
output += `* ${commit.s}([${commit.h}](${commitPath}${commit.h}))\n`;
173+
});
174+
175+
output += '\n';
176+
});
177+
178+
output += '\n\n';
179+
});
180+
181+
return output;
182+
}
183+
};
184+
```

bin/.picklogrc.js

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,22 @@ module.exports = {
66
filters: [
77
{
88
name: 'Features',
9-
regExp: /^feat(\(.*?\))?:\s/i,
9+
regExp: /^(?:feat|add)/i,
1010
},
1111
{
1212
name: 'Bugfixes',
13-
regExp: /^fix(\(.*?\))?:\s/i,
14-
},
15-
{
16-
name: 'Performance Improvements',
17-
regExp: /^perf(\(.*?\))?:\s/i,
18-
},
19-
{
20-
name: 'Reverts',
21-
regExp: /^revert(\(.*?\))?:\s/i,
22-
},
13+
regExp: /^fix/i,
14+
}
2315
],
24-
parse(picklog) {
16+
parse(commits){
2517
// RegExp.prototype.toJSON = RegExp.prototype.toString; // JSON.stringify会调用正则表达式的toJSON
26-
// return JSON.stringify(picklog, null, 2);
18+
// return JSON.stringify(commits, null, 2); // output commits
2719

2820
let output = '';
2921

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

3426
let currentTag = log.tag || log.commits[0].h;
3527
let prevTag = log.previousTag || log.commits[log.commits.length - 1].h;
@@ -39,16 +31,7 @@ module.exports = {
3931
output += `#### ${result.filter.name}\n`;
4032

4133
result.commits.forEach((commit) => {
42-
const { regExp } = result.filter;
43-
let subject = commit.s.match(regExp) || '';
44-
45-
if (subject[1]) {
46-
const type = subject[1].match(/\((.*?)\)/)[1];
47-
subject = `**${type}:** ${commit.s.replace(regExp, '')}`;
48-
} else {
49-
subject = commit.s.replace(regExp, '');
50-
}
51-
output += `* ${subject}([${commit.h}](${commitPath}${commit.h}))\n`;
34+
output += `* ${commit.s}([${commit.h}](${commitPath}${commit.h}))\n`;
5235
});
5336

5437
output += '\n';
@@ -58,5 +41,5 @@ module.exports = {
5841
});
5942

6043
return output;
61-
},
44+
}
6245
};

0 commit comments

Comments
 (0)