Skip to content

Commit 245663a

Browse files
FatmeFatme Havaluova
authored andcommitted
Deploy on emulator
1 parent 7b9f5c4 commit 245663a

14 files changed

+161
-60
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");
@@ -24,6 +26,7 @@ $injector.requireCommand("prepare", "./commands/prepare");
2426
$injector.requireCommand("build", "./commands/build");
2527
$injector.requireCommand("deploy", "./commands/deploy");
2628
$injector.requireCommand("dev-post-install", "./commands/post-install");
29+
$injector.requireCommand("emulate", "./commands/emulate");
2730

2831
$injector.require("npm", "./node-package-manager");
2932
$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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
///<reference path="../.d.ts"/>
2+
3+
export class EmulateCommand implements ICommand {
4+
constructor(private $platformService: IPlatformService) { }
5+
6+
execute(args: string[]): IFuture<void> { return this.$platformService.deployOnEmulator(args[0]);}
7+
}
8+
$injector.registerCommand("emulate", EmulateCommand);

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: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@ 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;
17-
buildOutputPath: string;
18-
validPackageNames: string[];
19+
deviceBuildOutputPath: string;
20+
emulatorBuildOutputPath?: string;
21+
validPackageNamesForDevice: string[];
22+
validPackageNamesForEmulator?: string[];
1923
targetedOS?: string[];
2024
}
2125

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: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,22 @@ 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"),
25-
buildOutputPath: path.join(this.$projectData.platformsDir, "android", "bin"),
26-
validPackageNames: [
27+
deviceBuildOutputPath: path.join(this.$projectData.platformsDir, "android", "bin"),
28+
validPackageNamesForDevice: [
2729
util.format("%s-%s.%s", this.$projectData.projectName, "debug", "apk"),
2830
util.format("%s-%s.%s", this.$projectData.projectName, "release", "apk")
2931
]
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: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,24 @@ 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"),
26-
buildOutputPath: path.join(this.$projectData.platformsDir, "ios", "build", "device"),
27-
validPackageNames: [
28+
deviceBuildOutputPath: path.join(this.$projectData.platformsDir, "ios", "build", "device"),
29+
emulatorBuildOutputPath: path.join(this.$projectData.platformsDir, "ios", "build", "emulator"),
30+
validPackageNamesForDevice: [
2831
this.$projectData.projectName + ".ipa"
2932
],
33+
validPackageNamesForEmulator: [
34+
this.$projectData.projectName + ".app"
35+
],
3036
targetedOS: ['darwin']
3137
};
3238
}
@@ -117,18 +123,20 @@ class IOSProjectService implements IPlatformProjectService {
117123
var childProcess = this.$childProcess.spawn("xcodebuild", args, {cwd: options, stdio: 'inherit'});
118124
this.$fs.futureFromEvent(childProcess, "exit").wait();
119125

120-
var buildOutputPath = path.join(projectRoot, "build", options.device ? "device" : "emulator");
126+
if(options.device) {
127+
var buildOutputPath = path.join(projectRoot, "build", options.device ? "device" : "emulator");
121128

122-
// Produce ipa file
123-
var xcrunArgs = [
124-
"-sdk", "iphoneos",
125-
"PackageApplication",
126-
"-v", path.join(buildOutputPath, this.$projectData.projectName + ".app"),
127-
"-o", path.join(buildOutputPath, this.$projectData.projectName + ".ipa")
128-
];
129+
// Produce ipa file
130+
var xcrunArgs = [
131+
"-sdk", "iphoneos",
132+
"PackageApplication",
133+
"-v", path.join(buildOutputPath, this.$projectData.projectName + ".app"),
134+
"-o", path.join(buildOutputPath, this.$projectData.projectName + ".ipa")
135+
];
129136

130-
var childProcess = this.$childProcess.spawn("xcrun", xcrunArgs, {cwd: options, stdio: 'inherit'});
131-
this.$fs.futureFromEvent(childProcess, "exit").wait();
137+
var childProcess = this.$childProcess.spawn("xcrun", xcrunArgs, {cwd: options, stdio: 'inherit'});
138+
this.$fs.futureFromEvent(childProcess, "exit").wait();
139+
}
132140
}).future<void>()();
133141
}
134142

0 commit comments

Comments
 (0)