Skip to content

Commit e85daf7

Browse files
committed
fix: fix deploy command
1 parent 042a043 commit e85daf7

File tree

3 files changed

+161
-89
lines changed

3 files changed

+161
-89
lines changed

lib/commands/deploy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE } from "../constants";
22
import { ValidatePlatformCommandBase } from "./command-base";
3+
import { DeployCommandHelper } from "../helpers/deploy-command-helper";
34

45
export class DeployOnDeviceCommand extends ValidatePlatformCommandBase implements ICommand {
56
public allowedParameters: ICommandParameter[] = [];
@@ -12,16 +13,15 @@ export class DeployOnDeviceCommand extends ValidatePlatformCommandBase implement
1213
private $mobileHelper: Mobile.IMobileHelper,
1314
$platformsData: IPlatformsData,
1415
private $bundleValidatorHelper: IBundleValidatorHelper,
15-
private $liveSyncCommandHelper: ILiveSyncCommandHelper,
16+
private $deployCommandHelper: DeployCommandHelper,
1617
private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper) {
1718
super($options, $platformsData, $platformValidationService, $projectData);
1819
this.$projectData.initializeProjectData();
1920
}
2021

2122
public async execute(args: string[]): Promise<void> {
2223
const platform = args[0].toLowerCase();
23-
// TODO: Add a separate deployCommandHelper with base class for it and LiveSyncCommandHelper
24-
await this.$liveSyncCommandHelper.executeCommandLiveSync(platform, <any>{ release: true });
24+
await this.$deployCommandHelper.deploy(platform, <any>{ release: true });
2525
}
2626

2727
public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {

lib/controllers/run-on-devices-controller.ts

Lines changed: 78 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -26,114 +26,106 @@ export class RunOnDevicesController extends EventEmitter {
2626
) { super(); }
2727

2828
public async syncInitialDataOnDevice(data: IInitialSyncEventData, projectData: IProjectData, liveSyncInfo: ILiveSyncInfo, deviceDescriptors: ILiveSyncDeviceInfo[]): Promise<void> {
29-
const executeAction = async (device: Mobile.IDevice) => {
29+
const deviceAction = async (device: Mobile.IDevice) => {
3030
const deviceDescriptor = _.find(deviceDescriptors, dd => dd.identifier === device.deviceInfo.identifier);
31-
await this.syncInitialDataOnDeviceSafe(device, deviceDescriptor, projectData, liveSyncInfo);
32-
};
33-
const canExecuteAction = (device: Mobile.IDevice) => device.deviceInfo.platform.toLowerCase() === data.platform.toLowerCase() && _.some(deviceDescriptors, deviceDescriptor => deviceDescriptor.identifier === device.deviceInfo.identifier);
34-
await this.addActionToChain(projectData.projectDir, () => this.$devicesService.execute(executeAction, canExecuteAction));
35-
}
36-
37-
public async syncChangedDataOnDevice(data: IFilesChangeEventData, projectData: IProjectData, liveSyncInfo: ILiveSyncInfo, deviceDescriptors: ILiveSyncDeviceInfo[]): Promise<void> {
38-
const executeAction = async (device: Mobile.IDevice) => {
39-
const deviceDescriptor = _.find(deviceDescriptors, dd => dd.identifier === device.deviceInfo.identifier);
40-
await this.syncChangedDataOnDeviceSafe(device, deviceDescriptor, data, projectData, liveSyncInfo);
41-
};
42-
const canExecuteAction = (device: Mobile.IDevice) => {
43-
const liveSyncProcessInfo = this.$runOnDevicesDataService.getData(projectData.projectDir);
44-
return (data.platform.toLowerCase() === device.deviceInfo.platform.toLowerCase()) && liveSyncProcessInfo && _.some(liveSyncProcessInfo.deviceDescriptors, deviceDescriptor => deviceDescriptor.identifier === device.deviceInfo.identifier);
45-
};
46-
await this.addActionToChain(projectData.projectDir, () => this.$devicesService.execute(executeAction, canExecuteAction));
47-
}
31+
const { nativePlatformData: platformData, buildPlatformData } = this.$workflowDataService.createWorkflowData(device.deviceInfo.platform, projectData.projectDir, liveSyncInfo);
4832

49-
private async syncInitialDataOnDeviceSafe(device: Mobile.IDevice, deviceDescriptor: ILiveSyncDeviceInfo, projectData: IProjectData, liveSyncInfo: ILiveSyncInfo): Promise<void> {
50-
const { nativePlatformData: platformData, buildPlatformData } = this.$workflowDataService.createWorkflowData(device.deviceInfo.platform, projectData.projectDir, liveSyncInfo);
33+
try {
34+
const outputPath = deviceDescriptor.outputPath || platformData.getBuildOutputPath(buildPlatformData);
35+
const packageFilePath = await this.$buildPlatformService.buildPlatformIfNeeded(platformData, projectData, buildPlatformData, outputPath);
5136

52-
try {
53-
const outputPath = deviceDescriptor.outputPath || platformData.getBuildOutputPath(buildPlatformData);
54-
const packageFilePath = await this.$buildPlatformService.buildPlatformIfNeeded(platformData, projectData, buildPlatformData, outputPath);
37+
await this.$deviceInstallAppService.installOnDeviceIfNeeded(device, platformData, projectData, buildPlatformData, packageFilePath, outputPath);
5538

56-
await this.$deviceInstallAppService.installOnDeviceIfNeeded(device, platformData, projectData, buildPlatformData, packageFilePath, outputPath);
39+
const platformLiveSyncService = this.$liveSyncServiceResolver.resolveLiveSyncService(platformData.platformNameLowerCase);
40+
const { force, useHotModuleReload, skipWatcher } = liveSyncInfo;
41+
const liveSyncResultInfo = await platformLiveSyncService.fullSync({ force, useHotModuleReload, projectData, device, watch: !skipWatcher, liveSyncDeviceInfo: deviceDescriptor });
5742

58-
const platformLiveSyncService = this.$liveSyncServiceResolver.resolveLiveSyncService(platformData.platformNameLowerCase);
59-
const { force, useHotModuleReload, skipWatcher } = liveSyncInfo;
60-
const liveSyncResultInfo = await platformLiveSyncService.fullSync({ force, useHotModuleReload, projectData, device, watch: !skipWatcher, liveSyncDeviceInfo: deviceDescriptor });
43+
const refreshInfo = await this.$deviceRefreshAppService.refreshApplicationWithoutDebug(projectData, liveSyncResultInfo, deviceDescriptor);
6144

62-
const refreshInfo = await this.$deviceRefreshAppService.refreshApplicationWithoutDebug(projectData, liveSyncResultInfo, deviceDescriptor);
45+
this.$runOnDevicesEmitter.emitRunOnDeviceExecutedEvent(projectData, liveSyncResultInfo.deviceAppData.device, {
46+
syncedFiles: liveSyncResultInfo.modifiedFilesData.map(m => m.getLocalPath()),
47+
isFullSync: liveSyncResultInfo.isFullSync
48+
});
6349

64-
this.$runOnDevicesEmitter.emitRunOnDeviceExecutedEvent(projectData, liveSyncResultInfo.deviceAppData.device, {
65-
syncedFiles: liveSyncResultInfo.modifiedFilesData.map(m => m.getLocalPath()),
66-
isFullSync: liveSyncResultInfo.isFullSync
67-
});
50+
if (liveSyncResultInfo && deviceDescriptor.debugggingEnabled) {
51+
await this.$deviceDebugAppService.enableDebugging(projectData, deviceDescriptor, refreshInfo);
52+
}
6853

69-
if (liveSyncResultInfo && deviceDescriptor.debugggingEnabled) {
70-
await this.$deviceDebugAppService.enableDebugging(projectData, deviceDescriptor, refreshInfo);
71-
}
54+
this.$logger.info(`Successfully synced application ${liveSyncResultInfo.deviceAppData.appIdentifier} on device ${liveSyncResultInfo.deviceAppData.device.deviceInfo.identifier}.`);
7255

73-
this.$logger.info(`Successfully synced application ${liveSyncResultInfo.deviceAppData.appIdentifier} on device ${liveSyncResultInfo.deviceAppData.device.deviceInfo.identifier}.`);
56+
this.$runOnDevicesEmitter.emitRunOnDeviceStartedEvent(projectData, device);
57+
} catch (err) {
58+
this.$logger.warn(`Unable to apply changes on device: ${device.deviceInfo.identifier}. Error is: ${err.message}.`);
7459

75-
this.$runOnDevicesEmitter.emitRunOnDeviceStartedEvent(projectData, device);
76-
} catch (err) {
77-
this.$logger.warn(`Unable to apply changes on device: ${device.deviceInfo.identifier}. Error is: ${err.message}.`);
60+
this.$runOnDevicesEmitter.emitRunOnDeviceErrorEvent(projectData, device, err);
7861

79-
this.$runOnDevicesEmitter.emitRunOnDeviceErrorEvent(projectData, device, err);
62+
// TODO: Consider to call here directly stopRunOnDevices
63+
}
64+
};
8065

81-
// TODO: Consider to call here directly stopRunOnDevices
82-
}
66+
await this.addActionToChain(projectData.projectDir, () => this.$devicesService.execute(deviceAction, (device: Mobile.IDevice) => device.deviceInfo.platform.toLowerCase() === data.platform.toLowerCase() && _.some(deviceDescriptors, deviceDescriptor => deviceDescriptor.identifier === device.deviceInfo.identifier)));
8367
}
8468

85-
private async syncChangedDataOnDeviceSafe(device: Mobile.IDevice, deviceDescriptor: ILiveSyncDeviceInfo, data: IFilesChangeEventData, projectData: IProjectData, liveSyncInfo: ILiveSyncInfo): Promise<void> {
86-
const { nativePlatformData, buildPlatformData } = this.$workflowDataService.createWorkflowData(device.deviceInfo.platform, projectData.projectDir, liveSyncInfo);
69+
public async syncChangedDataOnDevice(data: IFilesChangeEventData, projectData: IProjectData, liveSyncInfo: ILiveSyncInfo, deviceDescriptors: ILiveSyncDeviceInfo[]): Promise<void> {
70+
const deviceAction = async (device: Mobile.IDevice) => {
71+
const deviceDescriptor = _.find(deviceDescriptors, dd => dd.identifier === device.deviceInfo.identifier);
72+
const { nativePlatformData, buildPlatformData } = this.$workflowDataService.createWorkflowData(device.deviceInfo.platform, projectData.projectDir, liveSyncInfo);
8773

88-
try {
89-
if (data.hasNativeChanges) {
90-
// TODO: Consider to handle nativePluginsChange here (aar rebuilt)
91-
await this.$buildPlatformService.buildPlatform(nativePlatformData, projectData, buildPlatformData);
92-
}
74+
try {
75+
if (data.hasNativeChanges) {
76+
// TODO: Consider to handle nativePluginsChange here (aar rebuilt)
77+
await this.$buildPlatformService.buildPlatform(nativePlatformData, projectData, buildPlatformData);
78+
}
9379

94-
const isInHMRMode = liveSyncInfo.useHotModuleReload && data.hmrData && data.hmrData.hash;
95-
if (isInHMRMode) {
96-
this.$hmrStatusService.watchHmrStatus(device.deviceInfo.identifier, data.hmrData.hash);
97-
}
80+
const isInHMRMode = liveSyncInfo.useHotModuleReload && data.hmrData && data.hmrData.hash;
81+
if (isInHMRMode) {
82+
this.$hmrStatusService.watchHmrStatus(device.deviceInfo.identifier, data.hmrData.hash);
83+
}
9884

99-
const platformLiveSyncService = this.$liveSyncServiceResolver.resolveLiveSyncService(device.deviceInfo.platform);
100-
const watchInfo = {
101-
liveSyncDeviceInfo: deviceDescriptor,
102-
projectData,
103-
filesToRemove: <any>[],
104-
filesToSync: data.files,
105-
isReinstalled: false,
106-
hmrData: data.hmrData,
107-
useHotModuleReload: liveSyncInfo.useHotModuleReload,
108-
force: liveSyncInfo.force,
109-
connectTimeout: 1000
110-
};
111-
let liveSyncResultInfo = await platformLiveSyncService.liveSyncWatchAction(device, watchInfo);
112-
113-
await this.refreshApplication(projectData, liveSyncResultInfo, deviceDescriptor);
114-
115-
if (!liveSyncResultInfo.didRecover && isInHMRMode) {
116-
const status = await this.$hmrStatusService.getHmrStatus(device.deviceInfo.identifier, data.hmrData.hash);
117-
if (status === HmrConstants.HMR_ERROR_STATUS) {
118-
watchInfo.filesToSync = data.hmrData.fallbackFiles;
119-
liveSyncResultInfo = await platformLiveSyncService.liveSyncWatchAction(device, watchInfo);
120-
// We want to force a restart of the application.
121-
liveSyncResultInfo.isFullSync = true;
122-
await this.refreshApplication(projectData, liveSyncResultInfo, deviceDescriptor);
85+
const platformLiveSyncService = this.$liveSyncServiceResolver.resolveLiveSyncService(device.deviceInfo.platform);
86+
const watchInfo = {
87+
liveSyncDeviceInfo: deviceDescriptor,
88+
projectData,
89+
filesToRemove: <any>[],
90+
filesToSync: data.files,
91+
isReinstalled: false,
92+
hmrData: data.hmrData,
93+
useHotModuleReload: liveSyncInfo.useHotModuleReload,
94+
force: liveSyncInfo.force,
95+
connectTimeout: 1000
96+
};
97+
let liveSyncResultInfo = await platformLiveSyncService.liveSyncWatchAction(device, watchInfo);
98+
99+
await this.refreshApplication(projectData, liveSyncResultInfo, deviceDescriptor);
100+
101+
if (!liveSyncResultInfo.didRecover && isInHMRMode) {
102+
const status = await this.$hmrStatusService.getHmrStatus(device.deviceInfo.identifier, data.hmrData.hash);
103+
if (status === HmrConstants.HMR_ERROR_STATUS) {
104+
watchInfo.filesToSync = data.hmrData.fallbackFiles;
105+
liveSyncResultInfo = await platformLiveSyncService.liveSyncWatchAction(device, watchInfo);
106+
// We want to force a restart of the application.
107+
liveSyncResultInfo.isFullSync = true;
108+
await this.refreshApplication(projectData, liveSyncResultInfo, deviceDescriptor);
109+
}
123110
}
124-
}
125111

126-
this.$logger.info(`Successfully synced application ${liveSyncResultInfo.deviceAppData.appIdentifier} on device ${liveSyncResultInfo.deviceAppData.device.deviceInfo.identifier}.`);
127-
} catch (err) {
128-
const allErrors = (<Mobile.IDevicesOperationError>err).allErrors;
112+
this.$logger.info(`Successfully synced application ${liveSyncResultInfo.deviceAppData.appIdentifier} on device ${liveSyncResultInfo.deviceAppData.device.deviceInfo.identifier}.`);
113+
} catch (err) {
114+
const allErrors = (<Mobile.IDevicesOperationError>err).allErrors;
129115

130-
if (allErrors && _.isArray(allErrors)) {
131-
for (const deviceError of allErrors) {
132-
this.$logger.warn(`Unable to apply changes for device: ${deviceError.deviceIdentifier}. Error is: ${deviceError.message}.`);
133-
this.$runOnDevicesEmitter.emitRunOnDeviceErrorEvent(projectData, device, deviceError);
116+
if (allErrors && _.isArray(allErrors)) {
117+
for (const deviceError of allErrors) {
118+
this.$logger.warn(`Unable to apply changes for device: ${deviceError.deviceIdentifier}. Error is: ${deviceError.message}.`);
119+
this.$runOnDevicesEmitter.emitRunOnDeviceErrorEvent(projectData, device, deviceError);
120+
}
134121
}
135122
}
136-
}
123+
};
124+
125+
await this.addActionToChain(projectData.projectDir, () => this.$devicesService.execute(deviceAction, (device: Mobile.IDevice) => {
126+
const liveSyncProcessInfo = this.$runOnDevicesDataService.getData(projectData.projectDir);
127+
return (data.platform.toLowerCase() === device.deviceInfo.platform.toLowerCase()) && liveSyncProcessInfo && _.some(liveSyncProcessInfo.deviceDescriptors, deviceDescriptor => deviceDescriptor.identifier === device.deviceInfo.identifier);
128+
}));
137129
}
138130

139131
private async refreshApplication(projectData: IProjectData, liveSyncResultInfo: ILiveSyncResultInfo, deviceDescriptor: ILiveSyncDeviceInfo) {
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { BuildPlatformService } from "../services/platform/build-platform-service";
2+
import { MainController } from "../controllers/main-controller";
3+
4+
export class DeployCommandHelper {
5+
constructor(
6+
private $buildPlatformService: BuildPlatformService,
7+
private $devicesService: Mobile.IDevicesService,
8+
private $mainController: MainController,
9+
private $options: IOptions,
10+
private $projectData: IProjectData
11+
) { }
12+
13+
public async deploy(platform: string, additionalOptions?: ILiveSyncCommandHelperAdditionalOptions) {
14+
const emulator = this.$options.emulator;
15+
await this.$devicesService.initialize({
16+
deviceId: this.$options.device,
17+
platform,
18+
emulator,
19+
skipInferPlatform: !platform,
20+
sdk: this.$options.sdk
21+
});
22+
23+
const devices = this.$devicesService.getDeviceInstances()
24+
.filter(d => !platform || d.deviceInfo.platform.toLowerCase() === platform.toLowerCase());
25+
26+
const deviceDescriptors: ILiveSyncDeviceInfo[] = devices
27+
.map(d => {
28+
const buildConfig: IBuildConfig = {
29+
buildForDevice: !d.isEmulator,
30+
iCloudContainerEnvironment: this.$options.iCloudContainerEnvironment,
31+
projectDir: this.$options.path,
32+
clean: this.$options.clean,
33+
teamId: this.$options.teamId,
34+
device: this.$options.device,
35+
provision: this.$options.provision,
36+
release: this.$options.release,
37+
keyStoreAlias: this.$options.keyStoreAlias,
38+
keyStorePath: this.$options.keyStorePath,
39+
keyStoreAliasPassword: this.$options.keyStoreAliasPassword,
40+
keyStorePassword: this.$options.keyStorePassword
41+
};
42+
43+
const buildAction = additionalOptions && additionalOptions.buildPlatform ?
44+
additionalOptions.buildPlatform.bind(additionalOptions.buildPlatform, d.deviceInfo.platform, buildConfig, this.$projectData) :
45+
this.$buildPlatformService.buildPlatform.bind(this.$buildPlatformService, d.deviceInfo.platform, buildConfig, this.$projectData);
46+
47+
const outputPath = additionalOptions && additionalOptions.getOutputDirectory && additionalOptions.getOutputDirectory({
48+
platform: d.deviceInfo.platform,
49+
emulator: d.isEmulator,
50+
projectDir: this.$projectData.projectDir
51+
});
52+
53+
const info: ILiveSyncDeviceInfo = {
54+
identifier: d.deviceInfo.identifier,
55+
buildAction,
56+
debugggingEnabled: additionalOptions && additionalOptions.deviceDebugMap && additionalOptions.deviceDebugMap[d.deviceInfo.identifier],
57+
debugOptions: this.$options,
58+
outputPath,
59+
skipNativePrepare: additionalOptions && additionalOptions.skipNativePrepare,
60+
};
61+
62+
return info;
63+
});
64+
65+
const liveSyncInfo: ILiveSyncInfo = {
66+
projectDir: this.$projectData.projectDir,
67+
skipWatcher: !this.$options.watch,
68+
clean: this.$options.clean,
69+
release: this.$options.release,
70+
env: this.$options.env,
71+
timeout: this.$options.timeout,
72+
useHotModuleReload: this.$options.hmr,
73+
force: this.$options.force,
74+
emulator: this.$options.emulator
75+
};
76+
77+
await this.$mainController.deployOnDevices(this.$projectData.projectDir, deviceDescriptors, liveSyncInfo);
78+
}
79+
}
80+
$injector.register("deployCommandHelper", DeployCommandHelper);

0 commit comments

Comments
 (0)