Skip to content

Commit 2221976

Browse files
authored
refactoring in order to start moving functionality from emulate to run command (#2614)
* rename method * renamed method * removed obsolete code * removed unnecessary code and fixed stubs after renaming * moved --availableDevices option to run command * fixed up wrong inheritance * moved platform specific code to appropriate place * minor updates after review
1 parent 8dedbcd commit 2221976

18 files changed

+72
-61
lines changed

lib/commands/appstore-upload.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class PublishIOS implements ICommand {
5959
// No .ipa path provided, build .ipa on out own.
6060
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
6161
if (mobileProvisionIdentifier || codeSignIdentity) {
62-
let iOSBuildConfig: IiOSBuildConfig = {
62+
let iOSBuildConfig: IBuildConfig = {
6363
projectDir: this.$options.path,
6464
release: this.$options.release,
6565
device: this.$options.device,

lib/commands/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class BuildCommandBase {
1111
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
1212
await this.$platformService.preparePlatform(platform, appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData, { provision: this.$options.provision, sdk: this.$options.sdk });
1313
this.$options.clean = true;
14-
const buildConfig: IiOSBuildConfig = {
14+
const buildConfig: IBuildConfig = {
1515
buildForDevice: this.$options.forDevice,
1616
projectDir: this.$options.path,
1717
clean: this.$options.clean,

lib/commands/run.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@ export class RunCommandBase {
22
constructor(protected $platformService: IPlatformService,
33
protected $usbLiveSyncService: ILiveSyncService,
44
protected $projectData: IProjectData,
5-
protected $options: IOptions) {
5+
protected $options: IOptions,
6+
protected $emulatorPlatformService: IEmulatorPlatformService,
7+
private $mobileHelper: Mobile.IMobileHelper) {
68
this.$projectData.initializeProjectData();
79
}
810

911
public async executeCore(args: string[]): Promise<void> {
12+
13+
if (this.$options.availableDevices) {
14+
return this.$emulatorPlatformService.listAvailableEmulators(this.$mobileHelper.validatePlatformName(args[0]));
15+
}
16+
1017
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
1118
const deployOptions: IDeployPlatformOptions = {
1219
clean: this.$options.clean,
@@ -22,6 +29,7 @@ export class RunCommandBase {
2229
keyStorePassword: this.$options.keyStorePassword,
2330
keyStorePath: this.$options.keyStorePath
2431
};
32+
2533
await this.$platformService.deployPlatform(args[0], appFilesUpdaterOptions, deployOptions, this.$projectData, { provision: this.$options.provision, sdk: this.$options.sdk });
2634

2735
if (this.$options.bundle) {
@@ -35,7 +43,7 @@ export class RunCommandBase {
3543
justlaunch: this.$options.justlaunch,
3644
};
3745

38-
return this.$platformService.runPlatform(args[0], deployOpts, this.$projectData);
46+
return this.$platformService.startApplication(args[0], deployOpts, this.$projectData);
3947
}
4048

4149
return this.$usbLiveSyncService.liveSync(args[0], this.$projectData);
@@ -49,8 +57,10 @@ export class RunIosCommand extends RunCommandBase implements ICommand {
4957
private $platformsData: IPlatformsData,
5058
$usbLiveSyncService: ILiveSyncService,
5159
$projectData: IProjectData,
52-
$options: IOptions) {
53-
super($platformService, $usbLiveSyncService, $projectData, $options);
60+
$options: IOptions,
61+
$emulatorPlatformService: IEmulatorPlatformService,
62+
$mobileHelper: Mobile.IMobileHelper) {
63+
super($platformService, $usbLiveSyncService, $projectData, $options, $emulatorPlatformService, $mobileHelper);
5464
}
5565

5666
public async execute(args: string[]): Promise<void> {
@@ -72,8 +82,10 @@ export class RunAndroidCommand extends RunCommandBase implements ICommand {
7282
$usbLiveSyncService: ILiveSyncService,
7383
$projectData: IProjectData,
7484
$options: IOptions,
85+
$emulatorPlatformService: IEmulatorPlatformService,
86+
$mobileHelper: Mobile.IMobileHelper,
7587
private $errors: IErrors) {
76-
super($platformService, $usbLiveSyncService, $projectData, $options);
88+
super($platformService, $usbLiveSyncService, $projectData, $options, $emulatorPlatformService, $mobileHelper);
7789
}
7890

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

lib/definitions/platform.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ interface IPlatformService extends NodeJS.EventEmitter {
118118
* @param {IProjectData} projectData DTO with information about the project.
119119
* @returns {void}
120120
*/
121-
runPlatform(platform: string, runOptions: IRunPlatformOptions, projectData: IProjectData): Promise<void>;
121+
startApplication(platform: string, runOptions: IRunPlatformOptions, projectData: IProjectData): Promise<void>;
122122

123123
/**
124124
* The emulate command. In addition to `run --emulator` command, it handles the `--available-devices` option to show the available devices.

lib/definitions/plugins.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ interface IPluginsService {
1212
* @returns {IPackageJsonDepedenciesResult}
1313
*/
1414
getDependenciesFromPackageJson(projectDir: string): IPackageJsonDepedenciesResult;
15+
validate(platformData: IPlatformData, projectData: IProjectData): Promise<void>;
1516
}
1617

1718
interface IPackageJsonDepedenciesResult {

lib/definitions/project.d.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ interface IBuildForDevice {
130130
buildForDevice: boolean;
131131
}
132132

133-
interface IBuildConfig extends IAndroidBuildOptionsSettings, IBuildForDevice {
133+
interface IBuildConfig extends IAndroidBuildOptionsSettings, IiOSBuildConfig {
134134
projectDir: string;
135135
clean?: boolean;
136136
architectures?: string[];
@@ -140,7 +140,7 @@ interface IBuildConfig extends IAndroidBuildOptionsSettings, IBuildForDevice {
140140
/**
141141
* Describes iOS-specific build configuration properties
142142
*/
143-
interface IiOSBuildConfig extends IBuildConfig, IRelease, IDeviceIdentifier, IProvision, ITeamIdentifier {
143+
interface IiOSBuildConfig extends IBuildForDevice, IDeviceIdentifier, IProvision, ITeamIdentifier, IRelease {
144144
/**
145145
* Identifier of the mobile provision which will be used for the build. If not set a provision will be selected automatically if possible.
146146
*/
@@ -178,6 +178,8 @@ interface IPlatformProjectService extends NodeJS.EventEmitter {
178178
*/
179179
validateOptions(projectId?: string, provision?: any): Promise<boolean>;
180180

181+
validatePlugins(projectData: IProjectData): Promise<void>;
182+
181183
buildProject(projectRoot: string, projectData: IProjectData, buildConfig: IBuildConfig): Promise<void>;
182184

183185
/**
@@ -231,7 +233,7 @@ interface IPlatformProjectService extends NodeJS.EventEmitter {
231233
*/
232234
getAppResourcesDestinationDirectoryPath(projectData: IProjectData): string;
233235

234-
deploy(deviceIdentifier: string, projectData: IProjectData): Promise<void>;
236+
cleanDeviceTempFolder(deviceIdentifier: string, projectData: IProjectData): Promise<void>;
235237
processConfigurationFilesFromAppResources(release: boolean, projectData: IProjectData): Promise<void>;
236238

237239
/**

lib/providers/livesync-provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class LiveSyncProvider implements ILiveSyncProvider {
3333
}
3434

3535
public async buildForDevice(device: Mobile.IDevice, projectData: IProjectData): Promise<string> {
36-
let buildConfig: IiOSBuildConfig = {
36+
let buildConfig: IBuildConfig = {
3737
buildForDevice: !device.isEmulator,
3838
projectDir: this.$options.path,
3939
release: this.$options.release,

lib/services/android-project-service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
9797
await this.$androidToolsInfo.validateJavacVersion(javaCompilerVersion, { showWarningsAsErrors: true });
9898
}
9999

100+
public async validatePlugins(): Promise<void> {
101+
Promise.resolve();
102+
}
103+
100104
public async createProject(frameworkDir: string, frameworkVersion: string, projectData: IProjectData, pathToTemplate?: string): Promise<void> {
101105
if (semver.lt(frameworkVersion, AndroidProjectService.MIN_RUNTIME_VERSION_WITH_GRADLE)) {
102106
this.$errors.failWithoutHelp(`The NativeScript CLI requires Android runtime ${AndroidProjectService.MIN_RUNTIME_VERSION_WITH_GRADLE} or later to work properly.`);
@@ -432,7 +436,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
432436
await this.spawn(gradleBin, options, { stdio: "inherit", cwd: this.getPlatformData(projectData).projectRoot });
433437
}
434438

435-
public async deploy(deviceIdentifier: string, projectData: IProjectData): Promise<void> {
439+
public async cleanDeviceTempFolder(deviceIdentifier: string, projectData: IProjectData): Promise<void> {
436440
let adb = this.$injector.resolve(DeviceAndroidDebugBridge, { identifier: deviceIdentifier });
437441
let deviceRootPath = `/data/local/tmp/${projectData.projectId}`;
438442
await adb.executeShellCommand(["rm", "-rf", deviceRootPath]);

lib/services/ios-debug-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class IOSDebugService implements IDebugService {
148148
justlaunch: this.$options.justlaunch
149149
};
150150
// we intentionally do not wait on this here, because if we did, we'd miss the AppLaunching notification
151-
let action = this.$platformService.runPlatform(this.platform, runOptions, projectData);
151+
let action = this.$platformService.startApplication(this.platform, runOptions, projectData);
152152

153153
await this.debugBrkCore(device, projectData, shouldBreak);
154154

lib/services/ios-project-service.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
4040
private $mobileHelper: Mobile.IMobileHelper,
4141
private $pluginVariablesService: IPluginVariablesService,
4242
private $xcprojService: IXcprojService,
43-
private $iOSProvisionService: IOSProvisionService) {
43+
private $iOSProvisionService: IOSProvisionService,
44+
private $sysInfo: ISysInfo) {
4445
super($fs, $projectDataService);
4546
}
4647

@@ -238,7 +239,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
238239
}
239240
}
240241

241-
public async buildProject(projectRoot: string, projectData: IProjectData, buildConfig: IiOSBuildConfig): Promise<void> {
242+
public async buildProject(projectRoot: string, projectData: IProjectData, buildConfig: IBuildConfig): Promise<void> {
242243
let basicArgs = [
243244
"-configuration", buildConfig.release ? "Release" : "Debug",
244245
"build",
@@ -270,7 +271,19 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
270271

271272
}
272273

273-
private async buildForDevice(projectRoot: string, args: string[], buildConfig: IiOSBuildConfig, projectData: IProjectData): Promise<void> {
274+
public async validatePlugins(projectData: IProjectData): Promise<void> {
275+
let installedPlugins = await (<IPluginsService>this.$injector.resolve("pluginsService")).getAllInstalledPlugins(projectData);
276+
for (let pluginData of installedPlugins) {
277+
let pluginsFolderExists = this.$fs.exists(path.join(pluginData.pluginPlatformsFolderPath(this.$devicePlatformsConstants.iOS.toLowerCase()), "Podfile"));
278+
let cocoaPodVersion = await this.$sysInfo.getCocoapodVersion();
279+
if (pluginsFolderExists && !cocoaPodVersion) {
280+
this.$errors.failWithoutHelp(`${pluginData.name} has Podfile and you don't have Cocoapods installed or it is not configured correctly. Please verify Cocoapods can work on your machine.`);
281+
}
282+
}
283+
Promise.resolve();
284+
}
285+
286+
private async buildForDevice(projectRoot: string, args: string[], buildConfig: IBuildConfig, projectData: IProjectData): Promise<void> {
274287
let defaultArchitectures = [
275288
'ARCHS=armv7 arm64',
276289
'VALID_ARCHS=armv7 arm64'
@@ -438,7 +451,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
438451
return this.$fs.exists(path.join(projectRoot, projectData.projectName, constants.APP_FOLDER_NAME));
439452
}
440453

441-
public deploy(deviceIdentifier: string): Promise<void> {
454+
public cleanDeviceTempFolder(deviceIdentifier: string): Promise<void> {
442455
return Promise.resolve();
443456
}
444457

0 commit comments

Comments
 (0)