diff --git a/scripts/monorepo/bump-all-updated-packages/index.js b/scripts/monorepo/bump-all-updated-packages/index.js index f3569660a99638..09291c0d723423 100644 --- a/scripts/monorepo/bump-all-updated-packages/index.js +++ b/scripts/monorepo/bump-all-updated-packages/index.js @@ -14,7 +14,13 @@ const path = require('path'); const {echo, exec, exit} = require('shelljs'); const yargs = require('yargs'); -const {PUBLISH_PACKAGES_TAG} = require('../constants'); +const { + PUBLISH_PACKAGES_TAG, + GENERIC_COMMIT_MESSAGE, + NO_COMMIT_CHOICE, + COMMIT_WITH_GENERIC_MESSAGE_CHOICE, + COMMIT_WITH_CUSTOM_MESSAGE_CHOICE, +} = require('../constants'); const forEachPackage = require('../for-each-package'); const checkForGitChanges = require('../check-for-git-changes'); const bumpPackageVersion = require('./bump-package-version'); @@ -156,33 +162,67 @@ const main = async () => { .prompt([ { type: 'list', - name: 'shouldSubmitCommit', + name: 'commitChoice', message: 'Do you want to submit a commit with these changes?', - choices: ['Yes', 'No'], - filter: val => val === 'Yes', + choices: [ + { + name: 'Yes, with generic message', + value: COMMIT_WITH_GENERIC_MESSAGE_CHOICE, + }, + { + name: 'Yes, with custom message', + value: COMMIT_WITH_CUSTOM_MESSAGE_CHOICE, + }, + { + name: 'No', + value: NO_COMMIT_CHOICE, + }, + ], }, ]) - .then(({shouldSubmitCommit}) => { - if (!shouldSubmitCommit) { - echo('Not submitting a commit, but keeping all changes'); - return; + .then(({commitChoice}) => { + switch (commitChoice) { + case NO_COMMIT_CHOICE: { + echo('Not submitting a commit, but keeping all changes'); + + break; + } + + case COMMIT_WITH_GENERIC_MESSAGE_CHOICE: { + exec(`git commit -am "${GENERIC_COMMIT_MESSAGE}"`, { + cwd: ROOT_LOCATION, + silent: true, + }); + + break; + } + + case COMMIT_WITH_CUSTOM_MESSAGE_CHOICE: { + // exec from shelljs currently does not support interactive input + // https://github.com/shelljs/shelljs/wiki/FAQ#running-interactive-programs-with-exec + execSync('git commit -a', {cwd: ROOT_LOCATION, stdio: 'inherit'}); + + const enteredCommitMessage = exec( + 'git log -n 1 --format=format:%B', + { + cwd: ROOT_LOCATION, + silent: true, + }, + ).stdout.trim(); + const commitMessageWithTag = + enteredCommitMessage + `\n\n${PUBLISH_PACKAGES_TAG}`; + + exec(`git commit --amend -m "${commitMessageWithTag}"`, { + cwd: ROOT_LOCATION, + silent: true, + }); + + break; + } + + default: + throw new Error(''); } - - // exec from shelljs currently does not support interactive input - // https://github.com/shelljs/shelljs/wiki/FAQ#running-interactive-programs-with-exec - execSync('git commit -a', {cwd: ROOT_LOCATION, stdio: 'inherit'}); - - const enteredCommitMessage = exec('git log -n 1 --format=format:%B', { - cwd: ROOT_LOCATION, - silent: true, - }).stdout.trim(); - const commitMessageWithTag = - enteredCommitMessage + `\n\n${PUBLISH_PACKAGES_TAG}`; - - exec(`git commit --amend -m "${commitMessageWithTag}"`, { - cwd: ROOT_LOCATION, - silent: true, - }); }) .then(() => echo()); } diff --git a/scripts/monorepo/constants.js b/scripts/monorepo/constants.js index 82a455372bce49..8dd1f6c5fe87a9 100644 --- a/scripts/monorepo/constants.js +++ b/scripts/monorepo/constants.js @@ -9,5 +9,16 @@ */ const PUBLISH_PACKAGES_TAG = '#publish-packages-to-npm'; +const GENERIC_COMMIT_MESSAGE = `bumped packages versions\n\n${PUBLISH_PACKAGES_TAG}`; -module.exports = {PUBLISH_PACKAGES_TAG}; +const NO_COMMIT_CHOICE = 'NO_COMMIT'; +const COMMIT_WITH_GENERIC_MESSAGE_CHOICE = 'COMMIT_WITH_GENERIC_MESSAGE'; +const COMMIT_WITH_CUSTOM_MESSAGE_CHOICE = 'COMMIT_WITH_CUSTOM_MESSAGE'; + +module.exports = { + PUBLISH_PACKAGES_TAG, + GENERIC_COMMIT_MESSAGE, + NO_COMMIT_CHOICE, + COMMIT_WITH_GENERIC_MESSAGE_CHOICE, + COMMIT_WITH_CUSTOM_MESSAGE_CHOICE, +};