Skip to content

Commit

Permalink
feat:新增按提交者姓名生成changeLogg
Browse files Browse the repository at this point in the history
  • Loading branch information
472756921 committed Apr 6, 2021
1 parent 19839ab commit ee28855
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-BRTS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## **无版本**
### **2021-04-01**
### feat
+ feat:完善readme.md ([c5f6e91](https://github.com/472756921/Brts-changeLog/commit/c5f6e91f4487ea9a305571385167eed394447cf4)) - BensonChen
+ feat:v1.0版本 ([271fda7](https://github.com/472756921/Brts-changeLog/commit/271fda76d332596a78862698b2cc54af4678dcce)) - BensonChen

### **2021-03-31**
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ CHANGELOG-BRTS.md 中将展示 ['fix','feat','style'] 三类信息
}
```
完成上述配置后,使用 shell 工具执行 brts-changelog init 可生成 CHANGELOG-BRTS.md
命令参数加入 --username= 可指定生成某人的提交记录 Log

---

Expand Down
20 changes: 19 additions & 1 deletion bin/brts-changelog-init
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ const segmentationInItem = ",";
const segmentationInList = "----------";
const gitArg = [`--pretty=format:{"hash":"%H"${segmentationInItem}"gitTags":"%d"${segmentationInItem}"committerDate":"%ai"${segmentationInItem}"title":"%s"${segmentationInItem}"message":"%b"${segmentationInItem}"author":"%an"}${segmentationInList}`];

const userPrams = process.argv.slice(2);
let userConfig = {};
if (userPrams.length > 0) {
userPrams.map((it) => {
if (it.indexOf("=") !== -1 && it.indexOf("--") !== -1) {
let temp = it.split("=");
let to = {};
const key = temp[0].slice(2);
to[key] = temp[1].toLowerCase();
userConfig = { ...userConfig, ...to };
}
});
}

// 获取当前版本号(如果为空则创建版本号)
const p1 = new Promise((res, rej) => {
const newVersion = getVersion();
Expand Down Expand Up @@ -49,6 +63,10 @@ Promise.all([p1, p2]).then((res) => {
_ = _.replace(/[\r\n\']/g, "");
const temp = JSON.parse(_);
const gitInfo = { ...temp, type: getCommitType(temp.title) };

if (userConfig.username && userConfig.username !== gitInfo.author.toLowerCase()) {
return false;
}
const gitInfoDate = gitInfo.committerDate.split(" ")[0];
if (gitInfo.gitTags) {
tagIndex += 1;
Expand All @@ -67,7 +85,7 @@ Promise.all([p1, p2]).then((res) => {
});
createIfMissing(args);
const fileContent = writeFileFormat(args.infile, newGits, res[1], getissuesUrl());
writeFile(args.infile, fileContent);
writeFile(args.infile, fileContent, userConfig.username);
}
);
});
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "brt-changelog",
"version": "1.0.3",
"version": "1.0.4",
"description": "changelog 生成器",
"main": "index.js",
"bin": {
Expand Down
11 changes: 8 additions & 3 deletions src/file-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ function createIfMissing(args) {
}
}

function writeFile(filePath, content) {
console.log(chalk.green(`created file ${filePath} in ${path.resolve(".")}`));
fs.writeFileSync(filePath, content, "utf8");
function writeFile(filePath, content, expName) {
if (expName) {
console.log(chalk.green(`created file CHANGELOG-BRTS(${expName}).md in ${path.resolve(".")}`));
fs.writeFileSync(`CHANGELOG-BRTS(${expName}).md`, content, "utf8");
} else {
console.log(chalk.green(`created file ${filePath} in ${path.resolve(".")}`));
fs.writeFileSync(filePath, content, "utf8");
}
}

function writeFileFormat(filePath, content, repository, issuesUrl) {
Expand Down

0 comments on commit ee28855

Please sign in to comment.