Skip to content
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

Allow prepare for Android without ANDROID_HOME #2904

Merged
merged 3 commits into from
Jun 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/android-tools-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,12 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
@cache()
private getInstalledTargets(): string[] {
let installedTargets: string[] = [];
const pathToInstalledTargets = path.join(this.androidHome, "platforms");
if (this.$fs.exists(pathToInstalledTargets)) {
installedTargets = this.$fs.readDirectory(pathToInstalledTargets);
if (this.androidHome) {
const pathToInstalledTargets = path.join(this.androidHome, "platforms");
if (this.$fs.exists(pathToInstalledTargets)) {
installedTargets = this.$fs.readDirectory(pathToInstalledTargets);
}
}

this.$logger.trace("Installed Android Targets are: ", installedTargets);

return installedTargets;
Expand Down
8 changes: 7 additions & 1 deletion lib/commands/add-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export class AddPlatformCommand implements ICommand {
constructor(private $options: IOptions,
private $platformService: IPlatformService,
private $projectData: IProjectData,
private $platformsData: IPlatformsData,
private $errors: IErrors) {
this.$projectData.initializeProjectData();
}
Expand All @@ -17,7 +18,12 @@ export class AddPlatformCommand implements ICommand {
this.$errors.fail("No platform specified. Please specify a platform to add");
}

_.each(args, arg => this.$platformService.validatePlatform(arg, this.$projectData));
for (let arg of args) {
this.$platformService.validatePlatform(arg, this.$projectData);
const platformData = this.$platformsData.getPlatformData(arg, this.$projectData);
const platformProjectService = platformData.platformProjectService;
await platformProjectService.validate(this.$projectData);
}

return true;
}
Expand Down
5 changes: 5 additions & 0 deletions lib/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
if (this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
this.$errors.fail("When producing a release build, you need to specify all --key-store-* options.");
}

const platformData = this.$platformsData.getPlatformData(this.$devicePlatformsConstants.Android, this.$projectData);
const platformProjectService = platformData.platformProjectService;
await platformProjectService.validate(this.$projectData);

return args.length === 0 && await this.$platformService.validateOptions(this.$options.provision, this.$projectData, this.$platformsData.availablePlatforms.Android);
}
}
Expand Down
60 changes: 34 additions & 26 deletions lib/commands/clean-app.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,64 @@
export class CleanAppCommandBase {
export class CleanAppCommandBase implements ICommand {
public allowedParameters: ICommandParameter[] = [];

protected platform: string;

constructor(protected $options: IOptions,
protected $projectData: IProjectData,
protected $platformService: IPlatformService) {
protected $platformService: IPlatformService,
protected $errors: IErrors,
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
protected $platformsData: IPlatformsData) {

this.$projectData.initializeProjectData();
}

public async execute(args: string[]): Promise<void> {
let platform = args[0].toLowerCase();
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
return this.$platformService.cleanDestinationApp(platform, appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData, this.$options);
return this.$platformService.cleanDestinationApp(this.platform.toLowerCase(), appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData, this.$options);
}

public async canExecute(args: string[]): Promise<boolean> {
if (!this.$platformService.isPlatformSupportedForOS(this.platform, this.$projectData)) {
this.$errors.fail(`Applications for platform ${this.platform} can not be built on this OS`);
}

let platformData = this.$platformsData.getPlatformData(this.platform, this.$projectData);
let platformProjectService = platformData.platformProjectService;
await platformProjectService.validate(this.$projectData);
return true;
}
}

export class CleanAppIosCommand extends CleanAppCommandBase implements ICommand {
constructor(protected $options: IOptions,
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
private $platformsData: IPlatformsData,
private $errors: IErrors,
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
protected $platformsData: IPlatformsData,
protected $errors: IErrors,
$platformService: IPlatformService,
$projectData: IProjectData) {
super($options, $projectData, $platformService);
super($options, $projectData, $platformService, $errors, $devicePlatformsConstants, $platformsData);
}

public allowedParameters: ICommandParameter[] = [];

public async execute(args: string[]): Promise<void> {
if (!this.$platformService.isPlatformSupportedForOS(this.$devicePlatformsConstants.iOS, this.$projectData)) {
this.$errors.fail(`Applications for platform ${this.$devicePlatformsConstants.iOS} can not be built on this OS`);
}
return super.execute([this.$platformsData.availablePlatforms.iOS]);
protected get platform(): string {
return this.$devicePlatformsConstants.iOS;
}
}

$injector.registerCommand("clean-app|ios", CleanAppIosCommand);

export class CleanAppAndroidCommand extends CleanAppCommandBase implements ICommand {
public allowedParameters: ICommandParameter[] = [];

constructor(protected $options: IOptions,
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
private $platformsData: IPlatformsData,
private $errors: IErrors,
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
protected $platformsData: IPlatformsData,
protected $errors: IErrors,
$platformService: IPlatformService,
$projectData: IProjectData) {
super($options, $projectData, $platformService);
super($options, $projectData, $platformService, $errors, $devicePlatformsConstants, $platformsData);
}

public async execute(args: string[]): Promise<void> {
if (!this.$platformService.isPlatformSupportedForOS(this.$devicePlatformsConstants.iOS, this.$projectData)) {
this.$errors.fail(`Applications for platform ${this.$devicePlatformsConstants.iOS} can not be built on this OS`);
}
return super.execute([this.$platformsData.availablePlatforms.Android]);
protected get platform(): string {
return this.$devicePlatformsConstants.Android;
}
}

Expand Down
23 changes: 15 additions & 8 deletions lib/commands/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
protected $options: IOptions,
protected $platformsData: IPlatformsData,
protected $logger: ILogger,
protected $errors: IErrors,
private $debugLiveSyncService: IDebugLiveSyncService,
private $config: IConfiguration) {
this.$projectData.initializeProjectData();
Expand Down Expand Up @@ -73,6 +74,14 @@
}

public async canExecute(args: string[]): Promise<boolean> {
if (!this.$platformService.isPlatformSupportedForOS(this.platform, this.$projectData)) {
this.$errors.fail(`Applications for platform ${this.platform} can not be built on this OS`);
}

const platformData = this.$platformsData.getPlatformData(this.platform, this.$projectData);
const platformProjectService = platformData.platformProjectService;
await platformProjectService.validate(this.$projectData);

await this.$devicesService.initialize({
platform: this.platform,
deviceId: this.$options.device,
Expand All @@ -97,7 +106,7 @@
}

export class DebugIOSCommand extends DebugPlatformCommand {
constructor(private $errors: IErrors,
constructor(protected $errors: IErrors,
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
$logger: ILogger,
$iOSDebugService: IPlatformDebugService,
Expand All @@ -110,7 +119,8 @@ export class DebugIOSCommand extends DebugPlatformCommand {
$platformsData: IPlatformsData,
$iosDeviceOperations: IIOSDeviceOperations,
$debugLiveSyncService: IDebugLiveSyncService) {
super($iOSDebugService, $devicesService, $debugDataService, $platformService, $projectData, $options, $platformsData, $logger, $debugLiveSyncService, $config);
super($iOSDebugService, $devicesService, $debugDataService, $platformService, $projectData, $options, $platformsData, $logger,
$errors, $debugLiveSyncService, $config);
// Do not dispose ios-device-lib, so the process will remain alive and the debug application (NativeScript Inspector or Chrome DevTools) will be able to connect to the socket.
// In case we dispose ios-device-lib, the socket will be closed and the code will fail when the debug application tries to read/send data to device socket.
// That's why the `$ tns debug ios --justlaunch` command will not release the terminal.
Expand All @@ -132,7 +142,7 @@ export class DebugIOSCommand extends DebugPlatformCommand {
$injector.registerCommand("debug|ios", DebugIOSCommand);

export class DebugAndroidCommand extends DebugPlatformCommand {
constructor(private $errors: IErrors,
constructor(protected $errors: IErrors,
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
$logger: ILogger,
$androidDebugService: IPlatformDebugService,
Expand All @@ -144,14 +154,11 @@ export class DebugAndroidCommand extends DebugPlatformCommand {
$projectData: IProjectData,
$platformsData: IPlatformsData,
$debugLiveSyncService: IDebugLiveSyncService) {
super($androidDebugService, $devicesService, $debugDataService, $platformService, $projectData, $options, $platformsData, $logger, $debugLiveSyncService, $config);
super($androidDebugService, $devicesService, $debugDataService, $platformService, $projectData, $options, $platformsData, $logger,
$errors, $debugLiveSyncService, $config);
}

public async canExecute(args: string[]): Promise<boolean> {
if (!this.$platformService.isPlatformSupportedForOS(this.$devicePlatformsConstants.Android, this.$projectData)) {
this.$errors.fail(`Applications for platform ${this.$devicePlatformsConstants.Android} can not be built on this OS`);
}

return await super.canExecute(args) && await this.$platformService.validateOptions(this.$options.provision, this.$projectData, this.$platformsData.availablePlatforms.Android);
}

Expand Down
7 changes: 6 additions & 1 deletion lib/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export class DeployOnDeviceCommand implements ICommand {
private $options: IOptions,
private $projectData: IProjectData,
private $errors: IErrors,
private $mobileHelper: Mobile.IMobileHelper) {
private $mobileHelper: Mobile.IMobileHelper,
private $platformsData: IPlatformsData) {
this.$projectData.initializeProjectData();
}

Expand Down Expand Up @@ -43,6 +44,10 @@ export class DeployOnDeviceCommand implements ICommand {
this.$errors.fail("When producing a release build, you need to specify all --key-store-* options.");
}

const platformData = this.$platformsData.getPlatformData(args[0], this.$projectData);
const platformProjectService = platformData.platformProjectService;
await platformProjectService.validate(this.$projectData);

return this.$platformService.validateOptions(this.$options.provision, this.$projectData, args[0]);
}
}
Expand Down
3 changes: 3 additions & 0 deletions lib/commands/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export class InstallCommand implements ICommand {
const frameworkPackageData = this.$projectDataService.getNSValue(this.$projectData.projectDir, platformData.frameworkPackageName);
if (frameworkPackageData && frameworkPackageData.version) {
try {
const platformProjectService = platformData.platformProjectService;
await platformProjectService.validate(this.$projectData);

await this.$platformService.addPlatforms([`${platform}@${frameworkPackageData.version}`], this.$options.platformTemplate, this.$projectData, this.$options, this.$options.frameworkPath);
} catch (err) {
error = `${error}${EOL}${err}`;
Expand Down
11 changes: 9 additions & 2 deletions lib/commands/platform-clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export class CleanCommand implements ICommand {
constructor(private $options: IOptions,
private $projectData: IProjectData,
private $platformService: IPlatformService,
private $errors: IErrors) {
private $errors: IErrors,
private $platformsData: IPlatformsData) {
this.$projectData.initializeProjectData();
}

Expand All @@ -17,7 +18,13 @@ export class CleanCommand implements ICommand {
this.$errors.fail("No platform specified. Please specify a platform to clean");
}

_.each(args, arg => this.$platformService.validatePlatformInstalled(arg, this.$projectData));
for (let platform of args) {
this.$platformService.validatePlatformInstalled(platform, this.$projectData);

const platformData = this.$platformsData.getPlatformData(platform, this.$projectData);
const platformProjectService = platformData.platformProjectService;
await platformProjectService.validate(this.$projectData);
}

return true;
}
Expand Down
13 changes: 11 additions & 2 deletions lib/commands/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export class PrepareCommand implements ICommand {
constructor(private $options: IOptions,
private $platformService: IPlatformService,
private $projectData: IProjectData,
private $platformCommandParameter: ICommandParameter) {
private $platformCommandParameter: ICommandParameter,
private $platformsData: IPlatformsData) {
this.$projectData.initializeProjectData();
}

Expand All @@ -14,7 +15,15 @@ export class PrepareCommand implements ICommand {
}

public async canExecute(args: string[]): Promise<boolean> {
return await this.$platformCommandParameter.validate(args[0]) && await this.$platformService.validateOptions(this.$options.provision, this.$projectData, args[0]);
const platform = args[0];
const result = await this.$platformCommandParameter.validate(platform) && await this.$platformService.validateOptions(this.$options.provision, this.$projectData, platform);
if (result) {
const platformData = this.$platformsData.getPlatformData(platform, this.$projectData);
const platformProjectService = platformData.platformProjectService;
await platformProjectService.validate(this.$projectData);
}

return result;
}
}

Expand Down
14 changes: 10 additions & 4 deletions lib/commands/remove-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ export class RemovePlatformCommand implements ICommand {

constructor(private $platformService: IPlatformService,
private $projectData: IProjectData,
private $errors: IErrors) {
this.$projectData.initializeProjectData();
}
private $errors: IErrors,
private $platformsData: IPlatformsData) {
this.$projectData.initializeProjectData();
}

public execute(args: string[]): Promise<void> {
return this.$platformService.removePlatforms(args, this.$projectData);
Expand All @@ -16,7 +17,12 @@ export class RemovePlatformCommand implements ICommand {
this.$errors.fail("No platform specified. Please specify a platform to remove");
}

_.each(args, arg => this.$platformService.validatePlatformInstalled(arg, this.$projectData));
for (let platform of args) {
this.$platformService.validatePlatformInstalled(platform, this.$projectData);
const platformData = this.$platformsData.getPlatformData(platform, this.$projectData);
const platformProjectService = platformData.platformProjectService;
await platformProjectService.validate(this.$projectData);
}

return true;
}
Expand Down
21 changes: 16 additions & 5 deletions lib/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export class RunCommandBase implements ICommand {
private $devicesService: Mobile.IDevicesService,
private $hostInfo: IHostInfo,
private $iosDeviceOperations: IIOSDeviceOperations,
private $mobileHelper: Mobile.IMobileHelper) {
private $mobileHelper: Mobile.IMobileHelper,
protected $platformsData: IPlatformsData) {
}

public allowedParameters: ICommandParameter[] = [];
Expand All @@ -31,6 +32,13 @@ export class RunCommandBase implements ICommand {
this.platform = this.$devicePlatformsConstants.Android;
}

const availablePlatforms = this.platform ? [this.platform] : this.$platformsData.availablePlatforms;
for (let platform of availablePlatforms) {
const platformData = this.$platformsData.getPlatformData(platform, this.$projectData);
const platformProjectService = platformData.platformProjectService;
await platformProjectService.validate(this.$projectData);
}

return true;
}

Expand All @@ -46,6 +54,7 @@ export class RunCommandBase implements ICommand {
skipDeviceDetectionInterval: true,
skipInferPlatform: !this.platform
});

await this.$devicesService.detectCurrentlyAttachedDevices();

const devices = this.$devicesService.getDeviceInstances();
Expand Down Expand Up @@ -118,7 +127,7 @@ export class RunIosCommand extends RunCommandBase implements ICommand {
}

constructor($platformService: IPlatformService,
private $platformsData: IPlatformsData,
protected $platformsData: IPlatformsData,
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
protected $errors: IErrors,
$liveSyncService: ILiveSyncService,
Expand All @@ -129,7 +138,8 @@ export class RunIosCommand extends RunCommandBase implements ICommand {
$hostInfo: IHostInfo,
$iosDeviceOperations: IIOSDeviceOperations,
$mobileHelper: Mobile.IMobileHelper) {
super($platformService, $liveSyncService, $projectData, $options, $emulatorPlatformService, $devicePlatformsConstants, $errors, $devicesService, $hostInfo, $iosDeviceOperations, $mobileHelper);
super($platformService, $liveSyncService, $projectData, $options, $emulatorPlatformService, $devicePlatformsConstants, $errors,
$devicesService, $hostInfo, $iosDeviceOperations, $mobileHelper, $platformsData);
}

public async execute(args: string[]): Promise<void> {
Expand All @@ -154,7 +164,7 @@ export class RunAndroidCommand extends RunCommandBase implements ICommand {
}

constructor($platformService: IPlatformService,
private $platformsData: IPlatformsData,
protected $platformsData: IPlatformsData,
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
protected $errors: IErrors,
$liveSyncService: ILiveSyncService,
Expand All @@ -165,7 +175,8 @@ export class RunAndroidCommand extends RunCommandBase implements ICommand {
$hostInfo: IHostInfo,
$iosDeviceOperations: IIOSDeviceOperations,
$mobileHelper: Mobile.IMobileHelper) {
super($platformService, $liveSyncService, $projectData, $options, $emulatorPlatformService, $devicePlatformsConstants, $errors, $devicesService, $hostInfo, $iosDeviceOperations, $mobileHelper);
super($platformService, $liveSyncService, $projectData, $options, $emulatorPlatformService, $devicePlatformsConstants, $errors,
$devicesService, $hostInfo, $iosDeviceOperations, $mobileHelper, $platformsData);
}

public async execute(args: string[]): Promise<void> {
Expand Down
Loading