Skip to content

Separate preparation of JS from native code #2983

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

Merged
merged 9 commits into from
Jul 20, 2017
1 change: 1 addition & 0 deletions lib/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ $injector.require("devicePathProvider", "./device-path-provider");
$injector.requireCommand("platform|clean", "./commands/platform-clean");

$injector.requirePublicClass("liveSyncService", "./services/livesync/livesync-service");
$injector.require("liveSyncCommandHelper", "./services/livesync/livesync-command-helper");
$injector.require("debugLiveSyncService", "./services/livesync/debug-livesync-service");
$injector.require("androidLiveSyncService", "./services/livesync/android-livesync-service");
$injector.require("iOSLiveSyncService", "./services/livesync/ios-livesync-service");
Expand Down
122 changes: 50 additions & 72 deletions lib/commands/debug.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import { CONNECTED_STATUS } from "../common/constants";
import { isInteractive } from "../common/helpers";
import { cache } from "../common/decorators";
import { DebugCommandErrors } from "../constants";

export abstract class DebugPlatformCommand implements ICommand {
export class DebugPlatformCommand implements ICommand {
public allowedParameters: ICommandParameter[] = [];
public platform: string;

constructor(private debugService: IPlatformDebugService,
private $devicesService: Mobile.IDevicesService,
private $debugDataService: IDebugDataService,
private platform: string,
protected $devicesService: Mobile.IDevicesService,
protected $platformService: IPlatformService,
protected $projectData: IProjectData,
protected $options: IOptions,
protected $platformsData: IPlatformsData,
protected $logger: ILogger,
protected $errors: IErrors,
private $debugDataService: IDebugDataService,
private $debugLiveSyncService: IDebugLiveSyncService,
private $config: IConfiguration,
private $prompter: IPrompter) {
this.$projectData.initializeProjectData();
private $prompter: IPrompter,
private $liveSyncCommandHelper: ILiveSyncCommandHelper) {
}

public async execute(args: string[]): Promise<void> {
Expand All @@ -36,41 +37,7 @@ export abstract class DebugPlatformCommand implements ICommand {

const selectedDeviceForDebug = await this.getDeviceForDebug();

const deviceDescriptors: ILiveSyncDeviceInfo[] = [selectedDeviceForDebug]
.map(d => {
const info: ILiveSyncDeviceInfo = {
identifier: d.deviceInfo.identifier,
buildAction: async (): Promise<string> => {
const buildConfig: IBuildConfig = {
buildForDevice: !d.isEmulator,
projectDir: this.$options.path,
clean: this.$options.clean,
teamId: this.$options.teamId,
device: this.$options.device,
provision: this.$options.provision,
release: this.$options.release,
keyStoreAlias: this.$options.keyStoreAlias,
keyStorePath: this.$options.keyStorePath,
keyStoreAliasPassword: this.$options.keyStoreAliasPassword,
keyStorePassword: this.$options.keyStorePassword
};

await this.$platformService.buildPlatform(d.deviceInfo.platform, buildConfig, this.$projectData);
const pathToBuildResult = await this.$platformService.lastOutputPath(d.deviceInfo.platform, buildConfig, this.$projectData);
return pathToBuildResult;
}
};

return info;
});

const liveSyncInfo: ILiveSyncInfo = {
projectDir: this.$projectData.projectDir,
skipWatcher: !this.$options.watch || this.$options.justlaunch,
watchAllFiles: this.$options.syncAllFiles
};

await this.$debugLiveSyncService.liveSync(deviceDescriptors, liveSyncInfo);
await this.$liveSyncCommandHelper.getDevicesLiveSyncInfo([selectedDeviceForDebug], this.$debugLiveSyncService, this.platform);
}

public async getDeviceForDebug(): Promise<Mobile.IDevice> {
Expand Down Expand Up @@ -149,63 +116,74 @@ export abstract class DebugPlatformCommand implements ICommand {
}
}

export class DebugIOSCommand extends DebugPlatformCommand {
export class DebugIOSCommand implements ICommand {

@cache()
private get debugPlatformCommand(): DebugPlatformCommand {
return this.$injector.resolve<DebugPlatformCommand>(DebugPlatformCommand, { debugService: this.$iOSDebugService, platform: this.platform });
}

public allowedParameters: ICommandParameter[] = [];

constructor(protected $errors: IErrors,
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
$logger: ILogger,
$iOSDebugService: IPlatformDebugService,
$devicesService: Mobile.IDevicesService,
$config: IConfiguration,
$debugDataService: IDebugDataService,
$platformService: IPlatformService,
$options: IOptions,
$projectData: IProjectData,
$platformsData: IPlatformsData,
$iosDeviceOperations: IIOSDeviceOperations,
$debugLiveSyncService: IDebugLiveSyncService,
$prompter: IPrompter) {
super($iOSDebugService, $devicesService, $debugDataService, $platformService, $projectData, $options, $platformsData, $logger,
$errors, $debugLiveSyncService, $config, $prompter);
private $platformService: IPlatformService,
private $options: IOptions,
private $injector: IInjector,
private $projectData: IProjectData,
private $platformsData: IPlatformsData,
private $iOSDebugService: IDebugService,
$iosDeviceOperations: IIOSDeviceOperations) {
this.$projectData.initializeProjectData();
// 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.
// In case we do not set it to false, the dispose will be called once the command finishes its execution, which will prevent the debugging.
$iosDeviceOperations.setShouldDispose(false);
}

public execute(args: string[]): Promise<void> {
return this.debugPlatformCommand.execute(args);
}

public async canExecute(args: string[]): Promise<boolean> {
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 await super.canExecute(args) && await this.$platformService.validateOptions(this.$options.provision, this.$projectData, this.$platformsData.availablePlatforms.iOS);
return await this.debugPlatformCommand.canExecute(args) && await this.$platformService.validateOptions(this.$options.provision, this.$projectData, this.$platformsData.availablePlatforms.iOS);
}

public platform = this.$devicePlatformsConstants.iOS;
}

$injector.registerCommand("debug|ios", DebugIOSCommand);

export class DebugAndroidCommand extends DebugPlatformCommand {
export class DebugAndroidCommand implements ICommand {

@cache()
private get debugPlatformCommand(): DebugPlatformCommand {
return this.$injector.resolve<DebugPlatformCommand>(DebugPlatformCommand, { debugService: this.$androidDebugService, platform: this.platform });
}

public allowedParameters: ICommandParameter[] = [];

constructor(protected $errors: IErrors,
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
$logger: ILogger,
$androidDebugService: IPlatformDebugService,
$devicesService: Mobile.IDevicesService,
$config: IConfiguration,
$debugDataService: IDebugDataService,
$platformService: IPlatformService,
$options: IOptions,
$projectData: IProjectData,
$platformsData: IPlatformsData,
$debugLiveSyncService: IDebugLiveSyncService,
$prompter: IPrompter) {
super($androidDebugService, $devicesService, $debugDataService, $platformService, $projectData, $options, $platformsData, $logger,
$errors, $debugLiveSyncService, $config, $prompter);
private $platformService: IPlatformService,
private $options: IOptions,
private $injector: IInjector,
private $projectData: IProjectData,
private $platformsData: IPlatformsData,
private $androidDebugService: IDebugService) {
this.$projectData.initializeProjectData();
}

public execute(args: string[]): Promise<void> {
return this.debugPlatformCommand.execute(args);
}
public async canExecute(args: string[]): Promise<boolean> {
return await super.canExecute(args) && await this.$platformService.validateOptions(this.$options.provision, this.$projectData, this.$platformsData.availablePlatforms.Android);
return await this.debugPlatformCommand.canExecute(args) && await this.$platformService.validateOptions(this.$options.provision, this.$projectData, this.$platformsData.availablePlatforms.Android);
}

public platform = this.$devicePlatformsConstants.Android;
Expand Down
Loading