-
-
Notifications
You must be signed in to change notification settings - Fork 197
Deploy on emulator #59
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
///<reference path="../.d.ts"/> | ||
|
||
export class DeployCommand implements ICommand { | ||
export class DeployOnDeviceCommand implements ICommand { | ||
constructor(private $platformService: IPlatformService) { } | ||
|
||
execute(args: string[]): IFuture<void> { | ||
return (() => { | ||
this.$platformService.deploy(args[0]).wait(); | ||
}).future<void>()(); | ||
return this.$platformService.deployOnDevice(args[0]); | ||
} | ||
} | ||
$injector.registerCommand("deploy", DeployCommand); | ||
$injector.registerCommand("deploy", DeployOnDeviceCommand); | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
///<reference path="../.d.ts"/> | ||
|
||
export class EmulateCommand implements ICommand { | ||
constructor(private $platformService: IPlatformService) { } | ||
|
||
execute(args: string[]): IFuture<void> { return this.$platformService.deployOnEmulator(args[0]);} | ||
} | ||
$injector.registerCommand("emulate", EmulateCommand); |
+4 −0 | bootstrap.ts | |
+3 −0 | definitions/iconv-lite.d.ts | |
+21 −0 | definitions/mobile.d.ts | |
+8 −1 | dispatchers.ts | |
+227 −0 | mobile/android/android-emulator-services.ts | |
+43 −0 | mobile/ios/ios-emulator-services.ts | |
+38 −0 | mobile/wp8/wp8-emulator-services.ts |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
///<reference path="../.d.ts"/> | ||
|
||
export class EmulatorSettingsService implements Mobile.IEmulatorSettingsService { | ||
private static REQURED_ANDROID_APILEVEL = 17; | ||
|
||
constructor(private $injector: IInjector) { } | ||
|
||
public canStart(platform: string): IFuture<boolean> { | ||
return (() => { | ||
var platformService = this.$injector.resolve("platformService"); // this should be resolved here due to cyclic dependency | ||
|
||
var installedPlatforms = platformService.getInstalledPlatforms().wait(); | ||
return _.contains(installedPlatforms, platform.toLowerCase()); | ||
}).future<boolean>()(); | ||
} | ||
|
||
public get minVersion(): number { | ||
return EmulatorSettingsService.REQURED_ANDROID_APILEVEL; | ||
} | ||
} | ||
$injector.register("emulatorSettingsService", EmulatorSettingsService); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not a merge stopper, but consider adding a new line here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,14 +164,11 @@ export class PlatformService implements IPlatformService { | |
platform = platform.toLowerCase(); | ||
|
||
this.preparePlatform(platform).wait(); | ||
|
||
// We need to set device option here | ||
var cachedDeviceOption = options.device; | ||
options.device = true; | ||
this.buildPlatform(platform).wait(); | ||
options.device = cachedDeviceOption; | ||
|
||
this.deploy(platform).wait(); | ||
if(options.emulator) { | ||
this.deployOnEmulator(platform).wait(); | ||
} else { | ||
this.deployOnDevice(platform).wait(); | ||
} | ||
}).future<void>()(); | ||
} | ||
|
||
|
@@ -191,35 +188,21 @@ export class PlatformService implements IPlatformService { | |
}).future<void>()(); | ||
} | ||
|
||
public deploy(platform: string): IFuture<void> { | ||
public deployOnDevice(platform: string): IFuture<void> { | ||
return (() => { | ||
platform = platform.toLowerCase(); | ||
|
||
this.validatePlatformInstalled(platform); | ||
platform = platform.toLowerCase(); | ||
|
||
var platformData = this.$platformsData.getPlatformData(platform); | ||
|
||
// Get latest package that is produced from build | ||
var candidates = this.$fs.readDirectory(platformData.buildOutputPath).wait(); | ||
var packages = _.filter(candidates, candidate => { | ||
return _.contains(platformData.validPackageNames, candidate); | ||
}).map(currentPackage => { | ||
currentPackage = path.join(platformData.buildOutputPath, currentPackage); | ||
|
||
return { | ||
pkg: currentPackage, | ||
time: this.$fs.getFsStats(currentPackage).wait().mtime | ||
}; | ||
}); | ||
|
||
packages = _.sortBy(packages, pkg => pkg.time ).reverse(); // We need to reverse because sortBy always sorts in ascending order | ||
|
||
if(packages.length === 0) { | ||
var packageExtName = path.extname(platformData.validPackageNames[0]); | ||
this.$errors.fail("No %s found in %s directory", packageExtName, platformData.buildOutputPath) | ||
} | ||
// We need to build for device | ||
var cachedDeviceOption = options.device; | ||
options.device = true; | ||
this.buildPlatform(platform).wait(); | ||
options.device = cachedDeviceOption; | ||
|
||
var packageFile = packages[0].pkg; | ||
// Get latest package that is produced from build | ||
var packageFile = this.getLatestApplicationPackageForDevice(platformData).wait().packageName; | ||
this.$logger.out("Using ", packageFile); | ||
|
||
this.$devicesServices.initialize(platform, options.device).wait(); | ||
|
@@ -229,6 +212,25 @@ export class PlatformService implements IPlatformService { | |
}).future<void>()(); | ||
} | ||
|
||
public deployOnEmulator(platform: string): IFuture<void> { | ||
return (() => { | ||
this.validatePlatformInstalled(platform); | ||
platform = platform.toLowerCase(); | ||
|
||
var platformData = this.$platformsData.getPlatformData(platform); | ||
var emulatorServices = platformData.emulatorServices; | ||
|
||
emulatorServices.checkAvailability().wait(); | ||
|
||
this.buildPlatform(platform).wait(); | ||
|
||
var packageFile = this.getLatestApplicationPackageForEmulator(platformData).wait().packageName; | ||
this.$logger.out("Using ", packageFile); | ||
|
||
emulatorServices.startEmulator(packageFile, options.emulator).wait(); | ||
}).future<void>()(); | ||
} | ||
|
||
private validatePlatform(platform: string): void { | ||
if(!platform) { | ||
this.$errors.fail("No platform specified.") | ||
|
@@ -299,5 +301,46 @@ export class PlatformService implements IPlatformService { | |
}); | ||
}).future<void>()(); | ||
} | ||
|
||
private getApplicationPackages(buildOutputPath: string, validPackageNames: string[]): IFuture<IApplicationPackage[]> { | ||
return (() => { | ||
// Get latest package that is produced from build | ||
var candidates = this.$fs.readDirectory(buildOutputPath).wait(); | ||
var packages = _.filter(candidates, candidate => { | ||
return _.contains(validPackageNames, candidate); | ||
}).map(currentPackage => { | ||
currentPackage = path.join(buildOutputPath, currentPackage); | ||
|
||
return { | ||
packageName: currentPackage, | ||
time: this.$fs.getFsStats(currentPackage).wait().mtime | ||
}; | ||
}); | ||
|
||
return packages; | ||
}).future<IApplicationPackage[]>()(); | ||
} | ||
|
||
private getLatestApplicationPackage(buildOutputPath: string, validPackageNames: string[]): IFuture<IApplicationPackage> { | ||
return (() => { | ||
var packages = this.getApplicationPackages(buildOutputPath, validPackageNames).wait(); | ||
if (packages.length === 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check can be executed before the sortby+reverse operations. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, good catch :) thanks |
||
var packageExtName = path.extname(validPackageNames[0]); | ||
this.$errors.fail("No %s found in %s directory", packageExtName, buildOutputPath); | ||
} | ||
|
||
packages = _.sortBy(packages, pkg => pkg.time).reverse(); // We need to reverse because sortBy always sorts in ascending order | ||
|
||
return packages[0]; | ||
}).future<IApplicationPackage>()(); | ||
} | ||
|
||
private getLatestApplicationPackageForDevice(platformData: IPlatformData) { | ||
return this.getLatestApplicationPackage(platformData.deviceBuildOutputPath, platformData.validPackageNamesForDevice); | ||
} | ||
|
||
private getLatestApplicationPackageForEmulator(platformData: IPlatformData) { | ||
return this.getLatestApplicationPackage(platformData.emulatorBuildOutputPath || platformData.deviceBuildOutputPath, platformData.validPackageNamesForEmulator || platformData.validPackageNamesForDevice); | ||
} | ||
} | ||
$injector.register("platformService", PlatformService); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a merge stopper, but consider adding a new line here.