From e69e94726d85cc3e52a22193a74597aab14fd9f1 Mon Sep 17 00:00:00 2001 From: Pritin Tyagaraj Date: Tue, 7 Jul 2020 17:53:15 +0200 Subject: [PATCH] Add `--non-interactive` flag --- index.js | 24 +++++++++++++++++------- readme.md | 1 + 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 716cbf9..16f45ff 100644 --- a/index.js +++ b/index.js @@ -16,7 +16,7 @@ const pathToPlist = argv.pathToPlist || `${pathToRoot}/ios/${info.name}/Info.pli const pathToGradle = argv.pathToGradle || `${pathToRoot}/android/app/build.gradle`; // handle case of several plist files const pathsToPlists = Array.isArray(pathToPlist) ? pathToPlist : [pathToPlist]; - +const interactive = !argv.nonInteractive // getting next version const versionCurrent = info.version; @@ -56,9 +56,15 @@ const chain = new Promise((resolve, reject) => { log.warning(`I can\'t understand format of the version "${versionCurrent}".`); } - const question = log.info(`Use "${version}" as the next version? [y/n] `, 0, true); - const answer = readlineSync.question(question).toLowerCase(); - answer === 'y' ? resolve() : reject('Process canceled.'); + let answer + if (interactive) { + const question = log.info(`Use "${version}" as the next version? [y/n] `, 0, true); + answer = readlineSync.question(question).toLowerCase(); + } + + (!interactive || (answer === 'y')) + ? resolve() + : reject() }); @@ -90,9 +96,13 @@ const commit = update.then(() => { log.info(`I want to add a tag:`, 1); log.info(`"v${version}"`, 2); - const question = log.info(`Do you allow me to do this? [y/n] `, 1, true); - const answer = readlineSync.question(question).toLowerCase(); - if (answer === 'y') { + let answer + if (interactive) { + const question = log.info(`Do you allow me to do this? [y/n] `, 1, true); + answer = readlineSync.question(question).toLowerCase(); + } + + if (!interactive || (answer === 'y')) { return helpers.commitVersionIncrease(version, message, [ pathToPackage, ...pathsToPlists, diff --git a/readme.md b/readme.md index 914d58a..57cfb5c 100644 --- a/readme.md +++ b/readme.md @@ -109,3 +109,4 @@ yarn version:up --flag value | **`--pathToPackage './path'`** | `string` | `./package.json` | Path to `package.json` file in your project. | | **`--pathToPlist './path'`** | `string` | `./ios/${package.name}/Info.plist` | Path to `Info.plist` file (ios project). | | **`--pathToGradle './path'`** | `string` | `./android/app/build.gradle` | Path to `build.gradle` file (android project). | +| **`--non-interactive`** | `flag` | | Skip prompts |