Skip to content

Commit 080824b

Browse files
committed
feat: 使用git log来获取每个tag之间的commit,解决如果有merge的时候,commit会拉不全的问题。
1 parent 82ba74a commit 080824b

16 files changed

+727
-366
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ module.exports = {
1111
'no-param-reassign': ['error', { 'props': false }], // 允许修改入参的属性
1212
'no-continue': 'off', // 在我的代码里,continue; 就类似于 return; 的作用
1313
'no-labels': 'off', // 在我的代码里,就类似于 return; 的作用
14+
'no-trailing-spaces': 'off',
1415
}
1516
};

.picklogrc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module.exports = {
2929

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

3434
output += `### [${log.tag}](${comparePath}${log.previousTag || ''}...${log.tag}) (${date})\n\n`;
3535

@@ -59,4 +59,4 @@ module.exports = {
5959

6060
return output;
6161
},
62-
};
62+
};

bin/picklog.js

100644100755
Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,49 @@
11
#!/usr/bin/env node
22

3+
const fs = require('fs');
4+
const { resolve } = require('path');
5+
const yargs = require('yargs');
36
const picklog = require('../index');
47

5-
picklog(process.argv.slice(2))
8+
const { argv } = yargs
9+
.alias('h', 'help')
10+
.alias('v', 'version')
11+
12+
.option('g', {
13+
alias: 'gitLogArgs',
14+
describe: 'Pass the arg to "git log". Splited by comma. e.g: picklog -g v2.0.0',
15+
})
16+
.option('l', {
17+
alias: 'latest',
18+
describe: 'Only pick latest changes after the last tag.',
19+
})
20+
21+
.option('w', {
22+
alias: 'write',
23+
describe: 'Append stdout to this file.',
24+
})
25+
.option('o', {
26+
alias: 'overwrite',
27+
describe: 'Overwrite stdout to this file.',
28+
});
29+
30+
if (argv.overwrite && typeof argv.overwrite !== 'string') {
31+
console.warn('Please type a file name. eg: picklog -o changelog.md');
32+
return;
33+
}
34+
35+
if (argv.write && typeof argv.write !== 'string') {
36+
console.warn('Please type a file name. eg: picklog -w changelog.md');
37+
return;
38+
}
39+
40+
picklog(argv)
641
.then((commits) => {
7-
process.stdout.write(commits);
42+
if (argv.overwrite) {
43+
fs.writeFileSync(resolve(argv.overwrite), commits, 'utf8');
44+
} else if (argv.write) {
45+
fs.writeFileSync(resolve(argv.write), commits + fs.readFileSync(resolve(argv.write), 'utf8'));
46+
} else {
47+
console.log(commits);
48+
}
849
});

index.js

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,15 @@
11
const fs = require('fs');
22
const path = require('path');
3-
const getCommits = require('./lib/getCommits');
4-
const getLatestCommits = require('./lib/getLatestCommits');
3+
const getCommits = require('./src/getCommits');
4+
const defaultSetting = require('./src/lib/defaultSetting');
55

6-
const defaultSetting = {
7-
filters: [
8-
{
9-
name: 'Features',
10-
regExp: /^feat(\(.*?\))?:\s/i,
11-
},
12-
{
13-
name: 'Bugfixes',
14-
regExp: /^fix(\(.*?\))?:\s/i,
15-
},
16-
],
17-
parse(logs) {
18-
/* eslint-disable-next-line no-extend-native */
19-
RegExp.prototype.toJSON = RegExp.prototype.toString; // JSON.stringify会调用正则表达式的toJSON
20-
return JSON.stringify(logs, null, 2);
21-
},
22-
};
23-
24-
function picklog(_args = []) {
25-
let args = _args;
26-
let isLatest = false;
6+
function picklog(_args) {
7+
const args = Object.assign({
8+
gitLogArgs: '', // 透传给命令 git log 的参数
9+
latest: false, // 是否只取上一个tag后的commit
10+
}, _args);
2711
let setting;
2812

29-
if (typeof args === 'string') {
30-
args = args.split(' ');
31-
}
32-
33-
if (args.indexOf('--latest') > -1) {
34-
isLatest = true;
35-
args.splice(args.indexOf('--latest'), 1);
36-
}
37-
3813
try {
3914
fs.accessSync(path.resolve('.picklogrc.js'));
4015
setting = require(path.resolve('.picklogrc.js')); // eslint-disable-line global-require,import/no-dynamic-require
@@ -43,17 +18,13 @@ function picklog(_args = []) {
4318
}
4419

4520
return new Promise((resolve) => {
46-
getCommits(args, setting)
47-
.then((commits) => {
48-
if (isLatest) {
49-
getLatestCommits(commits, setting).then((latestCommits) => {
50-
resolve(setting.parse(latestCommits));
51-
});
52-
} else {
53-
resolve(setting.parse(commits));
54-
}
55-
});
21+
getCommits(args, setting).then((commits) => {
22+
resolve(setting.parse(commits));
23+
});
5624
});
5725
}
5826

27+
// picklog().then((commitStr) => {
28+
// fs.writeFileSync('bear.md', commitStr);
29+
// });
5930
module.exports = picklog;

lib/getCommits.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

lib/getLatestCommits.js

Lines changed: 0 additions & 78 deletions
This file was deleted.

lib/splitCommitByTag.js

Lines changed: 0 additions & 77 deletions
This file was deleted.

0 commit comments

Comments
 (0)