@4s1/conventional-commit-creator 3.0.0 → 3.2.0-dev.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 +2 -0
- package/dist/config.js +1 -0
- package/dist/index.js +16 -76
- package/dist/questions.js +112 -0
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -33,6 +33,7 @@ The default template look like the following json:
|
|
|
33
33
|
|
|
34
34
|
```json
|
|
35
35
|
{
|
|
36
|
+
"$schema": "https://www.4s1.de/conventional-commit-creator/schema.json",
|
|
36
37
|
"version": 1,
|
|
37
38
|
"templates": [
|
|
38
39
|
{
|
|
@@ -86,6 +87,7 @@ We take the configuration from above, remove all empty strings (missing settings
|
|
|
86
87
|
|
|
87
88
|
```json
|
|
88
89
|
{
|
|
90
|
+
"$schema": "https://www.4s1.de/conventional-commit-creator/schema.json",
|
|
89
91
|
"version": 1,
|
|
90
92
|
"templates": [
|
|
91
93
|
{
|
package/dist/config.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,68 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import prompts from 'prompts';
|
|
3
2
|
import { Git } from './git.js';
|
|
4
3
|
import { loadConfig } from './config.js';
|
|
5
4
|
import { AppError } from './app-error.js';
|
|
6
|
-
|
|
7
|
-
const questions = [
|
|
8
|
-
{
|
|
9
|
-
type: 'select',
|
|
10
|
-
name: 'type',
|
|
11
|
-
message: 'type?',
|
|
12
|
-
choices: [
|
|
13
|
-
{ title: 'fix - A bugfix', value: 'fix' },
|
|
14
|
-
{ title: 'feat - A new feature', value: 'feat' },
|
|
15
|
-
{ title: 'refactor - A code change that neither fixes a bug nor adds a feature', value: 'refactor' },
|
|
16
|
-
{ title: 'perf - A code change that improves performance', value: 'perf' },
|
|
17
|
-
{ title: 'docs - Documentation only changes', value: 'docs' },
|
|
18
|
-
{ title: 'style - Code style (semicolon, indentation, white-space, formatting, ...)', value: 'style' },
|
|
19
|
-
{ title: 'test - add/change/delete tests', value: 'test' },
|
|
20
|
-
{ title: "chore - Other changes that don't modify src or test files", value: 'chore' },
|
|
21
|
-
{ title: 'build - build system (npm, git, VSCode, tsconfig, ...)', value: 'build' },
|
|
22
|
-
{ title: 'ci - CI configuration (GitHub, GitLab, RenovateBot, ...)', value: 'ci' },
|
|
23
|
-
{ title: 'revert - Reverts a previous commit', value: 'revert' },
|
|
24
|
-
],
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
type: 'text',
|
|
28
|
-
name: 'scope',
|
|
29
|
-
message: 'scope?',
|
|
30
|
-
validate: (value) => {
|
|
31
|
-
if (value.length > 30) {
|
|
32
|
-
return `Your text is ${value.length - 30} char(s) too long.`;
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
type: 'text',
|
|
41
|
-
name: 'description',
|
|
42
|
-
message: 'description?',
|
|
43
|
-
validate: (value) => {
|
|
44
|
-
if (value.length > 80) {
|
|
45
|
-
return `Your text is ${value.length - 80} char(s) too long.`;
|
|
46
|
-
}
|
|
47
|
-
else if (value.length < 3) {
|
|
48
|
-
return `Your text is ${3 - value.length} char(s) too short.`;
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
type: 'text',
|
|
57
|
-
name: 'body',
|
|
58
|
-
message: 'body?',
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
type: 'number',
|
|
62
|
-
name: 'issue',
|
|
63
|
-
message: 'issue?',
|
|
64
|
-
},
|
|
65
|
-
];
|
|
5
|
+
import { askForBody, askForDescription, askForIssue, askForScope, askForType } from './questions.js';
|
|
66
6
|
async function main() {
|
|
67
7
|
try {
|
|
68
8
|
const git = new Git();
|
|
@@ -76,14 +16,14 @@ async function main() {
|
|
|
76
16
|
const remoteOriginUrl = (await git.getGitRemoteOriginUrl()).trim();
|
|
77
17
|
const template = getMatchingTemplate(config, remoteOriginUrl);
|
|
78
18
|
console.info(`Using template "${template.name}"\n`);
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
const msg = await createMsg(
|
|
19
|
+
const answers = {
|
|
20
|
+
type: await askForType(),
|
|
21
|
+
scope: await askForScope(),
|
|
22
|
+
description: await askForDescription(),
|
|
23
|
+
body: await askForBody(),
|
|
24
|
+
issue: await askForIssue(),
|
|
25
|
+
};
|
|
26
|
+
const msg = await createMsg(answers, template);
|
|
87
27
|
console.info(`${'-'.repeat(42)}\n${msg}\n${'-'.repeat(42)}`);
|
|
88
28
|
await git.commit(msg);
|
|
89
29
|
console.info('done');
|
|
@@ -113,18 +53,18 @@ function getMatchingTemplate(config, remoteOriginUrl) {
|
|
|
113
53
|
}
|
|
114
54
|
return template2;
|
|
115
55
|
}
|
|
116
|
-
async function createMsg(
|
|
117
|
-
const type =
|
|
118
|
-
const scope =
|
|
119
|
-
const body =
|
|
120
|
-
?
|
|
56
|
+
async function createMsg(answers, template) {
|
|
57
|
+
const type = answers.type ? answers.type.trim() : '';
|
|
58
|
+
const scope = answers.scope ? answers.scope.trim() : '';
|
|
59
|
+
const body = answers.body
|
|
60
|
+
? answers.body
|
|
121
61
|
.split('\\n')
|
|
122
62
|
.map((x) => x.trim())
|
|
123
63
|
.join('\n')
|
|
124
64
|
.trim()
|
|
125
65
|
: '';
|
|
126
|
-
const description =
|
|
127
|
-
const issue =
|
|
66
|
+
const description = answers.description ? answers.description.trim() : '';
|
|
67
|
+
const issue = answers.issue ? answers.issue.trim() : '';
|
|
128
68
|
let msg = template.pattern;
|
|
129
69
|
if (type) {
|
|
130
70
|
const typeText = `${template.pre_type ?? ''}${type}${template.post_type ?? ''}`;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import select from '@inquirer/select';
|
|
2
|
+
import input from '@inquirer/input';
|
|
3
|
+
export function askForType() {
|
|
4
|
+
return select({
|
|
5
|
+
message: 'type?',
|
|
6
|
+
choices: [
|
|
7
|
+
{
|
|
8
|
+
name: 'fix',
|
|
9
|
+
value: 'fix',
|
|
10
|
+
description: 'A bugfix',
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
name: 'feat',
|
|
14
|
+
value: 'feat',
|
|
15
|
+
description: 'A new feature',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: 'refactor',
|
|
19
|
+
value: 'refactor',
|
|
20
|
+
description: 'A code change that neither fixes a bug nor adds a feature',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: 'perf',
|
|
24
|
+
value: 'perf',
|
|
25
|
+
description: 'A code change that improves performance',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: 'docs',
|
|
29
|
+
value: 'docs',
|
|
30
|
+
description: 'Documentation only changes',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: 'style',
|
|
34
|
+
value: 'style',
|
|
35
|
+
description: 'Code style (semicolon, indentation, white-space, formatting, ...)',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: 'test',
|
|
39
|
+
value: 'test',
|
|
40
|
+
description: 'add/change/delete tests',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: 'chore',
|
|
44
|
+
value: 'chore',
|
|
45
|
+
description: "Other changes that don't modify src or test files",
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: 'build',
|
|
49
|
+
value: 'build',
|
|
50
|
+
description: 'build system (npm, git, VSCode, tsconfig, angular.json, ...)',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'ci',
|
|
54
|
+
value: 'ci',
|
|
55
|
+
description: 'CI configuration (GitHub, GitLab, RenovateBot, ...)',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: 'revert',
|
|
59
|
+
value: 'revert',
|
|
60
|
+
description: 'Reverts a previous commit',
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
export function askForScope() {
|
|
66
|
+
return input({
|
|
67
|
+
message: 'scope?',
|
|
68
|
+
validate: (value) => {
|
|
69
|
+
if (value.length > 20) {
|
|
70
|
+
return `Your text is ${value.length - 20} char(s) too long.`;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
export function askForDescription() {
|
|
79
|
+
return input({
|
|
80
|
+
message: 'description?',
|
|
81
|
+
validate: (value) => {
|
|
82
|
+
if (value.length > 70) {
|
|
83
|
+
return `Your text is ${value.length - 70} char(s) too long.`;
|
|
84
|
+
}
|
|
85
|
+
else if (value.length < 3) {
|
|
86
|
+
return `Your text is ${3 - value.length} char(s) too short.`;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
export function askForBody() {
|
|
95
|
+
return input({
|
|
96
|
+
message: 'body?',
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
export function askForIssue() {
|
|
100
|
+
return input({
|
|
101
|
+
message: 'issue?',
|
|
102
|
+
validate: (value) => {
|
|
103
|
+
const regularExpression = /^\d+$/;
|
|
104
|
+
if (value.length > 0 && !regularExpression.test(value)) {
|
|
105
|
+
return 'Your issue is not a number.';
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@4s1/conventional-commit-creator",
|
|
3
|
-
"version": "3.0.0",
|
|
3
|
+
"version": "3.2.0-dev.0",
|
|
4
4
|
"description": "Conventional Commit Creator",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"conventional commit",
|
|
@@ -28,24 +28,25 @@
|
|
|
28
28
|
],
|
|
29
29
|
"scripts": {
|
|
30
30
|
"build": "rm -rf dist && tsc",
|
|
31
|
-
"build:dev": "
|
|
31
|
+
"build:dev": "rm -rf dist && tsc --project tsconfig.dev.json",
|
|
32
32
|
"lbt": "npm run lint && npm run build && npm run test",
|
|
33
33
|
"lint": "eslint --ext .ts src/ && prettier --check .",
|
|
34
34
|
"lint:fix": "eslint --ext .ts --fix src/ && prettier --write .",
|
|
35
35
|
"start": "node dist/index.js",
|
|
36
|
-
"start:dev": "ts-node src/index.ts",
|
|
36
|
+
"start:dev": "ts-node --esm src/index.ts",
|
|
37
37
|
"test": "echo no tests",
|
|
38
38
|
"test:cov": "pnpm run test --coverage",
|
|
39
39
|
"test:watch": "pnpm run test --watch"
|
|
40
40
|
},
|
|
41
41
|
"prettier": "@4s1/eslint-config",
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"
|
|
43
|
+
"@inquirer/input": "1.0.3",
|
|
44
|
+
"@inquirer/select": "1.0.3"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
47
|
"@4s1/eslint-config": "6.5.0",
|
|
47
48
|
"@4s1/ts-config": "4.3.2",
|
|
48
|
-
"@types/node": "18.16.
|
|
49
|
+
"@types/node": "18.16.3",
|
|
49
50
|
"@types/prompts": "2.4.4",
|
|
50
51
|
"eslint": "8.39.0",
|
|
51
52
|
"prettier": "2.8.8",
|