Skip to content

Commit 7ca1ca2

Browse files
Fatme HavaluovaFatme Havaluova
Fatme Havaluova
authored and
Fatme Havaluova
committed
Implement run and emulate commands as hierarchical
1 parent 6fe99c4 commit 7ca1ca2

File tree

8 files changed

+85
-20
lines changed

8 files changed

+85
-20
lines changed

lib/bootstrap.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ $injector.requireCommand("debug", "./commands/debug");
3131
$injector.requireCommand("prepare", "./commands/prepare");
3232
$injector.requireCommand("build", "./commands/build");
3333
$injector.requireCommand("deploy", "./commands/deploy");
34-
$injector.requireCommand("emulate", "./commands/emulate");
34+
$injector.requireCommand("emulate|android", "./commands/emulate");
35+
$injector.requireCommand("emulate|ios", "./commands/emulate");
3536

3637
$injector.require("npm", "./node-package-manager");
3738
$injector.require("lockfile", "./lockfile");

lib/commands/emulate.ts

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,38 @@
11
///<reference path="../.d.ts"/>
22
"use strict";
33

4-
export class EmulateCommand implements ICommand {
5-
constructor(private $platformService: IPlatformService,
6-
private $platformCommandParameter: ICommandParameter) { }
4+
export class EmulateCommandBase {
5+
constructor(private $platformService: IPlatformService) { }
76

8-
execute(args: string[]): IFuture<void> { return this.$platformService.deployOnEmulator(args[0]); }
7+
executeCore(args: string[]): IFuture<void> {
8+
return this.$platformService.deployOnEmulator(args[0]);
9+
}
10+
}
11+
12+
export class EmulateIosCommand extends EmulateCommandBase implements ICommand {
13+
constructor($platformService: IPlatformService,
14+
private $platformsData: IPlatformsData) {
15+
super($platformService);
16+
}
17+
18+
public allowedParameters: ICommandParameter[] = [];
19+
20+
public execute(args: string[]): IFuture<void> {
21+
return this.executeCore([this.$platformsData.availablePlatforms.iOS]);
22+
}
23+
}
24+
$injector.registerCommand("emulate|ios", EmulateIosCommand);
25+
26+
export class EmulateAndroidCommand extends EmulateCommandBase implements ICommand {
27+
constructor($platformService: IPlatformService,
28+
private $platformsData: IPlatformsData) {
29+
super($platformService);
30+
}
31+
32+
public allowedParameters: ICommandParameter[] = [];
933

10-
allowedParameters = [this.$platformCommandParameter];
34+
public execute(args: string[]): IFuture<void> {
35+
return this.executeCore([this.$platformsData.availablePlatforms.Android]);
36+
}
1137
}
12-
$injector.registerCommand("emulate", EmulateCommand);
38+
$injector.registerCommand("emulate|android", EmulateAndroidCommand);

lib/commands/run.ts

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,38 @@
11
///<reference path="../.d.ts"/>
22
"use strict";
33

4-
export class RunCommand implements ICommand {
5-
constructor(private $platformService: IPlatformService,
6-
private $platformCommandParameter: ICommandParameter) { }
7-
8-
execute(args: string[]): IFuture<void> {
9-
return (() => {
10-
this.$platformService.runPlatform(args[0]).wait();
11-
}).future<void>()();
4+
export class RunCommandBase {
5+
constructor(private $platformService: IPlatformService) { }
6+
7+
public executeCore(args: string[]): IFuture<void> {
8+
return this.$platformService.runPlatform(args[0]);
9+
}
10+
}
11+
12+
export class RunIosCommand extends RunCommandBase implements ICommand {
13+
constructor($platformService: IPlatformService,
14+
private $platformsData: IPlatformsData) {
15+
super($platformService);
16+
}
17+
18+
public allowedParameters: ICommandParameter[] = [];
19+
20+
public execute(args: string[]): IFuture<void> {
21+
return this.executeCore([this.$platformsData.availablePlatforms.iOS]);
22+
}
23+
}
24+
$injector.registerCommand("run|ios", RunIosCommand);
25+
26+
export class RunAndroidCommand extends RunCommandBase implements ICommand {
27+
constructor($platformService: IPlatformService,
28+
private $platformsData: IPlatformsData) {
29+
super($platformService);
1230
}
1331

14-
allowedParameters = [this.$platformCommandParameter];
32+
public allowedParameters: ICommandParameter[] = [];
33+
34+
public execute(args: string[]): IFuture<void> {
35+
return this.executeCore([this.$platformsData.availablePlatforms.Android]);
36+
}
1537
}
16-
$injector.registerCommand("run", RunCommand);
38+
$injector.registerCommand("run|android", RunAndroidCommand);

lib/definitions/platform.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ interface IPlatformService {
55
getPreparedPlatforms(): IFuture<string[]>;
66
removePlatforms(platforms: string[]): IFuture<void>;
77
updatePlatforms(platforms: string[]): IFuture<void>;
8-
runPlatform(platform: string): IFuture<void>;
9-
debugPlatform(platform: string): IFuture<void>;
8+
runPlatform(platform: string): IFuture<void>;
9+
debugPlatform(platform: string): IFuture<void>;
1010
preparePlatform(platform: string): IFuture<void>;
1111
buildPlatform(platform: string): IFuture<void>;
1212
deployOnDevice(platform: string): IFuture<void>;
@@ -30,6 +30,7 @@ interface IPlatformData {
3030
}
3131

3232
interface IPlatformsData {
33+
availablePlatforms: any;
3334
platformsNames: string[];
3435
getPlatformData(platform: string): IPlatformData;
3536
}

lib/platforms-data.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,12 @@ export class PlatformsData implements IPlatformsData {
2020
public getPlatformData(platform: string): IPlatformData {
2121
return this.platformsData[platform];
2222
}
23+
24+
public get availablePlatforms(): any {
25+
return {
26+
iOS: "ios",
27+
Android: "android"
28+
};
29+
}
2330
}
2431
$injector.register("platformsData", PlatformsData);

test/platform-commands.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ class PlatformsData implements IPlatformsData {
6363

6464
return null;
6565
}
66+
67+
public get availablePlatforms(): any {
68+
return undefined;
69+
}
6670
}
6771

6872
function createTestInjector() {

test/stubs.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@ export class PlatformsDataStub implements IPlatformsData {
211211
frameworkFilesExtensions: []
212212
};
213213
}
214+
215+
public get availablePlatforms(): any {
216+
return undefined;
217+
}
214218
}
215219

216220
export class PlatformProjectServiceStub implements IPlatformProjectService {

0 commit comments

Comments
 (0)