Skip to content
This repository was archived by the owner on Jan 18, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 25 additions & 42 deletions packages/expo-cli/src/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import invariant from 'invariant';

import CommandError from './CommandError';
import log from './log';
import prompt, { Question } from './prompt';
import promptNew, { confirmAsync, Question as NewQuestion, selectAsync } from './prompts';
import { nonEmptyInput } from './validators';

UserManager.initialize();

Expand Down Expand Up @@ -42,27 +42,27 @@ export async function loginOrRegisterAsync(): Promise<User> {
);
}

const question: Question = {
type: 'list',
const question: NewQuestion = {
type: 'select',
name: 'action',
message: 'How would you like to authenticate?',
choices: [
{
name: 'Make a new Expo account',
title: 'Make a new Expo account',
value: 'register',
},
{
name: 'Log in with an existing Expo account',
title: 'Log in with an existing Expo account',
value: 'existingUser',
},
{
name: 'Cancel',
title: 'Cancel',
value: 'cancel',
},
],
};

const { action } = await prompt(question);
const { action } = await promptNew(question);

if (action === 'register') {
return register();
Expand Down Expand Up @@ -212,7 +212,7 @@ async function _promptForBackupOTPAsync(
* OTP (or backup code) and also give the user a way to cancel and move to case 3 below.
* 3. User doesn't have a primary device or doesn't have access to their primary device. In this case
* we should show a picker of the SMS devices that they can have an OTP code sent to, and when
* the user picks one we show a prompt for the sent OTP.
* the user picks one we show a prompt() for the sent OTP.
*/
export async function _retryUsernamePasswordAuthWithOTPAsync(
username: string,
Expand Down Expand Up @@ -268,18 +268,14 @@ async function _usernamePasswordAuth(
password?: string,
otp?: string
): Promise<User> {
const questions: Question[] = [];
const questions: NewQuestion[] = [];
if (!username) {
questions.push({
type: 'input',
type: 'text',
name: 'username',
message: 'Username/Email Address:',
validate(val: string) {
if (val.trim() === '') {
return false;
}
return true;
},
format: val => val.trim(),
validate: nonEmptyInput,
});
}

Expand All @@ -288,16 +284,12 @@ async function _usernamePasswordAuth(
type: 'password',
name: 'password',
message: 'Password:',
validate(val: string) {
if (val.trim() === '') {
return false;
}
return true;
},
format: val => val.trim(),
validate: nonEmptyInput,
});
}

const answers = await prompt(questions);
const answers = await promptNew(questions);

const data = {
username: username || answers.username,
Expand Down Expand Up @@ -336,36 +328,26 @@ Just a few questions:
`
);

const questions: Question[] = [
const questions: NewQuestion[] = [
{
type: 'input',
type: 'text',
name: 'email',
message: 'E-mail:',
filter: val => val.trim(),
validate(val) {
if (val.trim() === '') {
return false;
}
return true;
},
format: val => val.trim(),
validate: nonEmptyInput,
},
{
type: 'input',
type: 'text',
name: 'username',
message: 'Username:',
filter: val => val.trim(),
validate(val) {
if (val.trim() === '') {
return false;
}
return true;
},
format: val => val.trim(),
validate: nonEmptyInput,
},
{
type: 'password',
name: 'password',
message: 'Password:',
filter: val => val.trim(),
format: val => val.trim(),
validate(val) {
if (val.trim() === '') {
return 'Please create a password';
Expand All @@ -377,6 +359,7 @@ Just a few questions:
type: 'password',
name: 'passwordRepeat',
message: 'Confirm Password:',
format: val => val.trim(),
validate(val, answers) {
if (val.trim() === '') {
return false;
Expand All @@ -388,7 +371,7 @@ Just a few questions:
},
},
];
const answers = await prompt(questions);
const answers = await promptNew(questions);
const registeredUser = await UserManager.registerAsync(answers as RegistrationData);
log('\nThanks for signing up!');
return registeredUser;
Expand Down
12 changes: 6 additions & 6 deletions packages/expo-cli/src/appleApi/authenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import wordwrap from 'wordwrap';

import { learnMore } from '../commands/utils/TerminalLink';
import log from '../log';
import prompt from '../prompt';
import prompt from '../prompts';
import { nonEmptyInput } from '../validators';
import { runAction, travelingFastlane } from './fastlane';
import * as Keychain from './keychain';
Expand Down Expand Up @@ -133,12 +133,12 @@ async function _promptForAppleId({

const { appleId: promptAppleId } = await prompt(
{
type: 'input',
type: 'text',
name: 'appleId',
message: `Apple ID:`,
validate: nonEmptyInput,
default: lastAppleId ?? undefined,
...(previousAppleId && { default: previousAppleId }),
initial: lastAppleId ?? undefined,
...(previousAppleId && { initial: previousAppleId }),
},
{
nonInteractiveHelp: 'Pass your Apple ID using the --apple-id flag.',
Expand Down Expand Up @@ -205,12 +205,12 @@ async function _chooseTeam(teams: FastlaneTeam[], userProvidedTeamId?: string):
} else {
log(`You have ${teams.length} teams associated with your account`);
const choices = teams.map((team, i) => ({
name: `${i + 1}) ${team.teamId} "${team.name}" (${team.type})`,
title: `${i + 1}) ${team.teamId} "${team.name}" (${team.type})`,
value: team,
}));
const { team } = await prompt(
{
type: 'list',
type: 'select',
name: 'team',
message: 'Which team would you like to use?',
choices,
Expand Down
6 changes: 3 additions & 3 deletions packages/expo-cli/src/askUser.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { UserSettings } from '@expo/xdl';

import log from './log';
import prompt from './prompt';
import prompt from './prompts';

async function askForSendToAsync(): Promise<string> {
const cachedValue = await UserSettings.getAsync('sendTo', null);
log("Enter an email address and we'll send a link to your phone.");
const answers = await prompt(
[
{
type: 'input',
type: 'text',
name: 'sendTo',
message: `Your email address ${cachedValue ? ' (space to not send anything)' : ''}:`,
default: cachedValue ?? undefined,
initial: cachedValue ?? undefined,
},
],
{ nonInteractiveHelp: 'Please specify email address with --send-to.' }
Expand Down
8 changes: 4 additions & 4 deletions packages/expo-cli/src/commands/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import { CreateOrReuseProvisioningProfileAdhoc } from '../../credentials/views/I
import { SetupIosDist } from '../../credentials/views/SetupIosDist';
import { SetupIosPush } from '../../credentials/views/SetupIosPush';
import log from '../../log';
import prompt from '../../prompt';
import { confirmAsync } from '../../prompts';
import prompt, { confirmAsync } from '../../prompts';
import urlOpts from '../../urlOpts';
import * as ClientUpgradeUtils from '../utils/ClientUpgradeUtils';
import { createClientBuildRequest, getExperienceName, isAllowedToBuild } from './clientBuildApi';
Expand Down Expand Up @@ -211,10 +210,11 @@ export default function (program: Command) {
email = user.email;
} else {
({ email } = await prompt({
type: 'text',
name: 'email',
message: 'Please enter an email address to notify, when the build is completed:',
default: context?.user?.email,
filter: value => value.trim(),
initial: context?.user?.email,
format: value => value.trim(),
validate: (value: string) =>
/.+@.+/.test(value) ? true : "That doesn't look like a valid email.",
}));
Expand Down
35 changes: 16 additions & 19 deletions packages/expo-cli/src/commands/eject/ConfigValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { UserManager } from '@expo/xdl';
import got from 'got';

import log from '../../log';
import prompt from '../../prompt';
import { confirmAsync } from '../../prompts';
import prompt, { confirmAsync } from '../../prompts';
import { learnMore } from '../utils/TerminalLink';
import { isUrlAvailableAsync } from '../utils/url';

Expand Down Expand Up @@ -133,15 +132,14 @@ export async function getOrPromptForBundleIdentifier(projectRoot: string): Promi
// prompt a better error message, recommend a default value, and help the user
// validate their custom bundle ID upfront.
const { bundleIdentifier } = await prompt(
[
{
name: 'bundleIdentifier',
default: recommendedBundleId,
// The Apple helps people know this isn't an EAS feature.
message: `What would you like your iOS bundle identifier to be?`,
validate: validateBundleId,
},
],
{
type: 'text',
name: 'bundleIdentifier',
initial: recommendedBundleId,
// The Apple helps people know this isn't an EAS feature.
message: `What would you like your iOS bundle identifier to be?`,
validate: validateBundleId,
},
{
nonInteractiveHelp: noBundleIdMessage,
}
Expand Down Expand Up @@ -220,14 +218,13 @@ export async function getOrPromptForPackage(projectRoot: string): Promise<string
// prompt a better error message, recommend a default value, and help the user
// validate their custom android package upfront.
const { packageName } = await prompt(
[
{
name: 'packageName',
default: recommendedPackage,
message: `What would you like your Android package name to be?`,
validate: validatePackage,
},
],
{
type: 'text',
name: 'packageName',
initial: recommendedPackage,
message: `What would you like your Android package name to be?`,
validate: validatePackage,
},
{
nonInteractiveHelp: noPackageMessage,
}
Expand Down
4 changes: 2 additions & 2 deletions packages/expo-cli/src/commands/upload/IOSUploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import CommandError from '../../CommandError';
import { authenticate, requestAppleIdCreds } from '../../appleApi';
import { Context } from '../../credentials/context';
import log from '../../log';
import prompt, { Question } from '../../prompt';
import prompt, { Question } from '../../prompts';
import BaseUploader, { PlatformOptions } from './BaseUploader';
import { runFastlaneAsync } from './utils';

const PLATFORM = 'ios';

const APP_NAME_TOO_LONG_MSG = `An app name can't be longer than 30 characters.`;
const APP_NAME_QUESTION: Question = {
type: 'input',
type: 'text',
name: 'appName',
message: 'How would you like to name your app?',
validate(appName: string): string | true {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import prompt from '../../../../prompt';
import prompt from '../../../../prompts';
import { nonEmptyInput } from '../../../../validators';

enum AndroidPackageSourceType {
userDefined,
Expand Down Expand Up @@ -27,8 +28,8 @@ async function getAndroidPackageAsync(source: AndroidPackageSource) {
const { androidPackage } = await prompt({
name: 'androidPackage',
message: 'Android package name:',
type: 'input',
validate: (val: string): boolean => val !== '',
type: 'text',
validate: nonEmptyInput,
});
return androidPackage;
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import log from '../../../../log';
import prompt from '../../../../prompt';
import prompt from '../../../../prompts';
import { existingFile } from '../../../../validators';
import { learnMore } from '../../../utils/TerminalLink';

Expand Down Expand Up @@ -62,8 +62,8 @@ async function askForServiceAccountPathAsync(): Promise<string> {
const { filePath } = await prompt({
name: 'filePath',
message: 'Path to Google Service Account file:',
default: 'api-0000000000000000000-111111-aaaaaabbbbbb.json',
type: 'input',
initial: 'api-0000000000000000000-111111-aaaaaabbbbbb.json',
type: 'text',
validate: async (path: string): Promise<boolean | string> => {
if (!(await existingFile(path, false))) {
return `File ${path} doesn't exist.`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { vol } from 'memfs';

import prompt from '../../../../../prompt';
import prompt from '../../../../../prompts';
import {
getServiceAccountAsync,
ServiceAccountSource,
ServiceAccountSourceType,
} from '../ServiceAccountSource';

jest.mock('fs');
jest.mock('../../../../../prompt');
jest.mock('../../../../../prompts');

describe(getServiceAccountAsync, () => {
beforeAll(() => {
Expand Down
Loading