Skip to content

Commit eb52dd9

Browse files
committed
chore: add preparePlatformService and remove platformJSService and platformNativeService
1 parent 68187de commit eb52dd9

31 files changed

+1231
-2227
lines changed

lib/bootstrap.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ $injector.require("tnsModulesService", "./services/tns-modules-service");
3434

3535
$injector.require("platformsData", "./platforms-data");
3636
$injector.require("platformService", "./services/platform-service");
37-
$injector.require("platformJSService", "./services/prepare-platform-js-service");
38-
$injector.require("platformNativeService", "./services/prepare-platform-native-service");
39-
$injector.require("platformAddService", "./services/platform/platform-add-service");
40-
$injector.require("platformBuildService", "./services/platform/platform-build-service");
37+
$injector.require("addPlatformService", "./services/platform/add-platform-service");
38+
$injector.require("buildPlatformService", "./services/platform/build-platform-service");
39+
$injector.require("preparePlatformService", "./services/platform/prepare-platform-service");
4140
$injector.require("platformValidationService", "./services/platform/platform-validation-service");
4241
$injector.require("platformCommandsService", "./services/platform/platform-commands-service");
4342
$injector.require("platformWatcherService", "./services/platform/platform-watcher-service");

lib/commands/appstore-upload.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class PublishIOS implements ICommand {
1414
private $prompter: IPrompter,
1515
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
1616
private $platformValidationService: IPlatformValidationService,
17-
// private $platformBuildService: IPlatformBuildService,
17+
// private $buildPlatformService: BuildPlatformService,
1818
// private $xcodebuildService: IXcodebuildService
1919
) {
2020
this.$projectData.initializeProjectData();

lib/commands/deploy.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,23 @@ export class DeployOnDeviceCommand extends ValidatePlatformCommandBase implement
55
public allowedParameters: ICommandParameter[] = [];
66

77
constructor($platformValidationService: IPlatformValidationService,
8-
private $platformService: IPlatformService,
98
private $platformCommandParameter: ICommandParameter,
109
$options: IOptions,
1110
$projectData: IProjectData,
12-
private $deployCommandHelper: IDeployCommandHelper,
1311
private $errors: IErrors,
1412
private $mobileHelper: Mobile.IMobileHelper,
1513
$platformsData: IPlatformsData,
1614
private $bundleValidatorHelper: IBundleValidatorHelper,
15+
private $liveSyncCommandHelper: ILiveSyncCommandHelper,
1716
private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper) {
1817
super($options, $platformsData, $platformValidationService, $projectData);
1918
this.$projectData.initializeProjectData();
2019
}
2120

2221
public async execute(args: string[]): Promise<void> {
23-
const deployPlatformInfo = this.$deployCommandHelper.getDeployPlatformInfo(args[0]);
24-
25-
return this.$platformService.deployPlatform(deployPlatformInfo);
22+
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 });
2625
}
2726

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

lib/commands/platform-clean.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
import { PlatformCommandsService } from "../services/platform/platform-commands-service";
2+
13
export class CleanCommand implements ICommand {
24
public allowedParameters: ICommandParameter[] = [];
35

46
constructor(
57
private $errors: IErrors,
68
private $options: IOptions,
7-
private $platformCommandsService: IPlatformCommandsService,
9+
private $platformCommandsService: PlatformCommandsService,
810
private $platformValidationService: IPlatformValidationService,
9-
private $platformService: IPlatformService,
1011
private $platformEnvironmentRequirements: IPlatformEnvironmentRequirements,
1112
private $projectData: IProjectData
1213
) {
@@ -29,7 +30,7 @@ export class CleanCommand implements ICommand {
2930
for (const platform of args) {
3031
this.$platformValidationService.validatePlatformInstalled(platform, this.$projectData);
3132

32-
const currentRuntimeVersion = this.$platformService.getCurrentPlatformVersion(platform, this.$projectData);
33+
const currentRuntimeVersion = this.$platformCommandsService.getCurrentPlatformVersion(platform, this.$projectData);
3334
await this.$platformEnvironmentRequirements.checkEnvironmentRequirements({
3435
platform,
3536
projectDir: this.$projectData.projectDir,

lib/declarations.d.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,7 @@ interface INetworkConnectivityValidator {
10301030
interface IBundleWorkflowService {
10311031
preparePlatform(platform: string, projectDir: string, options: IOptions): Promise<void>;
10321032
buildPlatform(platform: string, projectDir: string, options: IOptions): Promise<string>;
1033+
deployPlatform(projectDir: string, deviceDescriptors: ILiveSyncDeviceInfo[], liveSyncInfo: ILiveSyncInfo): Promise<void>;
10331034
runPlatform(projectDir: string, deviceDescriptors: ILiveSyncDeviceInfo[], liveSyncInfo: ILiveSyncInfo): Promise<void>;
10341035
}
10351036

@@ -1063,11 +1064,6 @@ interface IBuildArtefactsService {
10631064
getAllBuiltApplicationPackages(buildOutputPath: string, validBuildOutputData: IValidBuildOutputData): IApplicationPackage[];
10641065
}
10651066

1066-
interface IPlatformAddService {
1067-
addPlatform(projectData: IProjectData, addPlatformData: any): Promise<void>;
1068-
addPlatformIfNeeded(platformData: IPlatformData, projectData: IProjectData, addPlatformData: any): Promise<void>;
1069-
}
1070-
10711067
interface IPlatformCommandsService {
10721068
addPlatforms(platforms: string[], projectData: IProjectData, frameworkPath: string): Promise<void>;
10731069
cleanPlatforms(platforms: string[], projectData: IProjectData, framworkPath: string): Promise<void>;

lib/definitions/livesync.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ declare global {
143143
*/
144144
interface ILiveSyncInfo extends IProjectDir, IRelease, IOptionalSkipWatcher, IHasUseHotModuleReloadOption, IHasSyncToPreviewAppOption {
145145
webpackCompilerConfig: IWebpackCompilerConfig;
146+
emulator?: boolean;
146147

147148
/**
148149
* Forces a build before the initial livesync.

lib/helpers/deploy-command-helper.ts

Lines changed: 0 additions & 45 deletions
This file was deleted.

lib/helpers/livesync-command-helper.ts

Lines changed: 15 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
1+
import { BuildPlatformService } from "../services/platform/build-platform-service";
2+
13
// import { LiveSyncEvents } from "../constants";
24

35
export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
46
public static MIN_SUPPORTED_WEBPACK_VERSION_WITH_HMR = "0.17.0";
57

6-
constructor(private $platformService: IPlatformService,
8+
constructor(
79
private $projectData: IProjectData,
810
private $options: IOptions,
911
private $bundleWorkflowService: IBundleWorkflowService,
10-
// private $liveSyncService: ILiveSyncService,
1112
private $iosDeviceOperations: IIOSDeviceOperations,
1213
private $mobileHelper: Mobile.IMobileHelper,
1314
private $devicesService: Mobile.IDevicesService,
1415
private $platformsData: IPlatformsData,
16+
private $buildPlatformService: BuildPlatformService,
1517
private $analyticsService: IAnalyticsService,
1618
private $bundleValidatorHelper: IBundleValidatorHelper,
1719
private $errors: IErrors,
1820
private $iOSSimulatorLogProvider: Mobile.IiOSSimulatorLogProvider,
1921
private $logger: ILogger,
20-
private $cleanupService: ICleanupService) {
21-
}
22+
private $cleanupService: ICleanupService
23+
) { }
2224

2325
public getPlatformsForOperation(platform: string): string[] {
2426
const availablePlatforms = platform ? [platform] : _.values<string>(this.$platformsData.availablePlatforms);
@@ -70,11 +72,6 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
7072
}
7173
}
7274

73-
if (this.$options.release) {
74-
await this.runInReleaseMode(platform, additionalOptions);
75-
return;
76-
}
77-
7875
// Now let's take data for each device:
7976
const deviceDescriptors: ILiveSyncDeviceInfo[] = devices
8077
.map(d => {
@@ -95,7 +92,7 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
9592

9693
const buildAction = additionalOptions && additionalOptions.buildPlatform ?
9794
additionalOptions.buildPlatform.bind(additionalOptions.buildPlatform, d.deviceInfo.platform, buildConfig, this.$projectData) :
98-
this.$platformService.buildPlatform.bind(this.$platformService, d.deviceInfo.platform, buildConfig, this.$projectData);
95+
this.$buildPlatformService.buildPlatform.bind(this.$buildPlatformService, d.deviceInfo.platform, buildConfig, this.$projectData);
9996

10097
const outputPath = additionalOptions && additionalOptions.getOutputDirectory && additionalOptions.getOutputDirectory({
10198
platform: d.deviceInfo.platform,
@@ -125,9 +122,16 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
125122
},
126123
timeout: this.$options.timeout,
127124
useHotModuleReload: this.$options.hmr,
128-
force: this.$options.force
125+
force: this.$options.force,
126+
emulator: this.$options.emulator
129127
};
130128

129+
// if (this.$options.release) {
130+
// liveSyncInfo.skipWatcher = true;
131+
// await this.$bundleWorkflowService.deployPlatform(this.$projectData.projectDir, deviceDescriptors, liveSyncInfo);
132+
// return;
133+
// }
134+
131135
await this.$bundleWorkflowService.runPlatform(this.$projectData.projectDir, deviceDescriptors, liveSyncInfo);
132136

133137
// const remainingDevicesToSync = devices.map(d => d.deviceInfo.identifier);
@@ -158,47 +162,6 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
158162

159163
return result;
160164
}
161-
162-
private async runInReleaseMode(platform: string, additionalOptions?: ILiveSyncCommandHelperAdditionalOptions): Promise<void> {
163-
const runPlatformOptions: IRunPlatformOptions = {
164-
device: this.$options.device,
165-
emulator: this.$options.emulator,
166-
justlaunch: this.$options.justlaunch
167-
};
168-
169-
const deployOptions = _.merge<IDeployPlatformOptions, IYargArgv>((<IDeployPlatformOptions>{
170-
projectDir: this.$projectData.projectDir,
171-
clean: true
172-
}), this.$options.argv);
173-
174-
const availablePlatforms = this.getPlatformsForOperation(platform);
175-
for (const currentPlatform of availablePlatforms) {
176-
const deployPlatformInfo: IDeployPlatformInfo = {
177-
platform: currentPlatform,
178-
appFilesUpdaterOptions: {
179-
bundle: !!this.$options.bundle,
180-
release: this.$options.release,
181-
useHotModuleReload: this.$options.hmr
182-
},
183-
deployOptions,
184-
buildPlatform: this.$platformService.buildPlatform.bind(this.$platformService),
185-
projectData: this.$projectData,
186-
config: <any>this.$options,
187-
env: this.$options.env
188-
};
189-
190-
await this.$platformService.deployPlatform(deployPlatformInfo);
191-
192-
await this.$platformService.startApplication(
193-
currentPlatform,
194-
runPlatformOptions,
195-
{
196-
appId: this.$projectData.projectIdentifiers[currentPlatform.toLowerCase()],
197-
projectName: this.$projectData.projectName
198-
}
199-
);
200-
}
201-
}
202165
}
203166

204167
$injector.register("liveSyncCommandHelper", LiveSyncCommandHelper);

lib/services/android-plugin-build-service.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { getShortPluginName, hook } from "../common/helpers";
44
import { Builder, parseString } from "xml2js";
55

66
export class AndroidPluginBuildService implements IAndroidPluginBuildService {
7-
private get $platformService(): IPlatformService {
8-
return this.$injector.resolve("platformService");
7+
private get $platformsData(): IPlatformsData {
8+
return this.$injector.resolve("platformsData");
99
}
1010

11-
constructor(private $injector: IInjector,
11+
constructor(
1212
private $fs: IFileSystem,
1313
private $childProcess: IChildProcess,
1414
private $hostInfo: IHostInfo,
@@ -19,7 +19,9 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
1919
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
2020
private $errors: IErrors,
2121
private $filesHashService: IFilesHashService,
22-
public $hooksService: IHooksService) { }
22+
public $hooksService: IHooksService,
23+
private $injector: IInjector
24+
) { }
2325

2426
private static MANIFEST_ROOT = {
2527
$: {
@@ -290,10 +292,9 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
290292
private async getRuntimeGradleVersions(projectDir: string): Promise<IRuntimeGradleVersions> {
291293
let runtimeGradleVersions: IRuntimeGradleVersions = null;
292294
if (projectDir) {
293-
const projectRuntimeVersion = this.$platformService.getCurrentPlatformVersion(
294-
this.$devicePlatformsConstants.Android,
295-
this.$projectDataService.getProjectData(projectDir));
296-
runtimeGradleVersions = await this.getGradleVersions(projectRuntimeVersion);
295+
const projectData = this.$projectDataService.getProjectData(projectDir);
296+
const platformData = this.$platformsData.getPlatformData(this.$devicePlatformsConstants.Android, projectData);
297+
const projectRuntimeVersion = platformData.platformProjectService.getFrameworkVersion(projectData);
297298
this.$logger.trace(`Got gradle versions ${JSON.stringify(runtimeGradleVersions)} from runtime v${projectRuntimeVersion}`);
298299
}
299300

0 commit comments

Comments
 (0)