Skip to content

Commit 26eaa3e

Browse files
Merge pull request #782 from NativeScript/vladimirov/improve-platform-commands
Add platform on all commands
2 parents 2d2ff89 + 9a38ec1 commit 26eaa3e

File tree

4 files changed

+31
-14
lines changed

4 files changed

+31
-14
lines changed

lib/commands/update-platform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class UpdatePlatformCommand implements ICommand {
1717
this.$errors.fail("No platform specified. Please specify platforms to update.");
1818
}
1919

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

2222
return true;
2323
}).future<boolean>()();

lib/platform-command-param.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export class PlatformCommandParameter implements ICommandParameter {
66
mandatory = true;
77
validate(value: string): IFuture<boolean> {
88
return (() => {
9-
this.$platformService.validatePlatformInstalled(value);
9+
this.$platformService.validatePlatform(value);
1010
return true;
1111
}).future<boolean>()();
1212
}

lib/services/platform-service.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export class PlatformService implements IPlatformService {
146146
this.validatePlatform(platform);
147147

148148
platform = platform.toLowerCase();
149+
this.ensurePlatformInstalled(platform).wait();
149150

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

234235
public updatePlatforms(platforms: string[]): IFuture<void> {
235236
return (() => {
236-
_.each(platforms, platform => {
237-
var parts = platform.split("@");
238-
platform = parts[0].toLowerCase();
239-
var version = parts[1];
240-
241-
this.validatePlatformInstalled(platform);
242-
this.updatePlatform(platform, version).wait();
237+
_.each(platforms, platformParam => {
238+
let [platform, version] = platformParam.split("@");
239+
if(this.isPlatformInstalled(platform).wait()) {
240+
this.updatePlatform(platform, version).wait();
241+
} else {
242+
this.addPlatform(platformParam).wait();
243+
}
243244
});
244245
}).future<void>()();
245246
}
246247

247248
public deployOnDevice(platform: string): IFuture<void> {
248249
return (() => {
249250
platform = platform.toLowerCase();
250-
251+
this.ensurePlatformInstalled(platform).wait();
251252
var platformData = this.$platformsData.getPlatformData(platform);
252253

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

277278
public deployOnEmulator(platform: string): IFuture<void> {
278279
return (() => {
279-
this.validatePlatformInstalled(platform);
280+
this.ensurePlatformInstalled(platform).wait();
280281
platform = platform.toLowerCase();
281282

282283
var platformData = this.$platformsData.getPlatformData(platform);
@@ -333,7 +334,15 @@ export class PlatformService implements IPlatformService {
333334
}
334335
}).future<void>()();
335336
}
336-
337+
338+
private ensurePlatformInstalled(platform: string): IFuture<void> {
339+
return (() => {
340+
if(!this.isPlatformInstalled(platform).wait()) {
341+
this.addPlatform(platform).wait();
342+
}
343+
}).future<void>()();
344+
}
345+
337346
private isPlatformInstalled(platform: string): IFuture<boolean> {
338347
return this.$fs.exists(path.join(this.$projectData.platformsDir, platform.toLowerCase()));
339348
}

test/platform-service.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,11 @@ describe('Platform Service Tests', () => {
227227
appResourcesDestinationDirectoryPath: appResourcesFolderPath,
228228
normalizedPlatformName: "iOS",
229229
platformProjectService: {
230-
prepareProject: () => Future.fromResult()
230+
prepareProject: () => Future.fromResult(),
231+
validate: () => Future.fromResult(),
232+
createProject: (projectRoot: string, frameworkDir: string) => Future.fromResult(),
233+
interpolateData: (projectRoot: string) => Future.fromResult(),
234+
afterCreateProject: (projectRoot: string) => Future.fromResult()
231235
}
232236
}
233237
};
@@ -281,7 +285,11 @@ describe('Platform Service Tests', () => {
281285
appResourcesDestinationDirectoryPath: appResourcesFolderPath,
282286
normalizedPlatformName: "Android",
283287
platformProjectService: {
284-
prepareProject: () => Future.fromResult()
288+
prepareProject: () => Future.fromResult(),
289+
validate: () => Future.fromResult(),
290+
createProject: (projectRoot: string, frameworkDir: string) => Future.fromResult(),
291+
interpolateData: (projectRoot: string) => Future.fromResult(),
292+
afterCreateProject: (projectRoot: string) => Future.fromResult()
285293
}
286294
}
287295
};

0 commit comments

Comments
 (0)