From 4ae26d93f47ba0f77e78c273d1e7bcf935029a9c Mon Sep 17 00:00:00 2001 From: Bunyanuch Saengnet <53788417+bunysae@users.noreply.github.com> Date: Mon, 21 Dec 2020 06:22:26 +0100 Subject: [PATCH] Show prompt only in interactive mode (#583) Co-authored-by: Sindre Sorhus --- package.json | 1 + source/ui.js | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 039dc2d8..97528a36 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "import-local": "^3.0.2", "inquirer": "^7.3.3", "is-installed-globally": "^0.3.2", + "is-interactive": "^1.0.0", "is-scoped": "^2.1.0", "issue-regex": "^3.1.0", "listr": "^0.14.3", diff --git a/source/ui.js b/source/ui.js index 569be234..7c5f6ad8 100644 --- a/source/ui.js +++ b/source/ui.js @@ -4,6 +4,7 @@ const chalk = require('chalk'); const githubUrlFromGit = require('github-url-from-git'); const {htmlEscape} = require('escape-goat'); const isScoped = require('is-scoped'); +const isInteractive = require('is-interactive'); const util = require('./util'); const git = require('./git-util'); const {prereleaseTags, checkIgnoreStrategy, getRegistryUrl, isExternalRegistry} = require('./npm/util'); @@ -56,10 +57,16 @@ const checkIgnoredFiles = async pkg => { return true; } + const message = `The following new files are not already part of your published package:\n${chalk.reset(ignoredFiles.map(path => `- ${path}`).join('\n'))}`; + if (!isInteractive()) { + console.log(message); + return true; + } + const answers = await inquirer.prompt([{ type: 'confirm', name: 'confirm', - message: `The following new files are not already part of your published package:\n${chalk.reset(ignoredFiles.map(path => `- ${path}`).join('\n'))}\nContinue?`, + message: `${message}\nContinue?`, default: false }]);