Skip to content

Commits on Source 71

# [2.0.0](https://gitlab.kilic.dev/libraries/cz-cc/compare/v1.8.1...v2.0.0) (2025-05-30)
* [object Object](engine): use inquirer instead [skip ci] ([1b87303](https://gitlab.kilic.dev/libraries/cz-cc/commit/1b87303cf7ad3b3a990c130b304dc2d474ead699))
### Performance Improvements
* **engine:** migrate to inquirer ([3332d00](https://gitlab.kilic.dev/libraries/cz-cc/commit/3332d00f2e503e476d2c464a0353bddb7dffef59))
### BREAKING CHANGES
* **engine:** completely changes the behavior
* asdfasdfasd
re 123
## [1.8.1](https://gitlab.kilic.dev/libraries/cz-cc/compare/v1.8.0...v1.8.1) (2025-04-11)
......
{
"name": "@cenk1cenk2/cz-cc",
"version": "1.8.1",
"version": "2.0.0",
"description": "Commitizen adapter following the conventional-changelog format.",
"repository": "git@gitlab.kilic.dev:libraries/cz-cc.git",
"author": "Cenk Kilic <cenk@kilic.dev>",
......@@ -33,20 +33,19 @@
"node": ">= 16"
},
"dependencies": {
"@listr2/prompt-adapter-enquirer": "^2.0.15",
"@inquirer/prompts": "^7.5.3",
"@listr2/prompt-adapter-inquirer": "^2.0.22",
"commitizen": "^4.3.1",
"conventional-commit-types": "^3.0.0",
"enquirer": "^2.4.1",
"external-editor": "^3.1.0",
"find-git-root": "^1.0.4",
"listr2": "^8.3.2"
},
"devDependencies": {
"@cenk1cenk2/eslint-config": "^3.1.34",
"eslint": "^9.24.0",
"lint-staged": "^15.5.1",
"@cenk1cenk2/eslint-config": "^3.1.39",
"eslint": "^9.26.0",
"lint-staged": "^15.5.2",
"prettier": "^3.5.3",
"simple-git-hooks": "^2.12.1",
"simple-git-hooks": "^2.13.0",
"tsup": "^8.4.0"
},
"config": {
......
This diff is collapsed.
import { ListrEnquirerPromptAdapter } from '@listr2/prompt-adapter-enquirer'
import Enquirer from 'enquirer'
import { ListrInquirerPromptAdapter } from '@listr2/prompt-adapter-inquirer'
import findGitRoot from 'find-git-root'
import fs from 'fs'
import { Listr, color } from 'listr2'
import { EOL } from 'os'
import { join } from 'path'
import { EditorPrompt } from './prompt'
import { confirm, select, input, checkbox, editor } from '@inquirer/prompts'
export default function(options) {
const choices = Object.entries(options.types).map(([key, type]) => {
return {
name: key,
hint: type.description,
value: key
}
})
return {
prompter(cz, commit) {
new Listr(
......@@ -41,10 +31,9 @@ export default function(options) {
},
task: async(ctx, task) => {
if (
await task.prompt(ListrEnquirerPromptAdapter).run({
type: 'Toggle',
await task.prompt(ListrInquirerPromptAdapter).run(confirm, {
message: 'Last commit was found as merge commit do you want to skip?',
initial: true
default: true
})
) {
throw new Error('Skipping because of merge commit.')
......@@ -53,43 +42,58 @@ export default function(options) {
},
{
task: async(ctx, task) =>
(ctx.prompts = await task.prompt(ListrEnquirerPromptAdapter).run([
{
type: 'autocomplete',
name: 'type',
task: async(ctx, task) => {
const choices = Object.entries(options.types).map(([key, type]) => {
return {
name: key,
description: type.description,
value: key
}
})
ctx.prompts.type = await task.prompt(ListrInquirerPromptAdapter).run(select, {
message: 'Type of commit:',
choices,
initial: choices.findIndex((val) => val.value === options.defaultType)
},
default: options.defaultType
})
{
type: 'Input',
name: 'subject',
message: 'Write a short description:' + EOL,
initial: options.defaultSubject,
ctx.prompts.subject = await task.prompt(ListrInquirerPromptAdapter).run(input, {
message: 'Write a short description:',
default: options.defaultSubject,
required: true
},
})
{
type: 'MultiSelect',
name: 'additional',
ctx.prompts.additional = await task.prompt(ListrInquirerPromptAdapter).run(checkbox, {
message: 'Please select additional actions.',
choices: [
{ name: 'scope', message: 'add a scope' },
{ name: 'issue', message: 'resolves issues' },
{
name: 'scope',
value: 'scope',
description: 'Add a scope to the commit message.'
},
{
name: 'issue',
value: 'issue',
description: 'Resolve Issues by additional comments.'
},
{
name: 'breaking-changes',
message: 'introduces breaking changes'
value: 'breaking-changes',
description: 'Note breaking changes in the commit message.'
},
{
name: 'long-description',
message: 'add a long description'
value: 'long-description',
description: 'Add a long description to the commit message.'
},
{ name: 'skip-ci', message: 'skip ci/cd setups' }
{
name: 'skip-ci',
value: 'skip-ci',
description: 'Skip CI/CD setups.'
}
]
})
}
]))
},
{
......@@ -98,11 +102,10 @@ export default function(options) {
{
skip: (ctx) => !ctx.prompts.additional.includes('scope'),
task: async(ctx, task) => {
ctx.prompts.scope = await task.prompt(ListrEnquirerPromptAdapter).run({
type: 'Input',
message: 'Please state the scope of the change:' + EOL,
initial: options.defaultScope,
format: (value) => {
ctx.prompts.scope = await task.prompt(ListrInquirerPromptAdapter).run(input, {
message: 'Please state the scope of the change:',
default: options.defaultScope,
transformer: (value) => {
return options.disableScopeLowerCase ? value.trim() : value.trim().toLowerCase()
}
})
......@@ -112,30 +115,19 @@ export default function(options) {
{
skip: (ctx) => !ctx.prompts.additional.some((property) => ['long-description'].includes(property)),
task: async(ctx, task) => {
const enquirer = new Enquirer().register('editor', EditorPrompt)
ctx.prompts.body = await task.prompt(ListrEnquirerPromptAdapter).run(
[
{
type: 'editor',
name: 'default',
message: 'Please give a long description:' + EOL,
initial: options.defaultBody
}
],
{ enquirer }
)
ctx.prompts.body = await task.prompt(ListrInquirerPromptAdapter).run(editor, {
message: 'Please give a long description:',
default: options.defaultBody
})
}
},
{
skip: (ctx) => !ctx.prompts.additional.includes('issue'),
task: async(ctx, task) => {
ctx.prompts.issues = await task.prompt(ListrEnquirerPromptAdapter).run({
type: 'input',
message: 'Add issue references:' + EOL,
hint: 'fix #123, re #124',
initial: options.defaultIssues
ctx.prompts.issues = await task.prompt(ListrInquirerPromptAdapter).run(input, {
message: 'Add issue references:',
default: options.defaultIssues
})
}
},
......@@ -143,9 +135,8 @@ export default function(options) {
{
skip: (ctx) => !ctx.prompts.additional.includes('breaking-changes'),
task: async(ctx, task) => {
ctx.prompts.breaking = await task.prompt(ListrEnquirerPromptAdapter).run({
type: 'editor',
message: 'Describe the breaking changes:' + EOL
ctx.prompts.breaking = await task.prompt(ListrInquirerPromptAdapter).run(editor, {
message: 'Describe the breaking changes:'
})
}
}
......@@ -154,7 +145,10 @@ export default function(options) {
],
{
rendererOptions: { collapseSubtasks: false },
fallbackRendererCondition: false
fallbackRendererCondition: false,
ctx: {
prompts: {}
}
}
)
.run()
......
// @ts-nocheck
import { Prompt } from 'enquirer'
import { edit } from 'external-editor'
import { EOL } from 'os'
export class EditorPrompt extends Prompt {
constructor(options = {}) {
super(options)
this.value = this.state.initial || ''
}
async suffix(addon = '') {
const suffix = this.state.cancelled ? ' — Aborted' : this.state.submitted ? ' — Received' : ' — Press <Enter> to launch ' + addon
return this.styles.dim(suffix)
}
// Intercept submit and launch the editor
async submit() {
this.value = edit(this.value)
return super.submit()
}
async render() {
const prefix = (await this.prefix()) + ' '
const message = await this.message()
const error = await this.error()
const suffix = error ? await this.suffix('the editor again') : await this.suffix('an editor')
this.clear(this.state.size)
this.cursorHide()
this.write(this.style.bold(prefix) + message + suffix)
if (error) {
this.write(EOL + error.split(EOL).join(''))
}
}
}