-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathlivesync-command-helper.ts
165 lines (142 loc) · 6.55 KB
/
livesync-command-helper.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
constructor(private $platformService: IPlatformService,
private $projectData: IProjectData,
private $options: IOptions,
private $liveSyncService: ILiveSyncService,
private $iosDeviceOperations: IIOSDeviceOperations,
private $mobileHelper: Mobile.IMobileHelper,
private $devicesService: Mobile.IDevicesService,
private $platformsData: IPlatformsData,
private $analyticsService: IAnalyticsService,
private $bundleValidatorHelper: IBundleValidatorHelper,
private $errors: IErrors,
private $iOSSimulatorLogProvider: Mobile.IiOSSimulatorLogProvider) {
this.$analyticsService.setShouldDispose(this.$options.justlaunch || !this.$options.watch);
}
public getPlatformsForOperation(platform: string): string[] {
const availablePlatforms = platform ? [platform] : _.values<string>(this.$platformsData.availablePlatforms);
return availablePlatforms;
}
public async executeCommandLiveSync(platform?: string, additionalOptions?: ILiveSyncCommandHelperAdditionalOptions) {
const emulator = this.$options.emulator;
await this.$devicesService.initialize({
deviceId: this.$options.device,
platform,
emulator,
skipDeviceDetectionInterval: true,
skipInferPlatform: !platform,
sdk: this.$options.sdk
});
const devices = this.$devicesService.getDeviceInstances()
.filter(d => !platform || d.deviceInfo.platform.toLowerCase() === platform.toLowerCase());
const devicesPlatforms = _(devices).map(d => d.deviceInfo.platform).uniq().value();
if (this.$options.bundle && devicesPlatforms.length > 1) {
this.$errors.failWithoutHelp("Bundling doesn't work with multiple platforms. Please specify platform to the run command.");
}
await this.executeLiveSyncOperation(devices, platform, additionalOptions);
}
public async executeLiveSyncOperation(devices: Mobile.IDevice[], platform: string, additionalOptions?: ILiveSyncCommandHelperAdditionalOptions): Promise<void> {
if (!devices || !devices.length) {
if (platform) {
this.$errors.failWithoutHelp("Unable to find applicable devices to execute operation. Ensure connected devices are trusted and try again.");
} else {
this.$errors.failWithoutHelp("Unable to find applicable devices to execute operation and unable to start emulator when platform is not specified.");
}
}
const workingWithiOSDevices = !platform || this.$mobileHelper.isiOSPlatform(platform);
const shouldKeepProcessAlive = this.$options.watch || !this.$options.justlaunch;
if (workingWithiOSDevices && shouldKeepProcessAlive) {
this.$iosDeviceOperations.setShouldDispose(false);
this.$iOSSimulatorLogProvider.setShouldDispose(false);
}
if (this.$options.release) {
await this.runInReleaseMode(platform, additionalOptions);
return;
}
// Now let's take data for each device:
const deviceDescriptors: ILiveSyncDeviceInfo[] = devices
.map(d => {
let buildAction: IBuildAction;
const buildConfig: IBuildConfig = {
buildForDevice: !d.isEmulator,
projectDir: this.$options.path,
clean: this.$options.clean,
teamId: this.$options.teamId,
device: this.$options.device,
provision: this.$options.provision,
release: this.$options.release,
keyStoreAlias: this.$options.keyStoreAlias,
keyStorePath: this.$options.keyStorePath,
keyStoreAliasPassword: this.$options.keyStoreAliasPassword,
keyStorePassword: this.$options.keyStorePassword
};
buildAction = additionalOptions && additionalOptions.buildPlatform ?
additionalOptions.buildPlatform.bind(additionalOptions.buildPlatform, d.deviceInfo.platform, buildConfig, this.$projectData) :
this.$platformService.buildPlatform.bind(this.$platformService, d.deviceInfo.platform, buildConfig, this.$projectData);
const info: ILiveSyncDeviceInfo = {
identifier: d.deviceInfo.identifier,
platformSpecificOptions: this.$options,
buildAction,
debugggingEnabled: additionalOptions && additionalOptions.deviceDebugMap && additionalOptions.deviceDebugMap[d.deviceInfo.identifier],
debugOptions: this.$options,
outputPath: additionalOptions && additionalOptions.getOutputDirectory && additionalOptions.getOutputDirectory({
platform: d.deviceInfo.platform,
emulator: d.isEmulator,
projectDir: this.$projectData.projectDir
}),
skipNativePrepare: additionalOptions && additionalOptions.skipNativePrepare
};
return info;
});
const liveSyncInfo: ILiveSyncInfo = {
projectDir: this.$projectData.projectDir,
skipWatcher: !this.$options.watch,
watchAllFiles: this.$options.syncAllFiles,
clean: this.$options.clean,
bundle: !!this.$options.bundle,
release: this.$options.release,
env: this.$options.env,
timeout: this.$options.timeout
};
await this.$liveSyncService.liveSync(deviceDescriptors, liveSyncInfo);
}
public async validatePlatform(platform: string) {
const availablePlatforms = this.getPlatformsForOperation(platform);
for (const availablePlatform of availablePlatforms) {
const platformData = this.$platformsData.getPlatformData(availablePlatform, this.$projectData);
const platformProjectService = platformData.platformProjectService;
await platformProjectService.validate(this.$projectData);
}
this.$bundleValidatorHelper.validate();
}
private async runInReleaseMode(platform: string, additionalOptions?: ILiveSyncCommandHelperAdditionalOptions): Promise<void> {
const runPlatformOptions: IRunPlatformOptions = {
device: this.$options.device,
emulator: this.$options.emulator,
justlaunch: this.$options.justlaunch
};
const deployOptions = _.merge<IDeployPlatformOptions>({
projectDir: this.$projectData.projectDir,
clean: true,
}, this.$options.argv);
const availablePlatforms = this.getPlatformsForOperation(platform);
for (const currentPlatform of availablePlatforms) {
const deployPlatformInfo: IDeployPlatformInfo = {
platform: currentPlatform,
appFilesUpdaterOptions: {
bundle: !!this.$options.bundle,
release: this.$options.release
},
deployOptions,
buildPlatform: this.$platformService.buildPlatform.bind(this.$platformService),
projectData: this.$projectData,
config: this.$options,
env: this.$options.env
};
await this.$platformService.deployPlatform(deployPlatformInfo);
await this.$platformService.startApplication(currentPlatform, runPlatformOptions, { appId: this.$projectData.projectId, projectName: this.$projectData.projectName });
this.$platformService.trackProjectType(this.$projectData);
}
}
}
$injector.register("liveSyncCommandHelper", LiveSyncCommandHelper);