@@ -14,7 +14,13 @@ const path = require('path');
1414const { echo, exec, exit} = require ( 'shelljs' ) ;
1515const yargs = require ( 'yargs' ) ;
1616
17- const { PUBLISH_PACKAGES_TAG } = require ( '../constants' ) ;
17+ const {
18+ PUBLISH_PACKAGES_TAG ,
19+ GENERIC_COMMIT_MESSAGE ,
20+ NO_COMMIT_CHOICE ,
21+ COMMIT_WITH_GENERIC_MESSAGE_CHOICE ,
22+ COMMIT_WITH_CUSTOM_MESSAGE_CHOICE ,
23+ } = require ( '../constants' ) ;
1824const forEachPackage = require ( '../for-each-package' ) ;
1925const checkForGitChanges = require ( '../check-for-git-changes' ) ;
2026const bumpPackageVersion = require ( './bump-package-version' ) ;
@@ -156,33 +162,67 @@ const main = async () => {
156162 . prompt ( [
157163 {
158164 type : 'list' ,
159- name : 'shouldSubmitCommit ' ,
165+ name : 'commitChoice ' ,
160166 message : 'Do you want to submit a commit with these changes?' ,
161- choices : [ 'Yes' , 'No' ] ,
162- filter : val => val === 'Yes' ,
167+ choices : [
168+ {
169+ name : 'Yes, with generic message' ,
170+ value : COMMIT_WITH_GENERIC_MESSAGE_CHOICE ,
171+ } ,
172+ {
173+ name : 'Yes, with custom message' ,
174+ value : COMMIT_WITH_CUSTOM_MESSAGE_CHOICE ,
175+ } ,
176+ {
177+ name : 'No' ,
178+ value : NO_COMMIT_CHOICE ,
179+ } ,
180+ ] ,
163181 } ,
164182 ] )
165- . then ( ( { shouldSubmitCommit} ) => {
166- if ( ! shouldSubmitCommit ) {
167- echo ( 'Not submitting a commit, but keeping all changes' ) ;
168- return ;
183+ . then ( ( { commitChoice} ) => {
184+ switch ( commitChoice ) {
185+ case NO_COMMIT_CHOICE : {
186+ echo ( 'Not submitting a commit, but keeping all changes' ) ;
187+
188+ break ;
189+ }
190+
191+ case COMMIT_WITH_GENERIC_MESSAGE_CHOICE : {
192+ exec ( `git commit -am "${ GENERIC_COMMIT_MESSAGE } "` , {
193+ cwd : ROOT_LOCATION ,
194+ silent : true ,
195+ } ) ;
196+
197+ break ;
198+ }
199+
200+ case COMMIT_WITH_CUSTOM_MESSAGE_CHOICE : {
201+ // exec from shelljs currently does not support interactive input
202+ // https://github.com/shelljs/shelljs/wiki/FAQ#running-interactive-programs-with-exec
203+ execSync ( 'git commit -a' , { cwd : ROOT_LOCATION , stdio : 'inherit' } ) ;
204+
205+ const enteredCommitMessage = exec (
206+ 'git log -n 1 --format=format:%B' ,
207+ {
208+ cwd : ROOT_LOCATION ,
209+ silent : true ,
210+ } ,
211+ ) . stdout . trim ( ) ;
212+ const commitMessageWithTag =
213+ enteredCommitMessage + `\n\n${ PUBLISH_PACKAGES_TAG } ` ;
214+
215+ exec ( `git commit --amend -m "${ commitMessageWithTag } "` , {
216+ cwd : ROOT_LOCATION ,
217+ silent : true ,
218+ } ) ;
219+
220+ break ;
221+ }
222+
223+ default :
224+ throw new Error ( '' ) ;
169225 }
170-
171- // exec from shelljs currently does not support interactive input
172- // https://github.com/shelljs/shelljs/wiki/FAQ#running-interactive-programs-with-exec
173- execSync ( 'git commit -a' , { cwd : ROOT_LOCATION , stdio : 'inherit' } ) ;
174-
175- const enteredCommitMessage = exec ( 'git log -n 1 --format=format:%B' , {
176- cwd : ROOT_LOCATION ,
177- silent : true ,
178- } ) . stdout . trim ( ) ;
179- const commitMessageWithTag =
180- enteredCommitMessage + `\n\n${ PUBLISH_PACKAGES_TAG } ` ;
181-
182- exec ( `git commit --amend -m "${ commitMessageWithTag } "` , {
183- cwd : ROOT_LOCATION ,
184- silent : true ,
185- } ) ;
186226 } )
187227 . then ( ( ) => echo ( ) ) ;
188228 }
0 commit comments