From 26b0e10b031af074ee99cdc991eb77a37f6469c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hegyi=20=C3=81ron=20Ferenc?= Date: Sat, 25 Nov 2023 22:04:40 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20add=20a=20prompt=20to=20run?= =?UTF-8?q?.ts=20to=20test=20easily?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/run.ts | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/commands/run.ts b/src/commands/run.ts index 947e5f0..ae5864c 100644 --- a/src/commands/run.ts +++ b/src/commands/run.ts @@ -26,15 +26,19 @@ export default defineCommand({ alias: 'd', default: '0', }, + test: { + type: 'boolean', + description: 'Test mode (input a commit message instead of a file path)', + alias: 't', + default: false, + }, }, async run(ctx) { const DEBUG = Number(ctx.args.DEBUG) try { const config = await loadConfig() - - const commitMessage = fs.readFileSync(ctx.args.commit_file, 'utf-8') - const firstLine = commitMessage.split('\n')[0] ?? '' + let commitMessage: string if (DEBUG >= 2) { process.argv.forEach((arg, i) => { @@ -42,9 +46,24 @@ export default defineCommand({ }) } - const newCommitMessage = eemojify(firstLine, config, DEBUG) + if (ctx.args.test) { + commitMessage = await consola.prompt('Commit message:', { + placeholder: 'enter a commit message for testing...', + initial: 'feat: add new feature', + }) + + if (commitMessage) + eemojify(commitMessage, config, DEBUG) + } + else { + commitMessage = fs.readFileSync(ctx.args.commit_file, 'utf-8') + + commitMessage = commitMessage.split('\n')[0] ?? '' - fs.writeFileSync(ctx.args.commit_file, newCommitMessage) + const newCommitMessage = eemojify(commitMessage, config, DEBUG) + + fs.writeFileSync(ctx.args.commit_file, newCommitMessage) + } } catch (err: any) { consola.error(err)