Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feature: setup commit command on exec child process
  • Loading branch information
ando committed Jun 1, 2023
commit cb8bfc0a50d0481a849bc91644bdd904b73276ab
22 changes: 20 additions & 2 deletions src/utils/commiter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { promisify } from 'node:util'
import { exec } from 'node:child_process'
import { cancel, intro, group } from '@clack/prompts'
import { lightYellow } from 'kolorist'

import { CANCELED_OP_MSG } from './constants'
import { type, message } from './prompts'
import { handleCliError, CliError } from './cli-errror'
import { log } from './log'

const execa = promisify(exec)

export const commiter = async () => {
intro(lightYellow('Commitizen CLI'))
Expand All @@ -20,6 +26,18 @@ export const commiter = async () => {
}
)

console.log(values.type)
console.log(values.message)
try {
const commit = `${values.type}: ${values.message}`
const cmd = `git commit -m ${commit}`
const { stdout, stderr } = await execa(cmd)

if (stderr) throw new CliError(`An error occured: ${stderr}`)

console.log(stdout)
console.log(commit)
} catch (err: any) {
log({ type: 'error', msg: err.message })
handleCliError(err)
process.exit(1)
}
}