11#!/usr/bin/env node
22import chalk from 'chalk' ;
33import execa from 'execa' ;
4+ import yargs from 'yargs' ;
45import inquirer from 'inquirer' ;
56import updateNotifier from 'update-notifier' ;
67
@@ -11,17 +12,28 @@ import { choices, questions } from './promptConfig';
1112const configuration = getConfig ( ) ;
1213const choicesList = choices ( configuration ) ;
1314const questionsList = questions ( choicesList ) ;
15+ const argv = yargs
16+ . usage ( 'Usage: $0' )
17+ . alias ( 'v' , 'version' )
18+ . describe ( 'v' , 'Version number' )
19+ . help ( 'h' )
20+ . alias ( 'h' , 'help' )
21+ . argv ;
1422
1523updateNotifier ( { pkg } ) . notify ( ) ;
1624
17- inquirer . prompt ( questionsList ) . then ( ( answers ) => {
18- const message = answers . moreInfo ? `${ answers . editor } ` : `${ answers . type } ${ answers . description } ` ;
25+ if ( argv . v ) {
26+ console . log ( `v${ pkg . version } ` ) ;
27+ } else {
28+ inquirer . prompt ( questionsList ) . then ( ( answers ) => {
29+ const message = answers . moreInfo ? `${ answers . editor } ` : `${ answers . type } ${ answers . description } ` ;
30+
31+ return execa ( 'git' , [ 'commit' , '-m' , message ] )
32+ . then ( result => console . log ( result . stdout ) )
33+ . catch ( ( ) => {
34+ console . error ( chalk . red ( "Have you thought about 'git add' some files? Add files and try run following again:\n" ) ) ;
35+ console . error ( chalk . green ( `git commit -m "${ message } "` ) ) ;
36+ } ) ;
37+ } ) ;
38+ }
1939
20- return execa ( 'git' , [ 'commit' , '-m' , message ] )
21- . then ( result => console . log ( result . stdout ) )
22- . catch ( ( ) => {
23- console . log ( ) ;
24- console . error ( chalk . red ( "Have you thought about 'git add' some files? Add files and try run following again:\n" ) ) ;
25- console . error ( chalk . green ( `git commit -m "${ message } "` ) ) ;
26- } ) ;
27- } ) ;
0 commit comments