@4s1/conventional-commit-creator 2.0.0 → 3.0.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/LICENSE +1 -1
- package/README.md +0 -4
- package/dist/app-error.js +7 -0
- package/dist/config.js +12 -0
- package/dist/git.js +6 -11
- package/dist/index.js +114 -31
- package/package.json +14 -15
- package/dist/git.d.ts +0 -8
- package/dist/git.d.ts.map +0 -1
- package/dist/git.js.map +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
[](https://sonarcloud.io/project/issues?id=4s1_conventional-commit-creator&resolved=false&types=BUG)
|
|
2
|
-
[](https://sonarcloud.io/project/issues?id=4s1_conventional-commit-creator&resolved=false&types=VULNERABILITY)
|
|
3
|
-
[](https://sonarcloud.io/project/issues?id=4s1_conventional-commit-creator&resolved=false&types=CODE_SMELL)
|
|
4
|
-
|
|
5
1
|
# Conventional Commit Creator
|
|
6
2
|
|
|
7
3
|
This CLI application assists in creating commit messages that are conform to the conventional commit style.
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import { AppError } from './app-error.js';
|
|
4
|
+
export function loadConfig() {
|
|
5
|
+
const path = `${os.homedir()}/.ccc.json`;
|
|
6
|
+
if (!fs.existsSync(path)) {
|
|
7
|
+
throw new AppError(`No configuration found at "${path}".`);
|
|
8
|
+
}
|
|
9
|
+
const content = fs.readFileSync(path, { encoding: 'utf-8' });
|
|
10
|
+
// ToDo: Exception handling
|
|
11
|
+
return JSON.parse(content);
|
|
12
|
+
}
|
package/dist/git.js
CHANGED
|
@@ -21,26 +21,22 @@ export class Git {
|
|
|
21
21
|
return false;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
async
|
|
25
|
-
|
|
26
|
-
const output = await this.execute('git remote -v');
|
|
27
|
-
return output.includes('intra.bender:');
|
|
28
|
-
}
|
|
29
|
-
catch (err) {
|
|
30
|
-
console.error(err);
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
24
|
+
async getGitRemoteOriginUrl() {
|
|
25
|
+
return this.execute('git remote get-url --push origin');
|
|
33
26
|
}
|
|
34
27
|
async commit(msg) {
|
|
35
28
|
console.info('committing ...');
|
|
36
29
|
try {
|
|
37
|
-
await this.execute(`git commit -m "${msg}"`);
|
|
30
|
+
await this.execute(`git commit -m "${this.encodeMessage(msg)}"`);
|
|
38
31
|
}
|
|
39
32
|
catch (err) {
|
|
40
33
|
console.error(err);
|
|
41
34
|
process.exit(1);
|
|
42
35
|
}
|
|
43
36
|
}
|
|
37
|
+
encodeMessage(msg) {
|
|
38
|
+
return msg.replaceAll('"', '\\"');
|
|
39
|
+
}
|
|
44
40
|
execute(cmd) {
|
|
45
41
|
return new Promise((resolve, reject) => {
|
|
46
42
|
exec(cmd, (err, stdout) => {
|
|
@@ -53,4 +49,3 @@ export class Git {
|
|
|
53
49
|
});
|
|
54
50
|
}
|
|
55
51
|
}
|
|
56
|
-
//# sourceMappingURL=git.js.map
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import prompts from 'prompts';
|
|
3
3
|
import { Git } from './git.js';
|
|
4
|
+
import { loadConfig } from './config.js';
|
|
5
|
+
import { AppError } from './app-error.js';
|
|
4
6
|
// https://kapeli.com/cheat_sheets/Conventional_Commits.docset/Contents/Resources/Documents/index
|
|
5
7
|
const questions = [
|
|
6
8
|
{
|
|
@@ -50,6 +52,11 @@ const questions = [
|
|
|
50
52
|
}
|
|
51
53
|
},
|
|
52
54
|
},
|
|
55
|
+
{
|
|
56
|
+
type: 'text',
|
|
57
|
+
name: 'body',
|
|
58
|
+
message: 'body?',
|
|
59
|
+
},
|
|
53
60
|
{
|
|
54
61
|
type: 'number',
|
|
55
62
|
name: 'issue',
|
|
@@ -57,42 +64,118 @@ const questions = [
|
|
|
57
64
|
},
|
|
58
65
|
];
|
|
59
66
|
async function main() {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
msg += `(${data.scope.trim()})`;
|
|
67
|
+
try {
|
|
68
|
+
const git = new Git();
|
|
69
|
+
if (!(await git.isCurrentDirUnderGitControl())) {
|
|
70
|
+
throw new AppError('Current directory is not a git repository.');
|
|
71
|
+
}
|
|
72
|
+
if (!(await git.haveStagedChanges())) {
|
|
73
|
+
throw new AppError('Nothing to commit');
|
|
74
|
+
}
|
|
75
|
+
const config = loadConfig();
|
|
76
|
+
const remoteOriginUrl = (await git.getGitRemoteOriginUrl()).trim();
|
|
77
|
+
const template = getMatchingTemplate(config, remoteOriginUrl);
|
|
78
|
+
console.info(`Using template "${template.name}"\n`);
|
|
79
|
+
const data = (await prompts(questions, {
|
|
80
|
+
onCancel: () => {
|
|
81
|
+
// ToDo: Better exception handling
|
|
82
|
+
console.error('Aborted');
|
|
83
|
+
process.exit(1);
|
|
84
|
+
},
|
|
85
|
+
}));
|
|
86
|
+
const msg = await createMsg(data, template);
|
|
87
|
+
console.info(`${'-'.repeat(42)}\n${msg}\n${'-'.repeat(42)}`);
|
|
88
|
+
await git.commit(msg);
|
|
89
|
+
console.info('done');
|
|
84
90
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
msg += ` (#${data.issue})`;
|
|
91
|
+
catch (err) {
|
|
92
|
+
if (err instanceof AppError) {
|
|
93
|
+
console.error(err.message);
|
|
94
|
+
process.exit(0);
|
|
90
95
|
}
|
|
91
96
|
else {
|
|
92
|
-
|
|
97
|
+
console.error(err);
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function getMatchingTemplate(config, remoteOriginUrl) {
|
|
103
|
+
// ToDo: rename var
|
|
104
|
+
let template2;
|
|
105
|
+
for (const template of config.templates) {
|
|
106
|
+
const regEx = new RegExp(template.regex);
|
|
107
|
+
if (regEx.test(remoteOriginUrl)) {
|
|
108
|
+
template2 = template;
|
|
93
109
|
}
|
|
94
110
|
}
|
|
111
|
+
if (!template2) {
|
|
112
|
+
throw new AppError(`No matching template found for "${remoteOriginUrl}"`);
|
|
113
|
+
}
|
|
114
|
+
return template2;
|
|
115
|
+
}
|
|
116
|
+
async function createMsg(data, template) {
|
|
117
|
+
const type = data.type ? data.type.trim() : '';
|
|
118
|
+
const scope = data.scope ? data.scope.trim() : '';
|
|
119
|
+
const body = data.body
|
|
120
|
+
? data.body
|
|
121
|
+
.split('\\n')
|
|
122
|
+
.map((x) => x.trim())
|
|
123
|
+
.join('\n')
|
|
124
|
+
.trim()
|
|
125
|
+
: '';
|
|
126
|
+
const description = data.description ? data.description.trim() : '';
|
|
127
|
+
const issue = data.issue ? data.issue.toString() : '';
|
|
128
|
+
let msg = template.pattern;
|
|
129
|
+
if (type) {
|
|
130
|
+
const typeText = `${template.pre_type ?? ''}${type}${template.post_type ?? ''}`;
|
|
131
|
+
msg = msg.replace('{type}', typeText);
|
|
132
|
+
const type2Text = `${template.pre_type2 ?? ''}${type}${template.post_type2 ?? ''}`;
|
|
133
|
+
msg = msg.replace('{type2}', type2Text);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
msg = msg.replace('{type}', '');
|
|
137
|
+
msg = msg.replace('{type2}', '');
|
|
138
|
+
}
|
|
139
|
+
if (scope) {
|
|
140
|
+
const scopeText = `${template.pre_scope ?? ''}${scope}${template.post_scope ?? ''}`;
|
|
141
|
+
msg = msg.replace('{scope}', scopeText);
|
|
142
|
+
const scope2Text = `${template.pre_scope2 ?? ''}${scope}${template.post_scope2 ?? ''}`;
|
|
143
|
+
msg = msg.replace('{scope2}', scope2Text);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
msg = msg.replace('{scope}', '');
|
|
147
|
+
msg = msg.replace('{scope2}', '');
|
|
148
|
+
}
|
|
149
|
+
if (description) {
|
|
150
|
+
const descriptionText = `${template.pre_description ?? ''}${description}${template.post_description ?? ''}`;
|
|
151
|
+
msg = msg.replace('{description}', descriptionText);
|
|
152
|
+
const description2Text = `${template.pre_description2 ?? ''}${description}${template.post_description2 ?? ''}`;
|
|
153
|
+
msg = msg.replace('{description2}', description2Text);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
msg = msg.replace('{description}', '');
|
|
157
|
+
msg = msg.replace('{description2}', '');
|
|
158
|
+
}
|
|
159
|
+
if (body) {
|
|
160
|
+
const bodyText = `${template.pre_body ?? ''}${body}${template.post_body ?? ''}`;
|
|
161
|
+
msg = msg.replace('{body}', bodyText);
|
|
162
|
+
const body2Text = `${template.pre_body2 ?? ''}${body}${template.post_body2 ?? ''}`;
|
|
163
|
+
msg = msg.replace('{body2}', body2Text);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
msg = msg.replace('{body}', '');
|
|
167
|
+
msg = msg.replace('{body2}', '');
|
|
168
|
+
}
|
|
169
|
+
if (issue) {
|
|
170
|
+
const issueText = `${template.pre_issue ?? ''}${issue}${template.post_issue ?? ''}`;
|
|
171
|
+
msg = msg.replace('{issue}', issueText);
|
|
172
|
+
const issue2Text = `${template.pre_issue2 ?? ''}${issue}${template.post_issue2 ?? ''}`;
|
|
173
|
+
msg = msg.replace('{issue2}', issue2Text);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
msg = msg.replace('{issue}', '');
|
|
177
|
+
msg = msg.replace('{issue2}', '');
|
|
178
|
+
}
|
|
95
179
|
return msg;
|
|
96
180
|
}
|
|
97
181
|
main().catch(console.error);
|
|
98
|
-
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@4s1/conventional-commit-creator",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-dev.0",
|
|
4
4
|
"description": "Conventional Commit Creator",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"conventional commit",
|
|
@@ -28,33 +28,32 @@
|
|
|
28
28
|
],
|
|
29
29
|
"scripts": {
|
|
30
30
|
"build": "rm -rf dist && tsc",
|
|
31
|
-
"build:dev": "pnpm run build --
|
|
32
|
-
"format": "prettier --write .",
|
|
31
|
+
"build:dev": "pnpm run build --project tsconfig.dev.json",
|
|
33
32
|
"lbt": "npm run lint && npm run build && npm run test",
|
|
34
33
|
"lint": "eslint --ext .ts src/ && prettier --check .",
|
|
34
|
+
"lint:fix": "eslint --ext .ts --fix src/ && prettier --write .",
|
|
35
35
|
"start": "node dist/index.js",
|
|
36
36
|
"start:dev": "ts-node src/index.ts",
|
|
37
37
|
"test": "echo no tests",
|
|
38
|
-
"test:cov": "pnpm run test --
|
|
39
|
-
"test:watch": "pnpm run test --
|
|
38
|
+
"test:cov": "pnpm run test --coverage",
|
|
39
|
+
"test:watch": "pnpm run test --watch"
|
|
40
40
|
},
|
|
41
41
|
"prettier": "@4s1/eslint-config",
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"prompts": "
|
|
43
|
+
"prompts": "2.4.2"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@4s1/eslint-config": "
|
|
47
|
-
"@4s1/ts-config": "3.0
|
|
48
|
-
"@types/node": "18.11
|
|
49
|
-
"@types/prompts": "2.4.
|
|
50
|
-
"eslint": "8.
|
|
51
|
-
"prettier": "2.8.
|
|
46
|
+
"@4s1/eslint-config": "6.5.0",
|
|
47
|
+
"@4s1/ts-config": "4.3.0",
|
|
48
|
+
"@types/node": "18.15.11",
|
|
49
|
+
"@types/prompts": "2.4.4",
|
|
50
|
+
"eslint": "8.38.0",
|
|
51
|
+
"prettier": "2.8.7",
|
|
52
52
|
"ts-node": "10.9.1",
|
|
53
|
-
"typescript": "
|
|
53
|
+
"typescript": "5.0.4"
|
|
54
54
|
},
|
|
55
55
|
"engines": {
|
|
56
|
-
"node": "18"
|
|
57
|
-
"pnpm": "7"
|
|
56
|
+
"node": "18"
|
|
58
57
|
},
|
|
59
58
|
"publishConfig": {
|
|
60
59
|
"access": "public"
|
package/dist/git.d.ts
DELETED
package/dist/git.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AAEA,qBAAa,GAAG;IACD,2BAA2B,IAAI,OAAO,CAAC,OAAO,CAAC;IAU/C,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC;IAWrC,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;IAU5B,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAU/C,OAAO,CAAC,OAAO;CAWhB"}
|
package/dist/git.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"git.js","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAiB,MAAM,oBAAoB,CAAC;AAEzD,MAAM,OAAO,GAAG;IACP,KAAK,CAAC,2BAA2B;QACtC,IAAI;YACF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,qCAAqC,CAAC,CAAC;YACzE,OAAO,MAAM,CAAC,IAAI,EAAE,KAAK,MAAM,CAAC;SACjC;QAAC,OAAO,GAAG,EAAE;YACZ,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACnB,OAAO,KAAK,CAAC;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AC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { exec, ExecException } from 'node:child_process';\n\nexport class Git {\n public async isCurrentDirUnderGitControl(): Promise<boolean> {\n try {\n const result = await this.execute('git rev-parse --is-inside-work-tree');\n return result.trim() === 'true';\n } catch (err) {\n console.error(err);\n return false;\n }\n }\n\n public async haveStagedChanges(): Promise<boolean> {\n try {\n const staged = await this.execute('git diff --cached | head -5');\n return staged !== '';\n } catch (err) {\n console.error(err);\n console.log('return false');\n return false;\n }\n }\n\n public async isAtWork(): Promise<boolean> {\n try {\n const output = await this.execute('git remote -v');\n return output.includes('intra.bender:');\n } catch (err) {\n console.error(err);\n return false;\n }\n }\n\n public async commit(msg: string): Promise<void> {\n console.info('committing ...');\n try {\n await this.execute(`git commit -m \"${msg}\"`);\n } catch (err) {\n console.error(err);\n process.exit(1);\n }\n }\n\n private execute(cmd: string): Promise<string> {\n return new Promise((resolve, reject) => {\n exec(cmd, (err: ExecException | null, stdout: string) => {\n if (err) {\n reject(err);\n return;\n }\n resolve(stdout);\n });\n });\n }\n}\n"]}
|
package/dist/index.d.ts
DELETED
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,OAAyB,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAS/B,iGAAiG;AACjG,MAAM,SAAS,GAAmB;IAChC;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,OAAO;QAChB,OAAO,EAAE;YACP,EAAE,KAAK,EAAE,qBAAqB,EAAE,KAAK,EAAE,KAAK,EAAE;YAC9C,EAAE,KAAK,EAAE,0B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KAAK,EAAE;QACd,GAAG,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC;KACjC;IAED,GAAG,IAAI,KAAK,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC;IAEtC,IAAI,IAAI,CAAC,KAAK,EAAE;QACd,kDAAkD;QAClD,IAAI,CAAC,MAAM,EAAE;YACX,GAAG,IAAI,MAAM,IAAI,CAAC,KAAK,GAAG,CAAC;SAC5B;aAAM;YACL,GAAG,IAAI,WAAW,IAAI,CAAC,KAAK,GAAG,CAAC;SACjC;KACF;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport prompts, { PromptObject } from 'prompts';\nimport { Git } from './git.js';\n\ntype promptType = {\n type: string;\n scope?: string;\n description: string;\n issue?: number;\n};\n\n// https://kapeli.com/cheat_sheets/Conventional_Commits.docset/Contents/Resources/Documents/index\nconst questions: PromptObject[] = [\n {\n type: 'select',\n name: 'type',\n message: 'type?',\n choices: [\n { title: 'fix - A bugfix', value: 'fix' },\n { title: 'feat - A new feature', value: 'feat' },\n { title: 'refactor - A code change that neither fixes a bug nor adds a feature', value: 'refactor' },\n { title: 'perf - A code change that improves performance', value: 'perf' },\n { title: 'docs - Documentation only changes', value: 'docs' },\n { title: 'style - Code style (semicolon, indentation, white-space, formatting, ...)', value: 'style' },\n { title: 'test - add/change/delete tests', value: 'test' },\n { title: \"chore - Other changes that don't modify src or test files\", value: 'chore' },\n { title: 'build - build system (npm, git, VSCode, tsconfig, ...)', value: 'build' },\n { title: 'ci - CI configuration (GitHub, GitLab, RenovateBot, ...)', value: 'ci' },\n { title: 'revert - Reverts a previous commit', value: 'revert' },\n ],\n },\n {\n type: 'text',\n name: 'scope',\n message: 'scope?',\n validate: (value: string): string | boolean => {\n if (value.length > 30) {\n return `Your text is ${value.length - 30} char(s) too long.`;\n } else {\n return true;\n }\n },\n },\n {\n type: 'text',\n name: 'description',\n message: 'description?',\n validate: (value: string): string | boolean => {\n if (value.length > 80) {\n return `Your text is ${value.length - 80} char(s) too long.`;\n } else if (value.length < 3) {\n return `Your text is ${3 - value.length} char(s) too short.`;\n } else {\n return true;\n }\n },\n },\n {\n type: 'number',\n name: 'issue',\n message: 'issue?',\n },\n];\n\nasync function main(): Promise<void> {\n const git = new Git();\n\n if (!(await git.isCurrentDirUnderGitControl())) {\n console.error('Current directory is not a git repository.');\n process.exit(0);\n }\n\n if (!(await git.haveStagedChanges())) {\n console.error('Nothing to commit');\n process.exit(0);\n }\n\n const data = (await prompts(questions, {\n onCancel: () => {\n console.error('Aborted');\n process.exit(1);\n },\n })) as promptType;\n\n const isAtWork = await git.isAtWork();\n const msg = await createMsg(data, isAtWork);\n await git.commit(msg);\n console.info('done');\n}\n\nasync function createMsg(data: promptType, isWork: boolean): Promise<string> {\n let msg = `${data.type.trim()}`;\n\n if (data.scope) {\n msg += `(${data.scope.trim()})`;\n }\n\n msg += `: ${data.description.trim()}`;\n\n if (data.issue) {\n // Hack to support Redmine ticket linking at work.\n if (!isWork) {\n msg += ` (#${data.issue})`;\n } else {\n msg += ` [refs #${data.issue}]`;\n }\n }\n\n return msg;\n}\n\nmain().catch(console.error);\n"]}
|