Skip to content

Commit

Permalink
✨ feat: add a prompt to run.ts to test easily
Browse files Browse the repository at this point in the history
  • Loading branch information
Rettend committed Nov 25, 2023
1 parent 1f8cc58 commit 26b0e10
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,44 @@ 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) => {
consola.log(`argv[${i}]: ${arg}`)
})
}

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)
Expand Down

0 comments on commit 26b0e10

Please sign in to comment.