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.requirePublicClass("liveSyncCommandHelper", "./services/livesync/livesync-command-helper");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be require

$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
121 changes: 50 additions & 71 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,40 +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
};

const { deviceDescriptors, liveSyncInfo } = await this.$liveSyncCommandHelper.getDevicesLiveSyncInfo(args, [selectedDeviceForDebug]);
await this.$debugLiveSyncService.liveSync(deviceDescriptors, liveSyncInfo);
}

Expand Down Expand Up @@ -149,63 +117,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
135 changes: 38 additions & 97 deletions lib/commands/run.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ERROR_NO_VALID_SUBCOMMAND_FORMAT } from "../common/constants";
import { cache } from "../common/decorators";

export class RunCommandBase implements ICommand {
protected platform: string;
Expand All @@ -7,15 +8,13 @@ export class RunCommandBase implements ICommand {
protected $liveSyncService: ILiveSyncService,
protected $projectData: IProjectData,
protected $options: IOptions,
protected $emulatorPlatformService: IEmulatorPlatformService,
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
protected $errors: IErrors,
private $devicesService: Mobile.IDevicesService,
protected $devicesService: Mobile.IDevicesService,
protected $platformsData: IPlatformsData,
private $hostInfo: IHostInfo,
private $iosDeviceOperations: IIOSDeviceOperations,
private $mobileHelper: Mobile.IMobileHelper,
protected $platformsData: IPlatformsData) {
}
private $liveSyncCommandHelper: ILiveSyncCommandHelper
) { }

public allowedParameters: ICommandParameter[] = [];
public async execute(args: string[]): Promise<void> {
Expand Down Expand Up @@ -47,6 +46,8 @@ export class RunCommandBase implements ICommand {
this.$options.watch = false;
}

this.platform = args[0] || this.platform;

await this.$devicesService.initialize({
deviceId: this.$options.device,
platform: this.platform,
Expand All @@ -56,138 +57,78 @@ export class RunCommandBase implements ICommand {
});

await this.$devicesService.detectCurrentlyAttachedDevices();

const devices = this.$devicesService.getDeviceInstances();
// Now let's take data for each device:
const deviceDescriptors: ILiveSyncDeviceInfo[] = devices.filter(d => !this.platform || d.deviceInfo.platform === this.platform)
.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 workingWithiOSDevices = !this.platform || this.$mobileHelper.isiOSPlatform(this.platform);
const shouldKeepProcessAlive = this.$options.watch || !this.$options.justlaunch;
if (workingWithiOSDevices && shouldKeepProcessAlive) {
this.$iosDeviceOperations.setShouldDispose(false);
}

if (this.$options.release || this.$options.bundle) {
const runPlatformOptions: IRunPlatformOptions = {
device: this.$options.device,
emulator: this.$options.emulator,
justlaunch: this.$options.justlaunch
};

const deployOptions = _.merge<IDeployPlatformOptions>({
projectDir: this.$projectData.projectDir,
clean: true,
}, this.$options.argv);

await this.$platformService.deployPlatform(args[0], this.$options, deployOptions, this.$projectData, this.$options);
await this.$platformService.startApplication(args[0], runPlatformOptions, this.$projectData.projectId);
return this.$platformService.trackProjectType(this.$projectData);
}

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

let devices = this.$devicesService.getDeviceInstances();
devices = devices.filter(d => !this.platform || d.deviceInfo.platform.toLowerCase() === this.platform.toLowerCase());
const { deviceDescriptors, liveSyncInfo } = await this.$liveSyncCommandHelper.getDevicesLiveSyncInfo(args, devices);
await this.$liveSyncService.liveSync(deviceDescriptors, liveSyncInfo);
}
}

$injector.registerCommand("run|*all", RunCommandBase);

export class RunIosCommand extends RunCommandBase implements ICommand {
export class RunIosCommand implements ICommand {

@cache()
private get runCommand(): RunCommandBase {
return this.$injector.resolve<RunCommandBase>(RunCommandBase);
}

public allowedParameters: ICommandParameter[] = [];
public get platform(): string {
return this.$devicePlatformsConstants.iOS;
}

constructor($platformService: IPlatformService,
protected $platformsData: IPlatformsData,
constructor(protected $platformsData: IPlatformsData,
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
protected $errors: IErrors,
$liveSyncService: ILiveSyncService,
$projectData: IProjectData,
$options: IOptions,
$emulatorPlatformService: IEmulatorPlatformService,
$devicesService: Mobile.IDevicesService,
$hostInfo: IHostInfo,
$iosDeviceOperations: IIOSDeviceOperations,
$mobileHelper: Mobile.IMobileHelper) {
super($platformService, $liveSyncService, $projectData, $options, $emulatorPlatformService, $devicePlatformsConstants, $errors,
$devicesService, $hostInfo, $iosDeviceOperations, $mobileHelper, $platformsData);
private $injector: IInjector,
private $platformService: IPlatformService,
private $projectData: IProjectData,
private $options: IOptions) {
}

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 this.executeCore([this.$platformsData.availablePlatforms.iOS]);
return this.runCommand.executeCore([this.$platformsData.availablePlatforms.iOS]);
}

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

$injector.registerCommand("run|ios", RunIosCommand);

export class RunAndroidCommand extends RunCommandBase implements ICommand {
export class RunAndroidCommand implements ICommand {

@cache()
private get runCommand(): RunCommandBase {
return this.$injector.resolve<RunCommandBase>(RunCommandBase);
}

public allowedParameters: ICommandParameter[] = [];
public get platform(): string {
return this.$devicePlatformsConstants.Android;
}

constructor($platformService: IPlatformService,
protected $platformsData: IPlatformsData,
constructor(protected $platformsData: IPlatformsData,
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
protected $errors: IErrors,
$liveSyncService: ILiveSyncService,
$projectData: IProjectData,
$options: IOptions,
$emulatorPlatformService: IEmulatorPlatformService,
$devicesService: Mobile.IDevicesService,
$hostInfo: IHostInfo,
$iosDeviceOperations: IIOSDeviceOperations,
$mobileHelper: Mobile.IMobileHelper) {
super($platformService, $liveSyncService, $projectData, $options, $emulatorPlatformService, $devicePlatformsConstants, $errors,
$devicesService, $hostInfo, $iosDeviceOperations, $mobileHelper, $platformsData);
private $injector: IInjector,
private $platformService: IPlatformService,
private $projectData: IProjectData,
private $options: IOptions) {
}

public async execute(args: string[]): Promise<void> {
return this.executeCore([this.$platformsData.availablePlatforms.Android]);
return this.runCommand.executeCore([this.$platformsData.availablePlatforms.Android]);
}

public async canExecute(args: string[]): Promise<boolean> {
await super.canExecute(args);
await this.runCommand.canExecute(args);
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`);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/common
Submodule common updated 1 files
+5 −0 helpers.ts
Loading