Skip to content

Add platform on all commands #782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/commands/update-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class UpdatePlatformCommand implements ICommand {
this.$errors.fail("No platform specified. Please specify platforms to update.");
}

_.each(args, arg => this.$platformService.validatePlatformInstalled(arg.split("@")[0]));
_.each(args, arg => this.$platformService.validatePlatform(arg.split("@")[0]));

return true;
}).future<boolean>()();
Expand Down
2 changes: 1 addition & 1 deletion lib/platform-command-param.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class PlatformCommandParameter implements ICommandParameter {
mandatory = true;
validate(value: string): IFuture<boolean> {
return (() => {
this.$platformService.validatePlatformInstalled(value);
this.$platformService.validatePlatform(value);
return true;
}).future<boolean>()();
}
Expand Down
29 changes: 19 additions & 10 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export class PlatformService implements IPlatformService {
this.validatePlatform(platform);

platform = platform.toLowerCase();
this.ensurePlatformInstalled(platform).wait();

var platformData = this.$platformsData.getPlatformData(platform);
let appDestinationDirectoryPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME);
Expand Down Expand Up @@ -233,21 +234,21 @@ export class PlatformService implements IPlatformService {

public updatePlatforms(platforms: string[]): IFuture<void> {
return (() => {
_.each(platforms, platform => {
var parts = platform.split("@");
platform = parts[0].toLowerCase();
var version = parts[1];

this.validatePlatformInstalled(platform);
this.updatePlatform(platform, version).wait();
_.each(platforms, platformParam => {
let [platform, version] = platformParam.split("@");
if(this.isPlatformInstalled(platform).wait()) {
this.updatePlatform(platform, version).wait();
} else {
this.addPlatform(platformParam).wait();
}
});
}).future<void>()();
}

public deployOnDevice(platform: string): IFuture<void> {
return (() => {
platform = platform.toLowerCase();

this.ensurePlatformInstalled(platform).wait();
var platformData = this.$platformsData.getPlatformData(platform);

var cachedDeviceOption = this.$options.forDevice;
Expand Down Expand Up @@ -276,7 +277,7 @@ export class PlatformService implements IPlatformService {

public deployOnEmulator(platform: string): IFuture<void> {
return (() => {
this.validatePlatformInstalled(platform);
this.ensurePlatformInstalled(platform).wait();
platform = platform.toLowerCase();

var platformData = this.$platformsData.getPlatformData(platform);
Expand Down Expand Up @@ -333,7 +334,15 @@ export class PlatformService implements IPlatformService {
}
}).future<void>()();
}


private ensurePlatformInstalled(platform: string): IFuture<void> {
return (() => {
if(!this.isPlatformInstalled(platform).wait()) {
this.addPlatform(platform).wait();
}
}).future<void>()();
}

private isPlatformInstalled(platform: string): IFuture<boolean> {
return this.$fs.exists(path.join(this.$projectData.platformsDir, platform.toLowerCase()));
}
Expand Down
12 changes: 10 additions & 2 deletions test/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,11 @@ describe('Platform Service Tests', () => {
appResourcesDestinationDirectoryPath: appResourcesFolderPath,
normalizedPlatformName: "iOS",
platformProjectService: {
prepareProject: () => Future.fromResult()
prepareProject: () => Future.fromResult(),
validate: () => Future.fromResult(),
createProject: (projectRoot: string, frameworkDir: string) => Future.fromResult(),
interpolateData: (projectRoot: string) => Future.fromResult(),
afterCreateProject: (projectRoot: string) => Future.fromResult()
}
}
};
Expand Down Expand Up @@ -281,7 +285,11 @@ describe('Platform Service Tests', () => {
appResourcesDestinationDirectoryPath: appResourcesFolderPath,
normalizedPlatformName: "Android",
platformProjectService: {
prepareProject: () => Future.fromResult()
prepareProject: () => Future.fromResult(),
validate: () => Future.fromResult(),
createProject: (projectRoot: string, frameworkDir: string) => Future.fromResult(),
interpolateData: (projectRoot: string) => Future.fromResult(),
afterCreateProject: (projectRoot: string) => Future.fromResult()
}
}
};
Expand Down