@4s1/conventional-commit-creator 3.0.0-dev.1 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +144 -7
- package/dist/config.js +35 -7
- package/dist/index.js +0 -12
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,21 +1,158 @@
|
|
|
1
1
|
# Conventional Commit Creator
|
|
2
2
|
|
|
3
|
-
This CLI application assists in creating commit messages that are conform to the conventional commit style.
|
|
4
|
-
It will ask for
|
|
3
|
+
This CLI application assists you in creating commit messages that are conform to the conventional commit style.
|
|
4
|
+
It will ask for _type_, _scope_, _description_, _body_ and _issue id_.
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
Features:
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
⭐ format of the commit message can be fully customized \
|
|
9
|
+
⭐ different templates for your repositories based on Git remote url \
|
|
10
|
+
⭐ issue id can be inserted in up to three places of a commit message
|
|
11
|
+
|
|
12
|
+
## Install & usage
|
|
13
|
+
|
|
14
|
+
Install this package globally.
|
|
9
15
|
|
|
10
16
|
```bash
|
|
11
|
-
# Install globally
|
|
12
17
|
npm install -g @4s1/conventional-commit-creator
|
|
13
18
|
```
|
|
14
19
|
|
|
15
|
-
|
|
20
|
+
Inside your repository run Conventional Commit Creator.
|
|
16
21
|
|
|
17
22
|
```bash
|
|
18
23
|
conventional-commit-creator
|
|
19
|
-
# or
|
|
24
|
+
# or just
|
|
20
25
|
ccc
|
|
21
26
|
```
|
|
27
|
+
|
|
28
|
+
## Configure commit message templates
|
|
29
|
+
|
|
30
|
+
The configuration is stored in `~/.config/conventional-commit-creator/config.json`.
|
|
31
|
+
|
|
32
|
+
The default template look like the following json:
|
|
33
|
+
|
|
34
|
+
```json
|
|
35
|
+
{
|
|
36
|
+
"version": 1,
|
|
37
|
+
"templates": [
|
|
38
|
+
{
|
|
39
|
+
"name": "Default",
|
|
40
|
+
"regex": ".*",
|
|
41
|
+
"pattern": "{type}{scope}: {description}{issue}{body}",
|
|
42
|
+
|
|
43
|
+
"pre_type": "",
|
|
44
|
+
"post_type": "",
|
|
45
|
+
"pre_scope": "(",
|
|
46
|
+
"post_scope": ")",
|
|
47
|
+
"pre_description": "",
|
|
48
|
+
"post_description": "",
|
|
49
|
+
"pre_body": "\n\n",
|
|
50
|
+
"post_body": "",
|
|
51
|
+
|
|
52
|
+
"pre_issue": " (#",
|
|
53
|
+
"post_issue": ")",
|
|
54
|
+
"pre_issue2": "",
|
|
55
|
+
"post_issue2": "",
|
|
56
|
+
"pre_issue3": "",
|
|
57
|
+
"post_issue3": ""
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
and will create the following commit message:
|
|
64
|
+
|
|
65
|
+
```text
|
|
66
|
+
--- your input --------------------------
|
|
67
|
+
|
|
68
|
+
type: chore
|
|
69
|
+
scope: foo
|
|
70
|
+
description: some description
|
|
71
|
+
body: Lorem ipsum dolor sit amet.
|
|
72
|
+
issue: 42
|
|
73
|
+
|
|
74
|
+
--- commit message result ---------------
|
|
75
|
+
|
|
76
|
+
chore(foo): some description (#42)
|
|
77
|
+
|
|
78
|
+
Lorem ipsum dolor sit amet.
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
The `pre` and `post` texts are only inserted if a matching middle part has also been entered.
|
|
82
|
+
|
|
83
|
+
Now let's look at another more complex variant.
|
|
84
|
+
|
|
85
|
+
We take the configuration from above, remove all empty strings (missing settings are replaced by empty strings) and add another template that should apply to all GitHub projects (see _regex_).
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
{
|
|
89
|
+
"version": 1,
|
|
90
|
+
"templates": [
|
|
91
|
+
{
|
|
92
|
+
"name": "Default",
|
|
93
|
+
"regex": ".*",
|
|
94
|
+
"pattern": "{type}{scope}: {description}{issue}{body}",
|
|
95
|
+
"pre_scope": "(",
|
|
96
|
+
"post_scope": ")",
|
|
97
|
+
"pre_body": "\n\n",
|
|
98
|
+
"pre_issue": " (#",
|
|
99
|
+
"post_issue": ")"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"name": "GitHub Project",
|
|
103
|
+
"regex": "^.*github.*$",
|
|
104
|
+
"pattern": "{type}{scope}: {description}{body}{issue}{issue2}{issue3}",
|
|
105
|
+
"pre_scope": "(",
|
|
106
|
+
"post_scope": ")",
|
|
107
|
+
"pre_body": "\n\n",
|
|
108
|
+
"pre_issue": "\n\nRefs: #",
|
|
109
|
+
"pre_issue2": " | [refs #",
|
|
110
|
+
"post_issue2": "]",
|
|
111
|
+
"pre_issue3": " | REDMINE-",
|
|
112
|
+
"post_issue3": ""
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
This will result in the following commit example:
|
|
119
|
+
|
|
120
|
+
```text
|
|
121
|
+
--- your input --------------------------
|
|
122
|
+
|
|
123
|
+
type: refactor
|
|
124
|
+
scope: -
|
|
125
|
+
description: foobar
|
|
126
|
+
body: Hallo \n world
|
|
127
|
+
issue: 42
|
|
128
|
+
|
|
129
|
+
--- commit message result ---------------
|
|
130
|
+
|
|
131
|
+
refactor: foobar
|
|
132
|
+
|
|
133
|
+
Hallo
|
|
134
|
+
world
|
|
135
|
+
|
|
136
|
+
Refs: #42 | [refs #42] | REDMINE-42
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
or without _issue id_
|
|
140
|
+
|
|
141
|
+
```text
|
|
142
|
+
--- your input --------------------------
|
|
143
|
+
|
|
144
|
+
type: refactor
|
|
145
|
+
scope: -
|
|
146
|
+
description: foobar
|
|
147
|
+
body: Hallo \n world
|
|
148
|
+
issue: -
|
|
149
|
+
|
|
150
|
+
--- commit message result ---------------
|
|
151
|
+
|
|
152
|
+
refactor: foobar
|
|
153
|
+
|
|
154
|
+
Hallo
|
|
155
|
+
world
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Checking the Git remote url via regular expression is done in the order the templates were specified from top to bottom. The last hit wins.
|
package/dist/config.js
CHANGED
|
@@ -1,12 +1,40 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import os from 'node:os';
|
|
3
|
-
import
|
|
3
|
+
import path from 'node:path';
|
|
4
4
|
export function loadConfig() {
|
|
5
|
-
const
|
|
6
|
-
if (
|
|
7
|
-
|
|
5
|
+
const configFile = `${os.homedir()}/.config/conventional-commit-creator/config.json`;
|
|
6
|
+
if (fs.existsSync(configFile)) {
|
|
7
|
+
const config = fs.readFileSync(configFile, { encoding: 'utf-8' });
|
|
8
|
+
return JSON.parse(config);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
const config = {
|
|
12
|
+
$schema: 'https://www.4s1.de/conventional-commit-creator/schema.json',
|
|
13
|
+
version: 1,
|
|
14
|
+
templates: [
|
|
15
|
+
{
|
|
16
|
+
name: 'Default',
|
|
17
|
+
regex: '.*',
|
|
18
|
+
pattern: '{type}{scope}: {description}{issue}{body}',
|
|
19
|
+
pre_type: '',
|
|
20
|
+
post_type: '',
|
|
21
|
+
pre_scope: '(',
|
|
22
|
+
post_scope: ')',
|
|
23
|
+
pre_description: '',
|
|
24
|
+
post_description: '',
|
|
25
|
+
pre_body: '\n\n',
|
|
26
|
+
post_body: '',
|
|
27
|
+
pre_issue: ' (#',
|
|
28
|
+
post_issue: ')',
|
|
29
|
+
pre_issue2: '',
|
|
30
|
+
post_issue2: '',
|
|
31
|
+
pre_issue3: '',
|
|
32
|
+
post_issue3: '',
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
fs.mkdirSync(path.dirname(configFile), { recursive: true });
|
|
37
|
+
fs.writeFileSync(configFile, JSON.stringify(config, null, 2), { encoding: 'utf-8' });
|
|
38
|
+
return config;
|
|
8
39
|
}
|
|
9
|
-
const content = fs.readFileSync(path, { encoding: 'utf-8' });
|
|
10
|
-
// ToDo: Exception handling
|
|
11
|
-
return JSON.parse(content);
|
|
12
40
|
}
|
package/dist/index.js
CHANGED
|
@@ -129,42 +129,30 @@ async function createMsg(data, template) {
|
|
|
129
129
|
if (type) {
|
|
130
130
|
const typeText = `${template.pre_type ?? ''}${type}${template.post_type ?? ''}`;
|
|
131
131
|
msg = msg.replace('{type}', typeText);
|
|
132
|
-
const type2Text = `${template.pre_type2 ?? ''}${type}${template.post_type2 ?? ''}`;
|
|
133
|
-
msg = msg.replace('{type2}', type2Text);
|
|
134
132
|
}
|
|
135
133
|
else {
|
|
136
134
|
msg = msg.replace('{type}', '');
|
|
137
|
-
msg = msg.replace('{type2}', '');
|
|
138
135
|
}
|
|
139
136
|
if (scope) {
|
|
140
137
|
const scopeText = `${template.pre_scope ?? ''}${scope}${template.post_scope ?? ''}`;
|
|
141
138
|
msg = msg.replace('{scope}', scopeText);
|
|
142
|
-
const scope2Text = `${template.pre_scope2 ?? ''}${scope}${template.post_scope2 ?? ''}`;
|
|
143
|
-
msg = msg.replace('{scope2}', scope2Text);
|
|
144
139
|
}
|
|
145
140
|
else {
|
|
146
141
|
msg = msg.replace('{scope}', '');
|
|
147
|
-
msg = msg.replace('{scope2}', '');
|
|
148
142
|
}
|
|
149
143
|
if (description) {
|
|
150
144
|
const descriptionText = `${template.pre_description ?? ''}${description}${template.post_description ?? ''}`;
|
|
151
145
|
msg = msg.replace('{description}', descriptionText);
|
|
152
|
-
const description2Text = `${template.pre_description2 ?? ''}${description}${template.post_description2 ?? ''}`;
|
|
153
|
-
msg = msg.replace('{description2}', description2Text);
|
|
154
146
|
}
|
|
155
147
|
else {
|
|
156
148
|
msg = msg.replace('{description}', '');
|
|
157
|
-
msg = msg.replace('{description2}', '');
|
|
158
149
|
}
|
|
159
150
|
if (body) {
|
|
160
151
|
const bodyText = `${template.pre_body ?? ''}${body}${template.post_body ?? ''}`;
|
|
161
152
|
msg = msg.replace('{body}', bodyText);
|
|
162
|
-
const body2Text = `${template.pre_body2 ?? ''}${body}${template.post_body2 ?? ''}`;
|
|
163
|
-
msg = msg.replace('{body2}', body2Text);
|
|
164
153
|
}
|
|
165
154
|
else {
|
|
166
155
|
msg = msg.replace('{body}', '');
|
|
167
|
-
msg = msg.replace('{body2}', '');
|
|
168
156
|
}
|
|
169
157
|
if (issue) {
|
|
170
158
|
const issueText = `${template.pre_issue ?? ''}${issue}${template.post_issue ?? ''}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@4s1/conventional-commit-creator",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Conventional Commit Creator",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"conventional commit",
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@4s1/eslint-config": "6.5.0",
|
|
47
|
-
"@4s1/ts-config": "4.3.
|
|
48
|
-
"@types/node": "18.
|
|
47
|
+
"@4s1/ts-config": "4.3.2",
|
|
48
|
+
"@types/node": "18.16.2",
|
|
49
49
|
"@types/prompts": "2.4.4",
|
|
50
|
-
"eslint": "8.
|
|
51
|
-
"prettier": "2.8.
|
|
50
|
+
"eslint": "8.39.0",
|
|
51
|
+
"prettier": "2.8.8",
|
|
52
52
|
"ts-node": "10.9.1",
|
|
53
53
|
"typescript": "5.0.4"
|
|
54
54
|
},
|