/
index.js
45 lines (39 loc) 路 1.35 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// @flow
import { execa } from 'execa'
import fs from 'fs'
import chalk from 'chalk'
import isHookCreated from '@utils/isHookCreated'
import configurationVault from '@utils/configurationVault'
import { type Answers } from '../prompts'
const withClient = async (answers: Answers): Promise<void> => {
try {
const scope = answers.scope ? `(${answers.scope}): ` : ''
const title = `${answers.gitmoji} ${scope}${answers.title}`
if (await isHookCreated()) {
return console.log(
chalk.red(
"\nError: Seems that you're trying to commit with the cli " +
'but you have the hook created.\nIf you want to use the `gitmoji -c` ' +
'command you have to remove the hook with the command `gitmoji -r`. \n' +
'The hook must be used only when you want to commit with the instruction `git commit`\n'
)
)
}
if (configurationVault.getAutoAdd()) await execa('git', ['add', '.'])
await execa('git', ['commit', '-m', title, '-m', answers.message], {
buffer: false,
stdio: 'inherit'
})
} catch (error) {
console.error(
chalk.red(
'\n',
'Oops! An error occurred. There is likely additional logging output above.\n',
'You can run the same commit with this command:\n'
),
'\t',
error.escapedCommand
)
}
}
export default withClient