Skip to content

Commit

Permalink
fix(@angular/cli): standardize TTY checks
Browse files Browse the repository at this point in the history
  • Loading branch information
clydin authored and mgechev committed May 23, 2019
1 parent 6d5454d commit 77a1734
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
5 changes: 3 additions & 2 deletions packages/angular/cli/models/analytics.ts
Expand Up @@ -14,6 +14,7 @@ import * as os from 'os';
import * as ua from 'universal-analytics';
import { v4 as uuidV4 } from 'uuid';
import { getWorkspace, getWorkspaceRaw } from '../utilities/config';
import { isTTY } from '../utilities/tty';

const analyticsDebug = debug('ng:analytics'); // Generate analytics, including settings and users.
const analyticsLogDebug = debug('ng:analytics:log'); // Actual logs of events.
Expand Down Expand Up @@ -359,7 +360,7 @@ export function setAnalyticsConfig(level: 'global' | 'local', value: string | bo
*/
export async function promptGlobalAnalytics(force = false) {
analyticsDebug('prompting global analytics.');
if (force || (process.stdout.isTTY && process.stdin.isTTY)) {
if (force || isTTY()) {
const answers = await inquirer.prompt<{ analytics: boolean }>([
{
type: 'confirm',
Expand Down Expand Up @@ -407,7 +408,7 @@ export async function promptProjectAnalytics(force = false): Promise<boolean> {
throw new Error(`Could not find a local workspace. Are you in a project?`);
}

if (force || (process.stdout.isTTY && process.stdin.isTTY)) {
if (force || isTTY()) {
const answers = await inquirer.prompt<{ analytics: boolean }>([
{
type: 'confirm',
Expand Down
3 changes: 2 additions & 1 deletion packages/angular/cli/models/schematic-command.ts
Expand Up @@ -37,6 +37,7 @@ import {
} from '../utilities/config';
import { parseJsonSchemaToOptions } from '../utilities/json-schema';
import { getPackageManager } from '../utilities/package-manager';
import { isTTY } from '../utilities/tty';
import { isPackageNameSafeForAnalytics } from './analytics';
import { BaseCommandOptions, Command } from './command';
import { Arguments, CommandContext, CommandDescription, Option } from './interface';
Expand Down Expand Up @@ -299,7 +300,7 @@ export abstract class SchematicCommand<
return undefined;
});

if (options.interactive !== false && process.stdout.isTTY) {
if (options.interactive !== false && isTTY()) {
workflow.registry.usePromptProvider((definitions: Array<schema.PromptDefinition>) => {
const questions: inquirer.Questions = definitions.map(definition => {
const question: inquirer.Question = {
Expand Down
15 changes: 15 additions & 0 deletions packages/angular/cli/utilities/tty.ts
@@ -0,0 +1,15 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
export function isTTY(): boolean {
const force = process.env['NG_FORCE_TTY'];
if (force !== undefined) {
return !(force === '0' || force.toUpperCase() === 'FALSE');
}

return !!process.stdout.isTTY && !!process.stdin.isTTY;
}

0 comments on commit 77a1734

Please sign in to comment.