@4s1/conventional-commit-creator 3.7.0 → 3.9.0-rc.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.
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AA8B7B,MAAM,UAAU,UAAU;IACxB,MAAM,UAAU,GAAG,GAAG,EAAE,CAAC,OAAO,EAAE,kDAAkD,CAAC;IAErF,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE;QAC7B,MAAM,MAAM,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;QAClE,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;KAC3B;SAAM;QACL,MAAM,MAAM,GAAe;YACzB,OAAO,EAAE,4DAA4D;YACrE,OAAO,EAAE,CAAC;YACV,SAAS,EAAE;gBACT;oBACE,IAAI,EAAE,SAAS;oBACf,KAAK,EAAE,IAAI;oBACX,OAAO,EAAE,2CAA2C;oBAEpD,QAAQ,EAAE,EAAE;oBACZ,SAAS,EAAE,EAAE;oBACb,SAAS,EAAE,GAAG;oBACd,UAAU,EAAE,GAAG;oBACf,eAAe,EAAE,EAAE;oBACnB,gBAAgB,EAAE,EAAE;oBACpB,QAAQ,EAAE,MAAM;oBAChB,SAAS,EAAE,EAAE;oBAEb,SAAS,EAAE,KAAK;oBAChB,UAAU,EAAE,GAAG;oBACf,UAAU,EAAE,EAAE;oBACd,WAAW,EAAE,EAAE;oBACf,UAAU,EAAE,EAAE;oBACd,WAAW,EAAE,EAAE;iBAChB;aACF;SACF,CAAC;QACF,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC5D,EAAE,CAAC,aAAa,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;QACrF,OAAO,MAAM,CAAC;KACf;AACH,CAAC","sourcesContent":["import fs from \"node:fs\";\nimport os from \"node:os\";\nimport path from \"node:path\";\n\nexport interface ConfigTemplateType {\n name: string;\n regex: string;\n pattern: string;\n\n pre_type?: string;\n post_type?: string;\n pre_scope?: string;\n post_scope?: string;\n pre_description?: string;\n post_description?: string;\n pre_body?: string;\n post_body?: string;\n\n pre_issue?: string;\n post_issue?: string;\n pre_issue2?: string;\n post_issue2?: string;\n pre_issue3?: string;\n post_issue3?: string;\n}\n\nexport interface ConfigType {\n $schema: \"https://www.4s1.de/conventional-commit-creator/schema.json\";\n version: number;\n templates: ConfigTemplateType[];\n}\n\nexport function loadConfig(): ConfigType {\n const configFile = `${os.homedir()}/.config/conventional-commit-creator/config.json`;\n\n if (fs.existsSync(configFile)) {\n const config = fs.readFileSync(configFile, { encoding: \"utf-8\" });\n return JSON.parse(config);\n } else {\n const config: ConfigType = {\n $schema: \"https://www.4s1.de/conventional-commit-creator/schema.json\",\n version: 1,\n templates: [\n {\n name: \"Default\",\n regex: \".*\",\n pattern: \"{type}{scope}: {description}{issue}{body}\",\n\n pre_type: \"\",\n post_type: \"\",\n pre_scope: \"(\",\n post_scope: \")\",\n pre_description: \"\",\n post_description: \"\",\n pre_body: \"\\n\\n\",\n post_body: \"\",\n\n pre_issue: \" (#\",\n post_issue: \")\",\n pre_issue2: \"\",\n post_issue2: \"\",\n pre_issue3: \"\",\n post_issue3: \"\",\n },\n ],\n };\n fs.mkdirSync(path.dirname(configFile), { recursive: true });\n fs.writeFileSync(configFile, JSON.stringify(config, null, 2), { encoding: \"utf-8\" });\n return config;\n }\n}\n"]}
1
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MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;QACrF,OAAO,MAAM,CAAC;IAChB,CAAC;AACH,CAAC","sourcesContent":["import fs from \"node:fs\";\nimport os from \"node:os\";\nimport path from \"node:path\";\n\nexport interface ConfigTemplateType {\n name: string;\n regex: string;\n pattern: string;\n\n pre_type?: string;\n post_type?: string;\n pre_scope?: string;\n post_scope?: string;\n pre_description?: string;\n post_description?: string;\n pre_body?: string;\n post_body?: string;\n\n pre_issue?: string;\n post_issue?: string;\n pre_issue2?: string;\n post_issue2?: string;\n pre_issue3?: string;\n post_issue3?: string;\n}\n\nexport interface ConfigType {\n $schema: \"https://www.4s1.de/conventional-commit-creator/schema.json\";\n version: number;\n templates: ConfigTemplateType[];\n}\n\nexport function loadConfig(): ConfigType {\n const configFile = `${os.homedir()}/.config/conventional-commit-creator/config.json`;\n\n if (fs.existsSync(configFile)) {\n const config = fs.readFileSync(configFile, { encoding: \"utf-8\" });\n return JSON.parse(config);\n } else {\n const config: ConfigType = {\n $schema: \"https://www.4s1.de/conventional-commit-creator/schema.json\",\n version: 1,\n templates: [\n {\n name: \"Default\",\n regex: \".*\",\n pattern: \"{type}{scope}: {description}{issue}{body}\",\n\n pre_type: \"\",\n post_type: \"\",\n pre_scope: \"(\",\n post_scope: \")\",\n pre_description: \"\",\n post_description: \"\",\n pre_body: \"\\n\\n\",\n post_body: \"\",\n\n pre_issue: \" (#\",\n post_issue: \")\",\n pre_issue2: \"\",\n post_issue2: \"\",\n pre_issue3: \"\",\n post_issue3: \"\",\n },\n ],\n };\n fs.mkdirSync(path.dirname(configFile), { recursive: true });\n fs.writeFileSync(configFile, JSON.stringify(config, null, 2), { encoding: \"utf-8\" });\n return config;\n }\n}\n"]}
package/dist/git.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"git.js","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,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I,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,GAAG,EAAE,CAAC,GAAyB,EAAE,MAAc,EAAE,EAAE;gBACtD,IAAI,GAAG,EAAE;oBACP,MAAM,CAAC,GAAG,CAAC,CAAC;oBACZ,OAAO;iBACR;gBACD,OAAO,CAAC,MAAM,CAAC,CAAC;YAClB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type { ExecException } from \"node:child_process\";\nimport { exec } 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 getGitRemoteOriginUrl(): Promise<string> {\n return this.execute(\"git remote get-url --push origin\");\n }\n\n public async commit(msg: string): Promise<void> {\n console.info(\"committing ...\");\n try {\n await this.execute(`git commit -m \"${this.encodeMessage(msg)}\"`);\n } catch (err) {\n console.error(err);\n process.exit(1);\n }\n }\n\n private encodeMessage(msg: string): string {\n return msg.replaceAll('\"', '\\\\\"');\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"]}
1
+ {"version":3,"file":"git.js","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C,MAAM,OAAO,GAAG;IACP,KAAK,CAAC,2BAA2B;QACtC,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,q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CAAC,GAAyB,EAAE,MAAc,EAAE,EAAE;gBACtD,IAAI,GAAG,EAAE,CAAC;oBACR,MAAM,CAAC,GAAG,CAAC,CAAC;oBACZ,OAAO;gBACT,CAAC;gBACD,OAAO,CAAC,MAAM,CAAC,CAAC;YAClB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type { ExecException } from \"node:child_process\";\nimport { exec } 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 getGitRemoteOriginUrl(): Promise<string> {\n return this.execute(\"git remote get-url --push origin\");\n }\n\n public async commit(msg: string): Promise<void> {\n console.info(\"committing ...\");\n try {\n await this.execute(`git commit -m \"${this.encodeMessage(msg)}\"`);\n } catch (err) {\n console.error(err);\n process.exit(1);\n }\n }\n\n private encodeMessage(msg: string): string {\n return msg.replaceAll('\"', '\\\\\"');\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.js CHANGED
@@ -17,11 +17,11 @@ async function main() {
17
17
  const template = getMatchingTemplate(config, remoteOriginUrl);
18
18
  console.info(`Using template "${template.name}"\n`);
19
19
  const answers = {
20
- type: await askForType(),
21
- scope: await askForScope(),
22
- description: await askForDescription(),
23
- body: await askForBody(),
24
- issue: await askForIssue(),
20
+ type: (await askForType()).trim(),
21
+ scope: (await askForScope()).trim(),
22
+ description: (await askForDescription()).trim(),
23
+ body: (await askForBody()).trim(),
24
+ issue: (await askForIssue()).trim(),
25
25
  };
26
26
  const msg = await createMsg(answers, template);
27
27
  console.info(`${"-".repeat(42)}\n${msg}\n${"-".repeat(42)}`);
@@ -33,6 +33,11 @@ async function main() {
33
33
  catch (err) {
34
34
  if (err instanceof AppError) {
35
35
  console.error(err.message);
36
+ process.exit(100);
37
+ }
38
+ else if (err instanceof Error &&
39
+ err.message.startsWith("User force closed the prompt with")) {
40
+ // Abort exception of @inquirer
36
41
  process.exit(0);
37
42
  }
38
43
  else {
@@ -56,8 +61,6 @@ function getMatchingTemplate(config, remoteOriginUrl) {
56
61
  return template2;
57
62
  }
58
63
  async function createMsg(answers, template) {
59
- const type = answers.type ? answers.type.trim() : "";
60
- const scope = answers.scope ? answers.scope.trim() : "";
61
64
  const body = answers.body
62
65
  ? answers.body
63
66
  .split("\\n")
@@ -65,25 +68,23 @@ async function createMsg(answers, template) {
65
68
  .join("\n")
66
69
  .trim()
67
70
  : "";
68
- const description = answers.description ? answers.description.trim() : "";
69
- const issue = answers.issue ? answers.issue.trim() : "";
70
71
  let msg = template.pattern;
71
- if (type) {
72
- const typeText = `${template.pre_type ?? ""}${type}${template.post_type ?? ""}`;
72
+ if (answers.type) {
73
+ const typeText = `${template.pre_type ?? ""}${answers.type}${template.post_type ?? ""}`;
73
74
  msg = msg.replace("{type}", typeText);
74
75
  }
75
76
  else {
76
77
  msg = msg.replace("{type}", "");
77
78
  }
78
- if (scope) {
79
- const scopeText = `${template.pre_scope ?? ""}${scope}${template.post_scope ?? ""}`;
79
+ if (answers.scope) {
80
+ const scopeText = `${template.pre_scope ?? ""}${answers.scope}${template.post_scope ?? ""}`;
80
81
  msg = msg.replace("{scope}", scopeText);
81
82
  }
82
83
  else {
83
84
  msg = msg.replace("{scope}", "");
84
85
  }
85
- if (description) {
86
- const descriptionText = `${template.pre_description ?? ""}${description}${template.post_description ?? ""}`;
86
+ if (answers.description) {
87
+ const descriptionText = `${template.pre_description ?? ""}${answers.description}${template.post_description ?? ""}`;
87
88
  msg = msg.replace("{description}", descriptionText);
88
89
  }
89
90
  else {
@@ -96,12 +97,12 @@ async function createMsg(answers, template) {
96
97
  else {
97
98
  msg = msg.replace("{body}", "");
98
99
  }
99
- if (issue) {
100
- const issueText = `${template.pre_issue ?? ""}${issue}${template.post_issue ?? ""}`;
100
+ if (answers.issue) {
101
+ const issueText = `${template.pre_issue ?? ""}${answers.issue}${template.post_issue ?? ""}`;
101
102
  msg = msg.replace("{issue}", issueText);
102
- const issue2Text = `${template.pre_issue2 ?? ""}${issue}${template.post_issue2 ?? ""}`;
103
+ const issue2Text = `${template.pre_issue2 ?? ""}${answers.issue}${template.post_issue2 ?? ""}`;
103
104
  msg = msg.replace("{issue2}", issue2Text);
104
- const issue3Text = `${template.pre_issue3 ?? ""}${issue}${template.post_issue3 ?? ""}`;
105
+ const issue3Text = `${template.pre_issue3 ?? ""}${answers.issue}${template.post_issue3 ?? ""}`;
105
106
  msg = msg.replace("{issue3}", issue3Text);
106
107
  }
107
108
  else {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAmB,MAAM,aAAa,CAAC;AAE1D,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EACL,UAAU,EACV,kBAAkB,EAClB,iBAAiB,EACjB,WAAW,EACX,WAAW,EACX,UAAU,GACX,MAAM,gBAAgB,CAAC;AAGxB,KAAK,UAAU,IAAI;IACjB,IAAI;QACF,MAAM,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;QAEtB,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,2BAA2B,EAAE,CAAC,EAAE;YAC9C,MAAM,IAAI,QAAQ,CAAC,4CAA4C,CAAC,CAAC;SAClE;QAED,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,iB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,EAAE,QAAQ,CAAC,CAAC;KACvC;SAAM;QACL,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;KACjC;IAED,IAAI,KAAK,EAAE;QACT,MAAM,SAAS,GAAG,GAAG,QAAQ,CAAC,SAAS,IAAI,EAAE,GAAG,KAAK,GAAG,QAAQ,CAAC,UAAU,IAAI,EAAE,EAAE,CAAC;QACpF,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QACxC,MAAM,UAAU,GAAG,GAAG,QAAQ,CAAC,UAAU,IAAI,EAAE,GAAG,KAAK,GAAG,QAAQ,CAAC,WAAW,IAAI,EAAE,EAAE,CAAC;QACvF,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;QAC1C,MAAM,UAAU,GAAG,GAAG,QAAQ,CAAC,UAAU,IAAI,EAAE,GAAG,KAAK,GAAG,QAAQ,CAAC,WAAW,IAAI,EAAE,EAAE,CAAC;QACvF,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;KAC3C;SAAM;QACL,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;QACjC,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QAClC,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;KACnC;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport { Git } from \"./git.js\";\nimport { loadConfig, type ConfigType } from \"./config.js\";\nimport type { ConfigTemplateType } from \"./config.js\";\nimport { AppError } from \"./app-error.js\";\nimport {\n askForBody,\n askForConfirmation,\n askForDescription,\n askForIssue,\n askForScope,\n askForType,\n} from \"./questions.js\";\nimport type { AnswersType } from \"./questions.js\";\n\nasync function main(): Promise<void> {\n try {\n const git = new Git();\n\n if (!(await git.isCurrentDirUnderGitControl())) {\n throw new AppError(\"Current directory is not a git repository.\");\n }\n\n if (!(await git.haveStagedChanges())) {\n throw new AppError(\"Nothing to commit\");\n }\n\n const config = loadConfig();\n const remoteOriginUrl = (await git.getGitRemoteOriginUrl()).trim();\n const template = getMatchingTemplate(config, remoteOriginUrl);\n console.info(`Using template \"${template.name}\"\\n`);\n\n const answers: AnswersType = {\n type: await askForType(),\n scope: await askForScope(),\n description: await askForDescription(),\n body: await askForBody(),\n issue: await askForIssue(),\n };\n\n const msg = await createMsg(answers, template);\n console.info(`${\"-\".repeat(42)}\\n${msg}\\n${\"-\".repeat(42)}`);\n if (await askForConfirmation()) {\n await git.commit(msg);\n console.info(\"done\");\n }\n } catch (err) {\n if (err instanceof AppError) {\n console.error(err.message);\n process.exit(0);\n } else {\n console.error(err);\n process.exit(1);\n }\n }\n}\n\nfunction getMatchingTemplate(config: ConfigType, remoteOriginUrl: string): ConfigTemplateType {\n // ToDo: rename var\n let template2: ConfigTemplateType | undefined;\n\n for (const template of config.templates) {\n const regEx = new RegExp(template.regex);\n if (regEx.test(remoteOriginUrl)) {\n template2 = template;\n }\n }\n\n if (!template2) {\n throw new AppError(`No matching template found for \"${remoteOriginUrl}\"`);\n }\n\n return template2;\n}\n\nasync function createMsg(answers: AnswersType, template: ConfigTemplateType): Promise<string> {\n const type = answers.type ? answers.type.trim() : \"\";\n const scope = answers.scope ? answers.scope.trim() : \"\";\n const body = answers.body\n ? answers.body\n .split(\"\\\\n\")\n .map((x) => x.trim())\n .join(\"\\n\")\n .trim()\n : \"\";\n const description = answers.description ? answers.description.trim() : \"\";\n const issue = answers.issue ? answers.issue.trim() : \"\";\n\n let msg = template.pattern;\n\n if (type) {\n const typeText = `${template.pre_type ?? \"\"}${type}${template.post_type ?? \"\"}`;\n msg = msg.replace(\"{type}\", typeText);\n } else {\n msg = msg.replace(\"{type}\", \"\");\n }\n\n if (scope) {\n const scopeText = `${template.pre_scope ?? \"\"}${scope}${template.post_scope ?? \"\"}`;\n msg = msg.replace(\"{scope}\", scopeText);\n } else {\n msg = msg.replace(\"{scope}\", \"\");\n }\n\n if (description) {\n const descriptionText = `${template.pre_description ?? \"\"}${description}${\n template.post_description ?? \"\"\n }`;\n msg = msg.replace(\"{description}\", descriptionText);\n } else {\n msg = msg.replace(\"{description}\", \"\");\n }\n\n if (body) {\n const bodyText = `${template.pre_body ?? \"\"}${body}${template.post_body ?? \"\"}`;\n msg = msg.replace(\"{body}\", bodyText);\n } else {\n msg = msg.replace(\"{body}\", \"\");\n }\n\n if (issue) {\n const issueText = `${template.pre_issue ?? \"\"}${issue}${template.post_issue ?? \"\"}`;\n msg = msg.replace(\"{issue}\", issueText);\n const issue2Text = `${template.pre_issue2 ?? \"\"}${issue}${template.post_issue2 ?? \"\"}`;\n msg = msg.replace(\"{issue2}\", issue2Text);\n const issue3Text = `${template.pre_issue3 ?? \"\"}${issue}${template.post_issue3 ?? \"\"}`;\n msg = msg.replace(\"{issue3}\", issue3Text);\n } else {\n msg = msg.replace(\"{issue}\", \"\");\n msg = msg.replace(\"{issue2}\", \"\");\n msg = msg.replace(\"{issue3}\", \"\");\n }\n\n return msg;\n}\n\nmain().catch(console.error);\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAmB,MAAM,aAAa,CAAC;AAE1D,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EACL,UAAU,EACV,kBAAkB,EAClB,iBAAiB,EACjB,WAAW,EACX,WAAW,EACX,UAAU,GACX,MAAM,gBAAgB,CAAC;AAGxB,KAAK,UAAU,IAAI;IACjB,IAAI,CAAC;QACH,MAAM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AAC,UAAU,EAAE,EAAE,CAAC,CAAC;QAClC,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IACpC,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport { Git } from \"./git.js\";\nimport { loadConfig, type ConfigType } from \"./config.js\";\nimport type { ConfigTemplateType } from \"./config.js\";\nimport { AppError } from \"./app-error.js\";\nimport {\n askForBody,\n askForConfirmation,\n askForDescription,\n askForIssue,\n askForScope,\n askForType,\n} from \"./questions.js\";\nimport type { AnswersType } from \"./questions.js\";\n\nasync function main(): Promise<void> {\n try {\n const git = new Git();\n\n if (!(await git.isCurrentDirUnderGitControl())) {\n throw new AppError(\"Current directory is not a git repository.\");\n }\n\n if (!(await git.haveStagedChanges())) {\n throw new AppError(\"Nothing to commit\");\n }\n\n const config = loadConfig();\n const remoteOriginUrl = (await git.getGitRemoteOriginUrl()).trim();\n const template = getMatchingTemplate(config, remoteOriginUrl);\n console.info(`Using template \"${template.name}\"\\n`);\n\n const answers: AnswersType = {\n type: (await askForType()).trim(),\n scope: (await askForScope()).trim(),\n description: (await askForDescription()).trim(),\n body: (await askForBody()).trim(),\n issue: (await askForIssue()).trim(),\n };\n\n const msg = await createMsg(answers, template);\n console.info(`${\"-\".repeat(42)}\\n${msg}\\n${\"-\".repeat(42)}`);\n if (await askForConfirmation()) {\n await git.commit(msg);\n console.info(\"done\");\n }\n } catch (err) {\n if (err instanceof AppError) {\n console.error(err.message);\n process.exit(100);\n } else if (\n err instanceof Error &&\n err.message.startsWith(\"User force closed the prompt with\")\n ) {\n // Abort exception of @inquirer\n process.exit(0);\n } else {\n console.error(err);\n process.exit(1);\n }\n }\n}\n\nfunction getMatchingTemplate(config: ConfigType, remoteOriginUrl: string): ConfigTemplateType {\n // ToDo: rename var\n let template2: ConfigTemplateType | undefined;\n\n for (const template of config.templates) {\n const regEx = new RegExp(template.regex);\n if (regEx.test(remoteOriginUrl)) {\n template2 = template;\n }\n }\n\n if (!template2) {\n throw new AppError(`No matching template found for \"${remoteOriginUrl}\"`);\n }\n\n return template2;\n}\n\nasync function createMsg(answers: AnswersType, template: ConfigTemplateType): Promise<string> {\n const body = answers.body\n ? answers.body\n .split(\"\\\\n\")\n .map((x) => x.trim())\n .join(\"\\n\")\n .trim()\n : \"\";\n\n let msg = template.pattern;\n\n if (answers.type) {\n const typeText = `${template.pre_type ?? \"\"}${answers.type}${template.post_type ?? \"\"}`;\n msg = msg.replace(\"{type}\", typeText);\n } else {\n msg = msg.replace(\"{type}\", \"\");\n }\n\n if (answers.scope) {\n const scopeText = `${template.pre_scope ?? \"\"}${answers.scope}${template.post_scope ?? \"\"}`;\n msg = msg.replace(\"{scope}\", scopeText);\n } else {\n msg = msg.replace(\"{scope}\", \"\");\n }\n\n if (answers.description) {\n const descriptionText = `${template.pre_description ?? \"\"}${answers.description}${\n template.post_description ?? \"\"\n }`;\n msg = msg.replace(\"{description}\", descriptionText);\n } else {\n msg = msg.replace(\"{description}\", \"\");\n }\n\n if (body) {\n const bodyText = `${template.pre_body ?? \"\"}${body}${template.post_body ?? \"\"}`;\n msg = msg.replace(\"{body}\", bodyText);\n } else {\n msg = msg.replace(\"{body}\", \"\");\n }\n\n if (answers.issue) {\n const issueText = `${template.pre_issue ?? \"\"}${answers.issue}${template.post_issue ?? \"\"}`;\n msg = msg.replace(\"{issue}\", issueText);\n const issue2Text = `${template.pre_issue2 ?? \"\"}${answers.issue}${template.post_issue2 ?? \"\"}`;\n msg = msg.replace(\"{issue2}\", issue2Text);\n const issue3Text = `${template.pre_issue3 ?? \"\"}${answers.issue}${template.post_issue3 ?? \"\"}`;\n msg = msg.replace(\"{issue3}\", issue3Text);\n } else {\n msg = msg.replace(\"{issue}\", \"\");\n msg = msg.replace(\"{issue2}\", \"\");\n msg = msg.replace(\"{issue3}\", \"\");\n }\n\n return msg;\n}\n\nmain().catch(console.error);\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"questions.js","sourceRoot":"","sources":["../src/questions.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,OAAO,MAAM,mBAAmB,CAAC;AAUxC,MAAM,UAAU,UAAU;IACxB,OAAO,MAAM,CAAC;QACZ,OAAO,EAAE,OAAO;QAChB,QAAQ,EAAE,EAAE;QACZ,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,KAAK;gBACX,KAAK,EAAE,KAAK;gBACZ,WAAW,EAAE,UAAU;aACxB;YACD;gBACE,IAAI,EAAE,MAAM;gBACZ,KAAK,EAAE,MAAM;gBACb,WAAW,EAAE,eAAe;aAC7B;YACD;gBACE,IAAI,EAAE,UAAU;gBAChB,KAAK,EAAE,UAAU;gBACjB,WAAW,EAAE,2DAA2D;aACzE;YACD;gBACE,IAAI,EAAE,MAAM;gBACZ,KAAK,EAAE,MAAM;gBACb,WAAW,EAAE,yCAAyC;aACvD;YACD;gBACE,IAAI,EAAE,MAAM;gBACZ,KAAK,EAAE,MAAM;gBACb,WAAW,EAAE,4BAA4B;aAC1C;YACD;gBACE,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE,OAAO;gBACd,WAAW,EAAE,mEAAmE;aACjF;YACD;gBACE,IAAI,EAAE,MAAM;gBACZ,KAAK,EAAE,MAAM;gBACb,WAAW,EAAE,yBAAyB;aACvC;YACD;gBACE,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE,OAAO;gBACd,WAAW,EAAE,mDAAmD;aACjE;YACD;gBACE,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE,OAAO;gBACd,WAAW,EAAE,8DAA8D;aAC5E;YACD;gBACE,IAAI,EAAE,IAAI;gBACV,KAAK,EAAE,IAAI;gBACX,WAAW,EAAE,qDAAqD;aACnE;YACD;gBACE,IAAI,EA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;aACtC;iBAAM;gBACL,OAAO,IAAI,CAAC;aACb;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,kBAAkB;IAChC,OAAO,OAAO,CAAC;QACb,OAAO,EAAE,eAAe;QACxB,OAAO,EAAE,IAAI;KACd,CAAC,CAAC;AACL,CAAC","sourcesContent":["import select from \"@inquirer/select\";\nimport input from \"@inquirer/input\";\nimport confirm from \"@inquirer/confirm\";\n\nexport interface AnswersType {\n type: string;\n scope: string;\n description: string;\n body: string;\n issue: string;\n}\n\nexport function askForType(): Promise<string> {\n return select({\n message: \"type?\",\n pageSize: 99,\n choices: [\n {\n name: \"fix\",\n value: \"fix\",\n description: \"A bugfix\",\n },\n {\n name: \"feat\",\n value: \"feat\",\n description: \"A new feature\",\n },\n {\n name: \"refactor\",\n value: \"refactor\",\n description: \"A code change that neither fixes a bug nor adds a feature\",\n },\n {\n name: \"perf\",\n value: \"perf\",\n description: \"A code change that improves performance\",\n },\n {\n name: \"docs\",\n value: \"docs\",\n description: \"Documentation only changes\",\n },\n {\n name: \"style\",\n value: \"style\",\n description: \"Code style (semicolon, indentation, white-space, formatting, ...)\",\n },\n {\n name: \"test\",\n value: \"test\",\n description: \"add/change/delete tests\",\n },\n {\n name: \"chore\",\n value: \"chore\",\n description: \"Other changes that don't modify src or test files\",\n },\n {\n name: \"build\",\n value: \"build\",\n description: \"build system (npm, git, VSCode, tsconfig, angular.json, ...)\",\n },\n {\n name: \"ci\",\n value: \"ci\",\n description: \"CI configuration (GitHub, GitLab, RenovateBot, ...)\",\n },\n {\n name: \"revert\",\n value: \"revert\",\n description: \"Reverts a previous commit\",\n },\n ],\n });\n}\n\nexport function askForScope(): Promise<string> {\n return input({\n message: \"scope?\",\n validate: (value: string): string | boolean => {\n if (value.length > 20) {\n return `Your text is ${value.length - 20} char(s) too long.`;\n } else {\n return true;\n }\n },\n });\n}\n\nexport function askForDescription(): Promise<string> {\n return input({\n message: \"description?\",\n validate: (value: string): string | boolean => {\n if (value.length > 70) {\n return `Your text is ${value.length - 70} 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\nexport function askForBody(): Promise<string> {\n return input({\n message: \"body?\",\n });\n}\n\nexport function askForIssue(): Promise<string> {\n return input({\n message: \"issue?\",\n validate: (value: string): string | boolean => {\n const regularExpression = /^\\d+$/;\n if (value.length > 0 && !regularExpression.test(value)) {\n return \"Your issue is not a number.\";\n } else {\n return true;\n }\n },\n });\n}\n\nexport function askForConfirmation(): Promise<boolean> {\n return confirm({\n message: \"Is this okay?\",\n default: true,\n });\n}\n"]}
1
+ {"version":3,"file":"questions.js","sourceRoot":"","sources":["../src/questions.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,OAAO,MAAM,mBAAmB,CAAC;AAUxC,MAAM,UAAU,UAAU;IACxB,OAAO,MAAM,CAAC;QACZ,OAAO,EAAE,OAAO;QAChB,QAAQ,EAAE,EAAE;QACZ,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,KAAK;gBACX,KAAK,EAAE,KAAK;gBACZ,WAAW,EAAE,UAAU;aACxB;YACD;gBACE,IAAI,EAAE,MAAM;gBACZ,KAAK,EAAE,MAAM;gBACb,WAAW,EAAE,eAAe;aAC7B;YACD;gBACE,IAAI,EAAE,UAAU;gBAChB,KAAK,EAAE,UAAU;gBACjB,WAAW,EAAE,2DAA2D;aACzE;YACD;gBACE,IAAI,EAAE,MAAM;gBACZ,KAAK,EAAE,MAAM;gBACb,WAAW,EAAE,yCAAyC;aACvD;YACD;gBACE,IAAI,EAAE,MAAM;gBACZ,KAAK,EAAE,MAAM;gBACb,WAAW,EAAE,4BAA4B;aAC1C;YACD;gBACE,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE,OAAO;gBACd,WAAW,EAAE,mEAAmE;aACjF;YACD;gB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ACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,OAAO,KAAK,CAAC;QACX,OAAO,EAAE,OAAO;KACjB,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,WAAW;IACzB,OAAO,KAAK,CAAC;QACX,OAAO,EAAE,QAAQ;QACjB,QAAQ,EAAE,CAAC,KAAa,EAAoB,EAAE;YAC5C,MAAM,iBAAiB,GAAG,OAAO,CAAC;YAClC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;gBACvD,OAAO,6BAA6B,CAAC;YACvC,CAAC;iBAAM,CAAC;gBACN,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,kBAAkB;IAChC,OAAO,OAAO,CAAC;QACb,OAAO,EAAE,eAAe;QACxB,OAAO,EAAE,IAAI;KACd,CAAC,CAAC;AACL,CAAC","sourcesContent":["import select from \"@inquirer/select\";\nimport input from \"@inquirer/input\";\nimport confirm from \"@inquirer/confirm\";\n\nexport interface AnswersType {\n type: string;\n scope: string;\n description: string;\n body: string;\n issue: string;\n}\n\nexport function askForType(): Promise<string> {\n return select({\n message: \"type?\",\n pageSize: 99,\n choices: [\n {\n name: \"fix\",\n value: \"fix\",\n description: \"A bugfix\",\n },\n {\n name: \"feat\",\n value: \"feat\",\n description: \"A new feature\",\n },\n {\n name: \"refactor\",\n value: \"refactor\",\n description: \"A code change that neither fixes a bug nor adds a feature\",\n },\n {\n name: \"perf\",\n value: \"perf\",\n description: \"A code change that improves performance\",\n },\n {\n name: \"docs\",\n value: \"docs\",\n description: \"Documentation only changes\",\n },\n {\n name: \"style\",\n value: \"style\",\n description: \"Code style (semicolon, indentation, white-space, formatting, ...)\",\n },\n {\n name: \"test\",\n value: \"test\",\n description: \"add/change/delete tests\",\n },\n {\n name: \"chore\",\n value: \"chore\",\n description: \"Other changes that don't modify src or test files\",\n },\n {\n name: \"build\",\n value: \"build\",\n description: \"build system (npm, git, VSCode, tsconfig, angular.json, ...)\",\n },\n {\n name: \"ci\",\n value: \"ci\",\n description: \"CI configuration (GitHub, GitLab, RenovateBot, ...)\",\n },\n {\n name: \"revert\",\n value: \"revert\",\n description: \"Reverts a previous commit\",\n },\n ],\n });\n}\n\nexport function askForScope(): Promise<string> {\n return input({\n message: \"scope?\",\n validate: (value: string): string | boolean => {\n if (value.length > 20) {\n return `Your text is ${value.length - 20} char(s) too long.`;\n } else {\n return true;\n }\n },\n });\n}\n\nexport function askForDescription(): Promise<string> {\n return input({\n message: \"description?\",\n validate: (value: string): string | boolean => {\n if (value.length > 70) {\n return `Your text is ${value.length - 70} 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\nexport function askForBody(): Promise<string> {\n return input({\n message: \"body?\",\n });\n}\n\nexport function askForIssue(): Promise<string> {\n return input({\n message: \"issue?\",\n validate: (value: string): string | boolean => {\n const regularExpression = /^\\d+$/;\n if (value.length > 0 && !regularExpression.test(value)) {\n return \"Your issue is not a number.\";\n } else {\n return true;\n }\n },\n });\n}\n\nexport function askForConfirmation(): Promise<boolean> {\n return confirm({\n message: \"Is this okay?\",\n default: true,\n });\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@4s1/conventional-commit-creator",
3
- "version": "3.7.0",
3
+ "version": "3.9.0-rc.0",
4
4
  "description": "Conventional Commit Creator",
5
5
  "keywords": [
6
6
  "conventional commit",
@@ -28,19 +28,19 @@
28
28
  ],
29
29
  "prettier": "@4s1/eslint-config",
30
30
  "dependencies": {
31
- "@inquirer/confirm": "2.0.8",
32
- "@inquirer/input": "1.2.6",
33
- "@inquirer/select": "1.2.7"
31
+ "@inquirer/confirm": "3.0.0",
32
+ "@inquirer/input": "2.0.0",
33
+ "@inquirer/select": "2.0.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@4s1/eslint-config": "7.1.1",
37
- "@4s1/ts-config": "5.2.1",
38
- "@types/node": "18.17.1",
39
- "@types/prompts": "2.4.4",
40
- "eslint": "8.46.0",
41
- "prettier": "3.0.0",
42
- "ts-node": "10.9.1",
43
- "typescript": "5.1.6"
36
+ "@4s1/eslint-config": "7.4.0",
37
+ "@4s1/ts-config": "7.0.0",
38
+ "@types/node": "20.11.19",
39
+ "@types/prompts": "2.4.9",
40
+ "eslint": "8.56.0",
41
+ "prettier": "3.2.5",
42
+ "tsx": "4.7.1",
43
+ "typescript": "5.3.3"
44
44
  },
45
45
  "publishConfig": {
46
46
  "access": "public"
@@ -52,9 +52,8 @@
52
52
  "lbt": "pnpm run lint && pnpm run build && pnpm run test",
53
53
  "lint": "eslint --ext .ts src/ && prettier --check .",
54
54
  "start": "node dist/index.js",
55
- "start:dev": "ts-node --esm src/index.ts",
55
+ "start:dev": "tsx src/index.ts",
56
56
  "test": "echo no tests",
57
- "test:cov": "pnpm run test --coverage",
58
57
  "test:watch": "pnpm run test --watch",
59
58
  "preversion": "pnpm run lbt",
60
59
  "postversion": "git push && git push --follow-tags"