Skip to content

Commit df8d519

Browse files
authored
Merge pull request #14 from Arianee/master
merge from @Arianee
2 parents 1d804e5 + f8e7a57 commit df8d519

File tree

12 files changed

+157
-64
lines changed

12 files changed

+157
-64
lines changed

README.md

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# gitool
55

66
Gitool helps you always have the right format for your commit message.
7-
Following https://www.conventionalcommits.org/en/v1.0.0-beta.2/
7+
Following https://www.conventionalcommits.org/en/v1.0.0/
88

99
## alias
1010
any gitool command can be called with ```gitool``` or ```gt```
@@ -24,22 +24,20 @@ or ```gitool -cl=3```
2424

2525
## pretty print
2626

27-
```gitool --prettyPrint```
28-
```gitool -p``` (groupBy type by default)
27+
```gitool --prettyPrint --pn=ProjectName --v=1.23.2```
28+
```gitool -p --pn=ProjectName --v=1.23.2``` (groupBy type by default)
2929

30-
```gitool -p groupBy='type'```
30+
```gitool -p groupBy='type' --pn=ProjectName --v=1.23.2```
3131

32-
```gitool -pg='type'```
33-
```gitool -pg='scope'```
32+
```gitool -pg='type' --pn=ProjectName --v=1.23.2```
33+
```gitool -pg='scope' --pn=ProjectName --v=1.23.2```
3434

35-
```gitool -pg='scope' --tag=3```
36-
37-
```gitool -pg='type' --tag=3 --filters='feat|fix'```
35+
```gitool -pg='type' --filters='feat|fix' --pn=ProjectName --v=1.23.2```
3836

3937

4038
![alt text](https://raw.githubusercontent.com/stefdelec/gitool/master/readme/commitprettier.png)
4139

42-
```gitool -p --tag``` output commits from last tag
40+
```gitool -p --pn=ProjectName --v=1.23.2``` output commits from last tag
4341

4442
Output a file:
4543

@@ -50,7 +48,7 @@ Output a file:
5048

5149
Add this in your package.json
5250
```
53-
"prepublish": "npm test && npm version minor && node index.js -pao=changelog.md --tag=1 && git push"
51+
"postversion": "gitool -p --pn=ProjectName --v=1.23.2"
5452
```
5553
## message composer
5654

@@ -68,12 +66,12 @@ and
6866
## cane
6967
shortcut for
7068
```
71-
git add . && git commit --amend --no-edit
69+
git add . && git commit -m "release(changelog): Update changelog.md [CI SKIP]"
7270
```
7371

7472
## force
75-
rebase on develop or branch + push force
73+
rebase on master or branch + push force
7674

7775
```gitool -force```
78-
```gitool -force -branch=master```
79-
```gitool -fb=master```
76+
```gitool -force -branch=develop```
77+
```gitool -fb=develop```

changelog.md

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,75 @@
1+
# gitool
12
# Release notes
3+
## v1.24.0 ( 2021-09-1 )
24

3-
**version**: From v1.21.0 to v1.22.0
5+
### **feat (1):**
6+
- feat(changelog): Append commits in change log file
47

5-
## **feat (1):**
8+
## v1.22.0 ( 2021-06-19 )
9+
10+
### **feat (1):**
611
- feat(force): git rebase and push
712

13+
## v1.21.0 ( 2021-02-19 )
14+
15+
### **feat (3):**
16+
- feat(cane): short cut for add commit no edit
17+
- feat(console): improve console log
18+
- feat(readme): improve package.json bump
819

20+
## v1.20.0 ( 2021-02-19 )
921

22+
### **docs (15):**
23+
- docs: changelog
24+
- docs: changelog
25+
- docs: changelog
26+
- docs: changelog
27+
- docs: changelog
28+
- docs: changelog
29+
- docs: changelog
30+
- docs: changelog
31+
- docs: changelog
32+
- docs: changelog
33+
- docs(readme): update readme with link to changelog
34+
- docs: changelog
35+
- docs(prettyPrint): update changelog pretty print
36+
- docs(readme): improve readme and add images
37+
- docs(readme): update readme with gitool alias (gt)
1038

39+
### **feat (22):**
40+
- feat(readme): improve readme
41+
- feat(autofetch): auto fetch tags before creating changelog
42+
- feat(changelog): improve changelog title
43+
- feat(changelog): changelog only on last tag
44+
- feat(prettyPrint): can add all or not
45+
- feat(prettyPrint): add changelog in preversion
46+
- feat(prettyPrint): add filters to type of pretty print
47+
- feat(prettyPrint): pretty print from tag
48+
- feat(prettyPrint): quick changelog
49+
- feat(readme): update readme and package.json
50+
- feat(prettyPrint): can pass --tag and output from last tag
51+
- feat(prettyPrint): can output a file
52+
- feat(prettyPrint): pretty print group by type or scope
53+
- feat(messageComposer): can add all modified file before commiting with -am
54+
- feat(bin): commit is not executed if message and type are undefined
55+
- feat(bin): gt is a new alias for gitool
56+
- feat(commitChecker): version bump commit by npm is accepted
57+
- feat: undefined
58+
- feat(bin): add aliases for existing commands
59+
- feat(messageComposer): add functionaly message composer
60+
- feat(readme): create a simple README.md
61+
- feat(bin): bin is packed
1162

63+
### **fix (8):**
64+
- fix(changelog): fix change log tag title
65+
- fix(prettyPrint): version of pretty print was incorrect
66+
- fix(travis): fix travis test
67+
- fix(readme): fix link to changelog
68+
- fix(messageComposer): ex was undefined for git add .
69+
- fix(messageComposer): remove automatic add .
70+
- fix(commitChecker): fix default value of last
71+
- fix(bin): bin command was not gitool
1272

73+
### **test (1):**
74+
- test(travis): add travis ci
1375

index.js

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ const commitMessageChercher = require('./src/commit-message-checker/commit-messa
33
const shortCut = require('./src/gitShortCut');
44
const messageComposer = require('./src/message-composer/message-composer')
55
const chalk = require('chalk');
6+
const { existsSync } = require('fs');
67

78
const argv = require('yargs')
89
.alias('c', 'checkCommit')
910
.alias('o', 'output')
1011
.alias('p', 'prettyPrint')
12+
.alias('pn','projectName')
13+
.alias('v','versionTag')
1114
.alias('a', 'addAll')
1215
.alias('m', 'messageComposer')
1316
.alias('t', 'test')
@@ -17,7 +20,7 @@ const argv = require('yargs')
1720
.alias('b','branch')
1821
.argv
1922

20-
const { prettyPrint, write } = require('./src/commit-prettier/commit-prettier');
23+
const { prettyPrint } = require('./src/commit-prettier/commit-prettier');
2124
// Check Last commit
2225

2326
if (argv.checkCommit) {
@@ -40,35 +43,55 @@ if (argv.checkCommit) {
4043
console.log(chalk.red('commit message is NOT valid'));
4144
throw new Error()
4245
}
43-
console.log('')
4446
}
4547

4648
}
4749
if(argv.bump){
4850
console.log(argv.bump);
4951
}
5052
if (argv.prettyPrint) {
53+
if(!argv.projectName){
54+
throw new Error('Project name is mandatory');
55+
}
56+
57+
if(!argv.versionTag){
58+
throw new Error('Version tag is mandatory');
59+
}
5160
console.log('Fetching tags from origin');
5261
shortCut.ex("git fetch origin --tags");
5362

5463
const groupBy = argv.groupBy === 'scope' ? 'scope' : 'type';
5564

56-
const tags = shortCut.getTagsOrderedByDate().split('\n').reverse();
57-
58-
const numOftag=parseInt(argv.tag);
65+
const tags = shortCut.getTagsOrderedByDate().split('\n').filter(t => t !== '');
5966

6067
const getFromTag = (tagNumber) => tags[+tagNumber];
6168

62-
const commitFrom = argv.tag ? getFromTag(numOftag) : shortCut.firstCommitAllTime().trim();
63-
64-
let title = `From ${getFromTag(numOftag)} to ${tags[0]}`;
69+
const firstCommit = shortCut.firstCommitAllTime().trim()
6570

6671
const filters = argv.filters ? argv.filters.split('|') : undefined;
67-
prettyPrint(commitFrom, groupBy, argv.output, title, filters);
72+
const path = argv.output || './changelog.md';
73+
74+
const getDateOfTag = (tag) => ((shortCut.getDateTimeOfTag(tag).trim().split(' '))[0]);
75+
const dateNow = (now = new Date()) => {
76+
let month = now.getMonth() + 1;
77+
month = month > 9 ? month : `0${month}`;
78+
return `${now.getFullYear()}-${month}-${now.getDate()}`;
79+
}
80+
81+
if(!existsSync(path)){
82+
for (let i = 0; i < tags.length; i++) {
83+
const date = getDateOfTag(getFromTag(i));
84+
prettyPrint(i !== 0 ? getFromTag(i - 1) : firstCommit, getFromTag(i), groupBy, path, argv.projectName || 'untitled', getFromTag(i), filters, date);
85+
}
86+
}
87+
88+
prettyPrint(tags.length !== 0 ? getFromTag(tags.length - 1) : shortCut.firstCommitAllTime().trim(), 'HEAD', groupBy, path, argv.projectName || 'untitled', argv.versionTag, filters, dateNow());
89+
90+
6891
if (argv.addAll) {
6992
console.log('Adding files to previous commit');
7093
shortCut.ex('git add .')
71-
shortCut.ex('git commit --amend --no-edit')
94+
shortCut.ex('git commit -m "release(changelog): Update changelog.md [CI SKIP]"')
7295
}
7396
}
7497

@@ -85,11 +108,11 @@ if (argv.messageComposer) {
85108
}
86109

87110
if(argv.force){
88-
const branch=argv.branch || 'develop';
89-
shortCut.ex(`git add . && git commit --amend --no-edit && git fetch && git pull origin ${branch} --rebase && git push origin HEAD --force`);
111+
const branch=argv.branch || 'master';
112+
shortCut.ex(`git add . && git commit -m "release(changelog): Update changelog.md [CI SKIP]" && git fetch && git pull origin ${branch} --rebase && git push origin HEAD --force`);
90113
}
91114

92115
if(argv.cane){
93116
shortCut.ex('git add .')
94-
shortCut.ex('git commit --amend --no-edit')
117+
shortCut.ex('git commit -m "release(changelog): Update changelog.md [CI SKIP]"')
95118
}

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
{
2-
"name": "gitool",
3-
"version": "1.22.0",
2+
"name": "@arianee/gitool",
3+
"version": "1.24.0",
44
"description": "",
55
"main": "index.js",
66
"scripts": {
77
"test": "jest",
8-
"prepublish": "npm test && npm version minor && node index.js -pao=changelog.md --tag=1 && git push"
8+
"postversion": "node index.js -po=changelog.md --pn=gitool --v=1.25.0"
99
},
1010
"bin": {
1111
"gitool": "index.js",
1212
"gt": "index.js"
1313
},
1414
"repository": {
1515
"type": "git",
16-
"url": "https://github.com/stefdelec/gitool"
16+
"url": "https://github.com/Arianee/gitool"
1717
},
1818
"access": "public",
19+
"private": false,
1920
"keywords": [],
2021
"author": "",
2122
"license": "ISC",

src/commit-extractor/commit-extractor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const commitExtractor = (commitMessage) => {
2-
const reg = new RegExp(/(feat|fix|docs|style|refactor|test|chore)(\((\w{1,})\)){0,1}: (.{1,})/)
2+
const reg = new RegExp(/(feat|fix|docs|style|refactor|test|chore|release)(\((\w{1,})\)){0,1}: (.{1,})/)
33
const result = commitMessage.match(reg)
44
if (result) {
55
return {

src/commit-message-checker/commit-message-checker.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe('commit message checker', () => {
1010
'chore: zefe',
1111
'2.0.1',
1212
'02.02.001',
13+
'release(changelog): Update changelog.md [CI SKIP]',
1314
]
1415

1516
acceptedCommit.forEach(commitMessage => {

src/commit-prettier/commit-prettier.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const { allCommitSince ,gitAddAll } = require('../gitShortCut');
1+
const { commitBetweenTags } = require('../gitShortCut');
22
const { types } = require('../configuration');
33
const { commitExtractor } = require('../commit-extractor/commit-extractor');
44
const Mustache = require('mustache');
5-
const { readFileSync, writeFileSync } = require("fs");
5+
const { readFileSync, writeFileSync, existsSync } = require("fs");
66

77
const addToAcc = (acc, commitType, value, filters) => {
88
const shouldAdd=!filters || filters.length === 0 || filters.includes(commitType);
@@ -49,8 +49,8 @@ const groupByType = (commitLogs, filters) => {
4949
}, {})
5050

5151
}
52-
const groupCommits = (commitHash, groupBy,filters) => {
53-
const commitsLog = allCommitSince(commitHash);
52+
const groupCommits = (from, to, groupBy,filters) => {
53+
const commitsLog = commitBetweenTags(from, to);
5454

5555
let groupedCommit
5656
if (groupBy === 'type') {
@@ -69,28 +69,39 @@ const write = (view) => {
6969
eval(output);
7070

7171
}
72-
const prettyPrint = (commitHash, groupBy, path, title = 'untitled', filters) => {
73-
const groupedCommit = groupCommits(commitHash, groupBy, filters);
72+
73+
const prettyPrint = (from, to, groupBy, path, projectName, versionTag, filters, date) => {
74+
const groupedCommit = groupCommits(from, to, groupBy, filters);
7475

7576
const data =
7677
{
77-
title,
78+
projectName,
79+
versionTag: versionTag.replace('v', ''),
80+
date,
7881
sections: Object.keys(groupedCommit).map(key => groupedCommit[key])
7982
}
8083

8184
const template = readFileSync(__dirname + '/template.terminal.txt').toString();
85+
const titleTemplate = readFileSync(__dirname + '/template.title.txt').toString();
8286
const fileTemplate = readFileSync(__dirname + '/template.file.txt').toString();
8387

8488

8589
const consoleLogs = Mustache.render(template, data);
86-
87-
const file = Mustache.render(fileTemplate, data);
90+
const title = Mustache.render(titleTemplate, data);
91+
const changelog = Mustache.render(fileTemplate, data);
8892

8993
eval(consoleLogs);
9094

9195
if (path) {
92-
console.log('Writing changelog at: ', path);
93-
writeFileSync(path, file);
96+
if (existsSync(path)) { // file exists
97+
console.log('Writing changelog at: ', path);
98+
const data = readFileSync(path, { encoding:'utf8' });
99+
const newdata = data.replace(title, title + changelog);
100+
writeFileSync(path, newdata);
101+
} else { // file not exists
102+
console.log('Generating and writing changelog at: ', path);
103+
writeFileSync(path, title + changelog);
104+
}
94105
}
95106
}
96107

src/commit-prettier/template.file.txt

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
# Release notes
2-
3-
**version**: {{title}}
1+
## v{{versionTag}} ( {{date}} )
42

53
{{#sections}}
6-
## **{{name}} ({{length}}):**
4+
### **{{name}} ({{length}}):**
75
{{#content}}
86
- {{.}}
97
{{/content}}
108

119
{{/sections}}
12-
13-
14-
15-
16-
17-

src/commit-prettier/template.terminal.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
var chalk = require('chalk');
22

3-
console.log(chalk.bold.blue('version: {{title}}'));
3+
console.log(chalk.bold.blue('### {{projectName}} ###'));
4+
console.log('');
5+
console.log(chalk.bold.blue('version: v{{versionTag}}'));
46
console.log('')
57
{{#sections}}
68
console.log(chalk.green('##########################'))
79
console.log(chalk.bold.green('### {{name}} ({{length}})'))
810
console.log(chalk.green('##########################'))
911
{{#content}}
10-
console.log(chalk.blue('{{.}}'))
12+
console.log(chalk.blue('{{.}}'))
1113
{{/content}}
1214
console.log('')
1315

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# {{projectName}}
2+
# Release notes

0 commit comments

Comments
 (0)