@4s1/conventional-commit-creator 3.4.0 → 3.6.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.
@@ -0,0 +1,4 @@
1
+ export declare class AppError extends Error {
2
+ constructor(msg: string);
3
+ }
4
+ //# sourceMappingURL=app-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-error.d.ts","sourceRoot":"","sources":["../src/app-error.ts"],"names":[],"mappings":"AAAA,qBAAa,QAAS,SAAQ,KAAK;gBACrB,GAAG,EAAE,MAAM;CAMxB"}
package/dist/app-error.js CHANGED
@@ -5,3 +5,4 @@ export class AppError extends Error {
5
5
  Object.setPrototypeOf(this, AppError.prototype);
6
6
  }
7
7
  }
8
+ //# sourceMappingURL=app-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-error.js","sourceRoot":"","sources":["../src/app-error.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,QAAS,SAAQ,KAAK;IACjC,YAAY,GAAW;QACrB,KAAK,CAAC,GAAG,CAAC,CAAC;QAEX,gCAAgC;QAChC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IAClD,CAAC;CACF","sourcesContent":["export class AppError extends Error {\n constructor(msg: string) {\n super(msg);\n\n // Set the prototype explicitly.\n Object.setPrototypeOf(this, AppError.prototype);\n }\n}\n"]}
@@ -0,0 +1,26 @@
1
+ export type ConfigTemplateType = {
2
+ name: string;
3
+ regex: string;
4
+ pattern: string;
5
+ pre_type?: string;
6
+ post_type?: string;
7
+ pre_scope?: string;
8
+ post_scope?: string;
9
+ pre_description?: string;
10
+ post_description?: string;
11
+ pre_body?: string;
12
+ post_body?: string;
13
+ pre_issue?: string;
14
+ post_issue?: string;
15
+ pre_issue2?: string;
16
+ post_issue2?: string;
17
+ pre_issue3?: string;
18
+ post_issue3?: string;
19
+ };
20
+ export type ConfigType = {
21
+ $schema: 'https://www.4s1.de/conventional-commit-creator/schema.json';
22
+ version: number;
23
+ templates: ConfigTemplateType[];
24
+ };
25
+ export declare function loadConfig(): ConfigType;
26
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAEhB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,4DAA4D,CAAC;IACtE,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,kBAAkB,EAAE,CAAC;CACjC,CAAC;AAEF,wBAAgB,UAAU,IAAI,UAAU,CAsCvC"}
package/dist/config.js CHANGED
@@ -38,3 +38,4 @@ export function loadConfig() {
38
38
  return config;
39
39
  }
40
40
  }
41
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MA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MAAM,CAAC;KACf;AACH,CAAC","sourcesContent":["import fs from 'node:fs';\nimport os from 'node:os';\nimport path from 'node:path';\n\nexport type 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 type 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.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ export declare class Git {
2
+ isCurrentDirUnderGitControl(): Promise<boolean>;
3
+ haveStagedChanges(): Promise<boolean>;
4
+ getGitRemoteOriginUrl(): Promise<string>;
5
+ commit(msg: string): Promise<void>;
6
+ private encodeMessage;
7
+ private execute;
8
+ }
9
+ //# sourceMappingURL=git.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AAGA,qBAAa,GAAG;IACD,2BAA2B,IAAI,OAAO,CAAC,OAAO,CAAC;IAU/C,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC;IAWrC,qBAAqB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIxC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAU/C,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,OAAO;CAWhB"}
package/dist/git.js CHANGED
@@ -49,3 +49,4 @@ export class Git {
49
49
  });
50
50
  }
51
51
  }
52
+ //# sourceMappingURL=git.js.map
@@ -0,0 +1 @@
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;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;SACd;IACH,CAAC;IAEM,KAAK,CAAC,iBAAiB;QAC5B,IAAI;YACF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,6BAA6B,CAAC,CAAC;YACjE,OAAO,MAAM,KAAK,EAAE,CAAC;SACtB;QAAC,OAAO,GAAG,EAAE;YACZ,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACnB,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;YAC5B,OAAO,KAAK,CAAC;SACd;IACH,CAAC;IAEM,KAAK,CAAC,qBAAqB;QAChC,OAAO,IAAI,CAAC,OAAO,CAAC,kCAAkC,CAAC,CAAC;IAC1D,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,GAAW;QAC7B,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAC/B,IAAI;YACF,MAAM,IAAI,CAAC,OAAO,CAAC,kBAAkB,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;SAClE;QAAC,OAAO,GAAG,EAAE;YACZ,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACjB;IACH,CAAC;IAEO,aAAa,CAAC,GAAW;QAC/B,OAAO,GAAG,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACpC,CAAC;IAEO,OAAO,CAAC,GAAW;QACzB,OAAO,IAAI,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"]}
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js CHANGED
@@ -112,3 +112,4 @@ async function createMsg(answers, template) {
112
112
  return msg;
113
113
  }
114
114
  main().catch(console.error);
115
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,EAAE,UAAU,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGzH,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,iBAAiB,EAAE,CAAC,EAAE;YACpC,MAAM,IAAI,QAAQ,CAAC,mBAAmB,CAAC,CAAC;SAC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C,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 { askForBody, askForConfirmation, askForDescription, askForIssue, askForScope, askForType } 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}${template.post_description ?? ''}`;\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"]}
@@ -0,0 +1,14 @@
1
+ export type AnswersType = {
2
+ type: string;
3
+ scope: string;
4
+ description: string;
5
+ body: string;
6
+ issue: string;
7
+ };
8
+ export declare function askForType(): Promise<string>;
9
+ export declare function askForScope(): Promise<string>;
10
+ export declare function askForDescription(): Promise<string>;
11
+ export declare function askForBody(): Promise<string>;
12
+ export declare function askForIssue(): Promise<string>;
13
+ export declare function askForConfirmation(): Promise<boolean>;
14
+ //# sourceMappingURL=questions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"questions.d.ts","sourceRoot":"","sources":["../src/questions.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,wBAAgB,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CA8D5C;AAED,wBAAgB,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC,CAW7C;AAED,wBAAgB,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC,CAanD;AAED,wBAAgB,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAI5C;AAED,wBAAgB,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC,CAY7C;AAED,wBAAgB,kBAAkB,IAAI,OAAO,CAAC,OAAO,CAAC,CAKrD"}
package/dist/questions.js CHANGED
@@ -118,3 +118,4 @@ export function askForConfirmation() {
118
118
  default: true,
119
119
  });
120
120
  }
121
+ //# sourceMappingURL=questions.js.map
@@ -0,0 +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,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B,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;gBACtD,OAAO,6BAA6B,CAAC;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 type 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.4.0",
3
+ "version": "3.6.0",
4
4
  "description": "Conventional Commit Creator",
5
5
  "keywords": [
6
6
  "conventional commit",
@@ -29,27 +29,29 @@
29
29
  "scripts": {
30
30
  "build": "rm -rf dist && tsc",
31
31
  "build:dev": "rm -rf dist && tsc --project tsconfig.dev.json",
32
+ "format": "prettier --write .",
32
33
  "lbt": "npm run lint && npm run build && npm run test",
33
34
  "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 --esm src/index.ts",
37
37
  "test": "echo no tests",
38
38
  "test:cov": "pnpm run test --coverage",
39
- "test:watch": "pnpm run test --watch"
39
+ "test:watch": "pnpm run test --watch",
40
+ "preversion": "npm run lbt",
41
+ "postversion": "git push && git push --follow-tags"
40
42
  },
41
43
  "prettier": "@4s1/eslint-config",
42
44
  "dependencies": {
43
- "@inquirer/confirm": "1.0.3",
44
- "@inquirer/input": "1.0.7",
45
- "@inquirer/select": "1.1.3"
45
+ "@inquirer/confirm": "2.0.2",
46
+ "@inquirer/input": "1.2.1",
47
+ "@inquirer/select": "1.2.1"
46
48
  },
47
49
  "devDependencies": {
48
50
  "@4s1/eslint-config": "6.6.0",
49
- "@4s1/ts-config": "4.3.2",
50
- "@types/node": "18.16.12",
51
+ "@4s1/ts-config": "5.0.1",
52
+ "@types/node": "18.16.18",
51
53
  "@types/prompts": "2.4.4",
52
- "eslint": "8.40.0",
54
+ "eslint": "8.42.0",
53
55
  "prettier": "2.8.8",
54
56
  "ts-node": "10.9.1",
55
57
  "typescript": "5.0.4"