/
index.js
40 lines (33 loc) 路 1.02 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
// @flow
import inquirer from 'inquirer'
import getEmojis from '@utils/getEmojis'
import COMMIT_MODES from '@constants/commit'
import withHook, {
registerHookInterruptionHandler,
cancelIfNeeded
} from './withHook'
import withClient from './withClient'
import prompts from './prompts'
export type CommitOptions = {
message?: string,
mode: typeof COMMIT_MODES.CLIENT | typeof COMMIT_MODES.HOOK,
scope?: string,
title?: string
}
const promptAndCommit = (options: CommitOptions): Function =>
getEmojis()
.then((gitmojis) => prompts(gitmojis, options))
.then((questions) => {
inquirer.prompt(questions).then((answers) => {
if (options.mode === COMMIT_MODES.HOOK) return withHook(answers)
return withClient(answers)
})
})
const commit = (options: CommitOptions): Function => {
if (options.mode === COMMIT_MODES.HOOK) {
registerHookInterruptionHandler()
return cancelIfNeeded().then(() => promptAndCommit(options))
}
return promptAndCommit(options)
}
export default commit