Skip to content

Commit

Permalink
✨ feat: createExampleCommitMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
Rettend committed Nov 27, 2023
1 parent 499ba9e commit 986a017
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { defineCommand } from 'citty'
import { consola } from 'consola'
import { cosmiconfig } from 'cosmiconfig'
import { name } from '../../package.json'
import { eemojify, unemojify } from '../utils/emoji'
import { createExampleCommitMessage, eemojify, unemojify } from '../utils/emoji'
import { type Config, ConfigObject } from './../config'

const C = new ConfigObject()
Expand Down Expand Up @@ -47,10 +47,10 @@ export default defineCommand({
}

if (ctx.args.test) {
let initial = 'feat: add new feature'
let initial = createExampleCommitMessage(config)

if (fs.existsSync(ctx.args.commit_file))
initial = unemojify(fs.readFileSync(ctx.args.commit_file, 'utf-8'), config) ?? ''
initial = unemojify(fs.readFileSync(ctx.args.commit_file, 'utf-8'), config)

commitMessage = await consola.prompt('Commit message:', {
placeholder: 'enter a commit message for testing...',
Expand Down
17 changes: 17 additions & 0 deletions src/utils/emoji.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,20 @@ export function unemojify(text: string, config: Config): string {

return text.replace(regex, '').trim()
}

export function createExampleCommitMessage(config: Config): string {
const type = Object.keys(config.emojis)[0]
let emoji = Object.values(config.emojis)[0]
const subject = 'add new feature'

if (typeof emoji === 'object')
emoji = Object.values(emoji)[0]

if (!type || !emoji)
return ''

return config.format
.replace('{emoji}', emoji)
.replace('{type}', type)
.replace('{subject}', subject)
}

0 comments on commit 986a017

Please sign in to comment.