-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
registerAsync.ts
34 lines (30 loc) · 1009 Bytes
/
registerAsync.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import openBrowserAsync from 'better-opn';
import { CI } from '../utils/env';
import { CommandError } from '../utils/errors';
import { learnMore } from '../utils/link';
import { ora } from '../utils/ora';
export async function registerAsync() {
if (CI) {
throw new CommandError(
'NON_INTERACTIVE',
`Cannot register an account in CI. Use the EXPO_TOKEN environment variable to authenticate in CI (${learnMore(
'https://docs.expo.dev/accounts/programmatic-access/'
)})`
);
}
const registrationUrl = `https://expo.dev/signup`;
const failedMessage = `Unable to open a web browser. Register an account at: ${registrationUrl}`;
const spinner = ora(`Opening ${registrationUrl}`).start();
try {
const opened = await openBrowserAsync(registrationUrl);
if (opened) {
spinner.succeed(`Opened ${registrationUrl}`);
} else {
spinner.fail(failedMessage);
}
return;
} catch (error) {
spinner.fail(failedMessage);
throw error;
}
}