Skip to content

Commit 0e4109b

Browse files
committed
refactor: refactor bundleWorkflowService to mainController
1 parent faaf337 commit 0e4109b

File tree

10 files changed

+48
-47
lines changed

10 files changed

+48
-47
lines changed

lib/bootstrap.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ $injector.require("deviceInstallationService", "./services/device/device-install
4545
$injector.require("deviceRefreshApplicationService", "./services/device/device-refresh-application-service");
4646

4747
$injector.require("workflowDataService", "./services/workflow/workflow-data-service");
48-
$injector.require("bundleWorkflowService", "./services/bundle-workflow-service");
48+
49+
$injector.require("mainController", "./controllers/main-controller");
50+
$injector.require("runOnDeviceController", "./controllers/run-on-device");
4951

5052
$injector.require("buildArtefactsService", "./services/build-artefacts-service");
5153

lib/commands/build.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE, AndroidAppBundleMessages } from "../constants";
22
import { ValidatePlatformCommandBase } from "./command-base";
3-
import { BundleWorkflowService } from "../services/bundle-workflow-service";
3+
import { MainController } from "../controllers/main-controller";
44

55
export abstract class BuildCommandBase extends ValidatePlatformCommandBase {
66
constructor($options: IOptions,
77
protected $errors: IErrors,
88
$projectData: IProjectData,
99
$platformsData: IPlatformsData,
1010
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
11-
protected $bundleWorkflowService: BundleWorkflowService,
11+
protected $mainController: MainController,
1212
$platformValidationService: IPlatformValidationService,
1313
private $bundleValidatorHelper: IBundleValidatorHelper,
1414
protected $logger: ILogger) {
@@ -18,7 +18,7 @@ export abstract class BuildCommandBase extends ValidatePlatformCommandBase {
1818

1919
public async executeCore(args: string[]): Promise<string> {
2020
const platform = args[0].toLowerCase();
21-
const outputPath = await this.$bundleWorkflowService.buildPlatform(platform, this.$projectData.projectDir, this.$options);
21+
const outputPath = await this.$mainController.buildPlatform(platform, this.$projectData.projectDir, this.$options);
2222

2323
return outputPath;
2424
}
@@ -57,11 +57,11 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
5757
$projectData: IProjectData,
5858
$platformsData: IPlatformsData,
5959
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
60-
$bundleWorkflowService: BundleWorkflowService,
60+
$mainController: MainController,
6161
$platformValidationService: IPlatformValidationService,
6262
$bundleValidatorHelper: IBundleValidatorHelper,
6363
$logger: ILogger) {
64-
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $bundleWorkflowService, $platformValidationService, $bundleValidatorHelper, $logger);
64+
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $mainController, $platformValidationService, $bundleValidatorHelper, $logger);
6565
}
6666

6767
public async execute(args: string[]): Promise<void> {
@@ -92,12 +92,12 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
9292
$projectData: IProjectData,
9393
$platformsData: IPlatformsData,
9494
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
95-
$bundleWorkflowService: BundleWorkflowService,
95+
$mainController: MainController,
9696
$platformValidationService: IPlatformValidationService,
9797
$bundleValidatorHelper: IBundleValidatorHelper,
9898
protected $androidBundleValidatorHelper: IAndroidBundleValidatorHelper,
9999
protected $logger: ILogger) {
100-
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $bundleWorkflowService, $platformValidationService, $bundleValidatorHelper, $logger);
100+
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $mainController, $platformValidationService, $bundleValidatorHelper, $logger);
101101
}
102102

103103
public async execute(args: string[]): Promise<void> {

lib/commands/prepare.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { ValidatePlatformCommandBase } from "./command-base";
2-
import { BundleWorkflowService } from "../services/bundle-workflow-service";
2+
import { MainController } from "../controllers/main-controller";
33

44
export class PrepareCommand extends ValidatePlatformCommandBase implements ICommand {
55
public allowedParameters = [this.$platformCommandParameter];
66

77
constructor($options: IOptions,
8-
private $bundleWorkflowService: BundleWorkflowService,
8+
private $mainController: MainController,
99
$platformValidationService: IPlatformValidationService,
1010
$projectData: IProjectData,
1111
private $platformCommandParameter: ICommandParameter,
@@ -17,7 +17,7 @@ export class PrepareCommand extends ValidatePlatformCommandBase implements IComm
1717
public async execute(args: string[]): Promise<void> {
1818
const platform = args[0];
1919

20-
await this.$bundleWorkflowService.preparePlatform(platform, this.$projectData.projectDir, this.$options);
20+
await this.$mainController.preparePlatform(platform, this.$projectData.projectDir, this.$options);
2121
}
2222

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

lib/common/definitions/mobile.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,9 @@ declare module Mobile {
495495
* Returns a single device based on the specified options. If more than one devices are matching,
496496
* prompts the user for a manual choice or returns the first one for non interactive terminals.
497497
*/
498-
pickSingleDevice(options: IPickSingleDeviceOptions): Promise<Mobile.IDevice>
498+
pickSingleDevice(options: IPickSingleDeviceOptions): Promise<Mobile.IDevice>;
499+
500+
getPlatformsFromDeviceDescriptors(deviceDescriptors: ILiveSyncDeviceInfo[]): string[];
499501
}
500502

501503
interface IPickSingleDeviceOptions {

lib/common/mobile/mobile-core/devices-service.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,16 @@ export class DevicesService extends EventEmitter implements Mobile.IDevicesServi
601601
}
602602
}
603603

604+
public getPlatformsFromDeviceDescriptors(deviceDescriptors: ILiveSyncDeviceInfo[]): string[] {
605+
const platforms = _(deviceDescriptors)
606+
.map(device => this.getDeviceByIdentifier(device.identifier))
607+
.map(device => device.deviceInfo.platform)
608+
.uniq()
609+
.value();
610+
611+
return platforms;
612+
}
613+
604614
private async initializeCore(deviceInitOpts?: Mobile.IDevicesServicesInitializationOptions): Promise<void> {
605615
if (this._isInitialized) {
606616
return;
Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { INITIAL_SYNC_EVENT_NAME, FILES_CHANGE_EVENT_NAME, LiveSyncEvents } from "../constants";
2-
import { WorkflowDataService } from "./workflow/workflow-data-service";
3-
import { AddPlatformService } from "./platform/add-platform-service";
4-
import { BuildPlatformService } from "./platform/build-platform-service";
5-
import { PreparePlatformService } from "./platform/prepare-platform-service";
2+
import { WorkflowDataService } from "../services/workflow/workflow-data-service";
3+
import { AddPlatformService } from "../services/platform/add-platform-service";
4+
import { BuildPlatformService } from "../services/platform/build-platform-service";
5+
import { PreparePlatformService } from "../services/platform/prepare-platform-service";
66
import { EventEmitter } from "events";
7-
import { DeviceRefreshApplicationService } from "./device/device-refresh-application-service";
7+
import { DeviceRefreshApplicationService } from "../services/device/device-refresh-application-service";
88

99
const deviceDescriptorPrimaryKey = "identifier";
1010

11-
export class BundleWorkflowService extends EventEmitter implements IBundleWorkflowService {
11+
export class MainController extends EventEmitter {
1212
private liveSyncProcessesInfo: IDictionary<ILiveSyncProcessInfo> = {};
1313

1414
constructor(
@@ -46,7 +46,7 @@ export class BundleWorkflowService extends EventEmitter implements IBundleWorkfl
4646
}
4747

4848
public async deployPlatform(projectDir: string, deviceDescriptors: ILiveSyncDeviceInfo[], liveSyncInfo: ILiveSyncInfo): Promise<void> {
49-
const platforms = this.getPlatformsFromDevices(deviceDescriptors);
49+
const platforms = this.$devicesService.getPlatformsFromDeviceDescriptors(deviceDescriptors);
5050

5151
for (const platform of platforms) {
5252
await this.preparePlatform(platform, projectDir, <any>liveSyncInfo);
@@ -65,7 +65,7 @@ export class BundleWorkflowService extends EventEmitter implements IBundleWorkfl
6565
const projectData = this.$projectDataService.getProjectData(projectDir);
6666
await this.initializeSetup(projectData);
6767

68-
const platforms = this.getPlatformsFromDevices(deviceDescriptors);
68+
const platforms = this.$devicesService.getPlatformsFromDeviceDescriptors(deviceDescriptors);
6969

7070
for (const platform of platforms) {
7171
const { nativePlatformData, addPlatformData } = this.$workflowDataService.createWorkflowData(platform, projectDir, { ...liveSyncInfo, platformParam: platform });
@@ -267,15 +267,5 @@ export class BundleWorkflowService extends EventEmitter implements IBundleWorkfl
267267

268268
this.$errors.failWithoutHelp(`Invalid platform ${platform}. Supported platforms are: ${this.$mobileHelper.platformNames.join(", ")}`);
269269
}
270-
271-
private getPlatformsFromDevices(deviceDescriptors: ILiveSyncDeviceInfo[]): string[] {
272-
const platforms = _(deviceDescriptors)
273-
.map(device => this.$devicesService.getDeviceByIdentifier(device.identifier))
274-
.map(device => device.deviceInfo.platform)
275-
.uniq()
276-
.value();
277-
278-
return platforms;
279-
}
280270
}
281-
$injector.register("bundleWorkflowService", BundleWorkflowService);
271+
$injector.register("mainController", MainController);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export class RunOnDeviceController {
2+
3+
}
4+
$injector.register("runOnDeviceController", RunOnDeviceController);

lib/declarations.d.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,13 +1027,6 @@ interface INetworkConnectivityValidator {
10271027
validate(): Promise<void>;
10281028
}
10291029

1030-
interface IBundleWorkflowService {
1031-
preparePlatform(platform: string, projectDir: string, options: IOptions): Promise<void>;
1032-
buildPlatform(platform: string, projectDir: string, options: IOptions): Promise<string>;
1033-
deployPlatform(projectDir: string, deviceDescriptors: ILiveSyncDeviceInfo[], liveSyncInfo: ILiveSyncInfo): Promise<void>;
1034-
runPlatform(projectDir: string, deviceDescriptors: ILiveSyncDeviceInfo[], liveSyncInfo: ILiveSyncInfo): Promise<void>;
1035-
}
1036-
10371030
interface IPlatformValidationService {
10381031
/**
10391032
* Ensures the passed platform is a valid one (from the supported ones)

lib/helpers/livesync-command-helper.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { BuildPlatformService } from "../services/platform/build-platform-service";
2+
import { MainController } from "../controllers/main-controller";
23

34
// import { LiveSyncEvents } from "../constants";
45

@@ -8,7 +9,7 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
89
constructor(
910
private $projectData: IProjectData,
1011
private $options: IOptions,
11-
private $bundleWorkflowService: IBundleWorkflowService,
12+
private $mainController: MainController,
1213
private $iosDeviceOperations: IIOSDeviceOperations,
1314
private $mobileHelper: Mobile.IMobileHelper,
1415
private $devicesService: Mobile.IDevicesService,
@@ -132,7 +133,7 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
132133
// return;
133134
// }
134135

135-
await this.$bundleWorkflowService.runPlatform(this.$projectData.projectDir, deviceDescriptors, liveSyncInfo);
136+
await this.$mainController.runPlatform(this.$projectData.projectDir, deviceDescriptors, liveSyncInfo);
136137

137138
// const remainingDevicesToSync = devices.map(d => d.deviceInfo.identifier);
138139
// this.$liveSyncService.on(LiveSyncEvents.liveSyncStopped, (data: { projectDir: string, deviceIdentifier: string }) => {

test/services/bundle-workflow-service.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Yok } from "../../lib/common/yok";
2-
import { BundleWorkflowService } from "../../lib/services/bundle-workflow-service";
32
import { assert } from "chai";
43
import { AddPlatformService } from "../../lib/services/platform/add-platform-service";
4+
import { MainController } from "../../lib/controllers/main-controller";
55

66
const deviceMap: IDictionary<any> = {
77
myiOSDevice: {
@@ -42,7 +42,7 @@ function createTestInjector(): IInjector {
4242
emit: () => ({}),
4343
startWatcher: () => ({})
4444
}));
45-
injector.register("bundleWorkflowService", BundleWorkflowService);
45+
injector.register("mainController", MainController);
4646
injector.register("pluginsService", ({}));
4747
injector.register("projectDataService", ({
4848
getProjectData: () => ({
@@ -55,7 +55,6 @@ function createTestInjector(): IInjector {
5555
injector.register("platformService", ({}));
5656
injector.register("projectChangesService", ({}));
5757
injector.register("fs", ({}));
58-
injector.register("bundleWorkflowService", BundleWorkflowService);
5958

6059
return injector;
6160
}
@@ -75,7 +74,7 @@ const liveSyncInfo = {
7574
}
7675
};
7776

78-
describe("BundleWorkflowService", () => {
77+
describe("MainController", () => {
7978
describe("start", () => {
8079
describe("when the run on device is called for second time for the same projectDir", () => {
8180
it("should run only for new devies (for which the initial sync is still not executed)", async () => {
@@ -101,8 +100,8 @@ describe("BundleWorkflowService", () => {
101100
return true;
102101
};
103102

104-
const bundleWorkflowService: IBundleWorkflowService = injector.resolve("bundleWorkflowService");
105-
await bundleWorkflowService.runPlatform(projectDir, [iOSDeviceDescriptor], liveSyncInfo);
103+
const mainController: MainController = injector.resolve("mainController");
104+
await mainController.runPlatform(projectDir, [iOSDeviceDescriptor], liveSyncInfo);
106105

107106
assert.isTrue(isStartWatcherCalled);
108107
});
@@ -130,7 +129,7 @@ describe("BundleWorkflowService", () => {
130129
const injector = createTestInjector();
131130

132131
const actualAddedPlatforms: IPlatformData[] = [];
133-
const platformAddService: AddPlatformService = injector.resolve("bundleWorkflowService");
132+
const platformAddService: AddPlatformService = injector.resolve("platformAddService");
134133
platformAddService.addPlatformIfNeeded = async (platformData: IPlatformData) => {
135134
actualAddedPlatforms.push(platformData);
136135
};

0 commit comments

Comments
 (0)