Skip to content

Commit 37448c9

Browse files
committed
Deploy on emulator
1 parent 3bef0fb commit 37448c9

13 files changed

+125
-44
lines changed

lib/bootstrap.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ $injector.require("platformService", "./services/platform-service");
1515
$injector.require("userSettingsService", "./services/user-settings-service");
1616
$injector.require("analyticsSettingsService", "./services/analytics-settings-service");
1717

18+
$injector.require("emulatorSettingsService", "./services/emulator-settings-service");
19+
1820
$injector.requireCommand("create", "./commands/create-project");
1921
$injector.requireCommand("platform|*list", "./commands/list-platforms");
2022
$injector.requireCommand("platform|add", "./commands/add-platform");
@@ -23,6 +25,7 @@ $injector.requireCommand("run", "./commands/run");
2325
$injector.requireCommand("prepare", "./commands/prepare");
2426
$injector.requireCommand("build", "./commands/build");
2527
$injector.requireCommand("deploy", "./commands/deploy");
28+
$injector.requireCommand("emulate", "./commands/emulate");
2629

2730
$injector.require("npm", "./node-package-manager");
2831
$injector.require("config", "./config");

lib/commands/deploy.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
///<reference path="../.d.ts"/>
22

3-
export class DeployCommand implements ICommand {
3+
export class DeployOnDeviceCommand implements ICommand {
44
constructor(private $platformService: IPlatformService) { }
55

66
execute(args: string[]): IFuture<void> {
7-
return (() => {
8-
this.$platformService.deploy(args[0]).wait();
9-
}).future<void>()();
7+
return this.$platformService.deployOnDevice(args[0]);
108
}
119
}
12-
$injector.registerCommand("deploy", DeployCommand);
10+
$injector.registerCommand("deploy", DeployOnDeviceCommand);

lib/commands/emulate.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
///<reference path="../.d.ts"/>
2+
3+
export class DeployOnEmulatorCommand implements ICommand {
4+
constructor(private $platformService: IPlatformService) { }
5+
6+
execute(args: string[]): IFuture<void> {
7+
return this.$platformService.deployOnEmulator(args[0]);
8+
}
9+
}
10+
$injector.registerCommand("deploy", DeployOnEmulatorCommand);

lib/declarations.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@ interface INodePackageManager {
66

77
interface IStaticConfig extends Config.IStaticConfig { }
88

9+
interface IApplicationPackage {
10+
packageName: string;
11+
time: Date;
12+
}
13+

lib/definitions/platform.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ interface IPlatformService {
66
runPlatform(platform: string): IFuture<void>;
77
preparePlatform(platform: string): IFuture<void>;
88
buildPlatform(platform: string): IFuture<void>;
9-
deploy(platform: string): IFuture<void>;
9+
deployOnDevice(platform: string): IFuture<void>;
10+
deployOnEmulator(platform: string): IFuture<void>;
1011
}
1112

1213
interface IPlatformData {
1314
frameworkPackageName: string;
1415
platformProjectService: IPlatformProjectService;
16+
emulatorServices: Mobile.IEmulatorPlatformServices;
1517
projectRoot: string;
1618
normalizedPlatformName: string;
1719
buildOutputPath: string;

lib/options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var knownOpts:any = {
1313
"link-to": String,
1414
"release": String,
1515
"device": Boolean,
16+
"emulator": Boolean,
1617
"version": Boolean,
1718
"help": Boolean
1819
},

lib/services/android-project-service.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,19 @@ class AndroidProjectService implements IPlatformProjectService {
1010
private targetApi: string;
1111

1212
constructor(private $fs: IFileSystem,
13-
private $errors: IErrors,
14-
private $logger: ILogger,
15-
private $childProcess: IChildProcess,
16-
private $projectData: IProjectData,
17-
private $propertiesParser: IPropertiesParser) { }
13+
private $errors: IErrors,
14+
private $logger: ILogger,
15+
private $childProcess: IChildProcess,
16+
private $projectData: IProjectData,
17+
private $propertiesParser: IPropertiesParser,
18+
private $androidEmulatorServices: Mobile.IEmulatorPlatformServices) { }
1819

1920
public get platformData(): IPlatformData {
2021
return {
2122
frameworkPackageName: "tns-android",
2223
normalizedPlatformName: "Android",
2324
platformProjectService: this,
25+
emulatorServices: this.$androidEmulatorServices,
2426
projectRoot: path.join(this.$projectData.platformsDir, "android"),
2527
buildOutputPath: path.join(this.$projectData.platformsDir, "android", "bin"),
2628
validPackageNames: [
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
///<reference path="../.d.ts"/>
2+
3+
export class EmulatorSettingsService implements Mobile.IEmulatorSettingsService {
4+
private static REQURED_ANDROID_APILEVEL = 17;
5+
6+
constructor(private $injector: IInjector) { }
7+
8+
public canStart(platform: string): IFuture<boolean> {
9+
return (() => {
10+
var platformService = this.$injector.resolve("platformService"); // this should be resolved here due to cyclic dependency
11+
12+
var installedPlatforms = platformService.getInstalledPlatforms().wait();
13+
return _.contains(installedPlatforms, platform.toLowerCase());
14+
}).future<boolean>()();
15+
}
16+
17+
public get minVersion(): number {
18+
return EmulatorSettingsService.REQURED_ANDROID_APILEVEL;
19+
}
20+
}
21+
$injector.register("emulatorSettingsService", EmulatorSettingsService);

lib/services/ios-project-service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ class IOSProjectService implements IPlatformProjectService {
1515
constructor(private $projectData: IProjectData,
1616
private $fs: IFileSystem,
1717
private $childProcess: IChildProcess,
18-
private $errors: IErrors) { }
18+
private $errors: IErrors,
19+
private $iOSEmulatorServices: Mobile.IEmulatorPlatformServices) { }
1920

2021
public get platformData(): IPlatformData {
2122
return {
2223
frameworkPackageName: "tns-ios",
2324
normalizedPlatformName: "iOS",
2425
platformProjectService: this,
26+
emulatorServices: this.$iOSEmulatorServices,
2527
projectRoot: path.join(this.$projectData.platformsDir, "ios"),
2628
buildOutputPath: path.join(this.$projectData.platformsDir, "ios", "build", "device"),
2729
validPackageNames: [

0 commit comments

Comments
 (0)