diff --git a/src/commands/run.ts b/src/commands/run.ts index 25a978a..205b43e 100644 --- a/src/commands/run.ts +++ b/src/commands/run.ts @@ -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() @@ -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...', diff --git a/src/utils/emoji.ts b/src/utils/emoji.ts index 9fb8706..87145db 100644 --- a/src/utils/emoji.ts +++ b/src/utils/emoji.ts @@ -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) +}