This repository has been archived by the owner on Jan 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 477
/
context.ts
60 lines (53 loc) · 1.5 KB
/
context.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { readConfigJsonAsync } from '@expo/config';
import { ApiV2, Doctor, User, UserManager } from '@expo/xdl';
import { AppleCtx, authenticate } from '../appleApi';
import { IosApi } from './api';
export interface IView {
open(ctx: Context): Promise<IView | null>;
}
export class Context {
_hasProjectContext: boolean = false;
_user?: User;
_manifest: any;
_apiClient?: ApiV2;
_iosApiClient?: IosApi;
_appleCtx?: AppleCtx;
get user(): User {
return this._user as User;
}
get hasProjectContext(): boolean {
return this._hasProjectContext;
}
get manifest(): any {
return this._manifest;
}
get api(): ApiV2 {
return this._apiClient as ApiV2;
}
get ios(): IosApi {
return this._iosApiClient as IosApi;
}
get appleCtx(): AppleCtx {
if (!this._appleCtx) {
throw new Error('Apple context not initialized.');
}
return this._appleCtx;
}
async ensureAppleCtx() {
if (!this._appleCtx) {
this._appleCtx = await authenticate();
}
}
async init(projectDir: string) {
const status = await Doctor.validateWithoutNetworkAsync(projectDir);
if (status !== Doctor.FATAL) {
/* This manager does not need to work in project context */
const { exp } = await readConfigJsonAsync(projectDir);
this._manifest = exp;
this._hasProjectContext = true;
}
this._user = await UserManager.ensureLoggedInAsync();
this._apiClient = ApiV2.clientForUser(this.user);
this._iosApiClient = new IosApi(this._user);
}
}