Remove the cloud-emulators related code
This commit is contained in:
Родитель
5022dba67d
Коммит
2096b6b6b5
|
@ -201,8 +201,7 @@ module.exports = function (grunt) {
|
|||
const pathToIosDeviceLib = fs.existsSync(rootPathToIosDeviceLib) ? rootPathToIosDeviceLib : path.join(nodeModulesDirPath, nativescript, node_modules, iOSDeviceLib);
|
||||
|
||||
const pathsOfDtsFiles = getReferencesFromDir(path.join(nodeModulesDirPath, nativescript))
|
||||
.concat(getReferencesFromDir(pathToIosDeviceLib))
|
||||
.concat(getReferencesFromDir(path.join(nodeModulesDirPath, "cloud-device-emulator")));
|
||||
.concat(getReferencesFromDir(pathToIosDeviceLib));
|
||||
|
||||
const lines = pathsOfDtsFiles.map(file => `/// <reference path="${fromWindowsRelativePathToUnix(path.relative(__dirname, file))}" />`);
|
||||
|
||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
54
README.md
54
README.md
|
@ -39,7 +39,7 @@ tns.extensibilityService.installExtension("nativescript-cloud@latest")
|
|||
* [nsCloudApplicationService](#nscloudapplicationservice)
|
||||
* [shouldBuild](#shouldbuild)
|
||||
* [shouldInstall](#shouldinstall)
|
||||
* [nsCloudEmulatorLauncher](#nscloudemulatorlauncher)
|
||||
* [nsCloudAuthenticationService](#nsCloudAuthenticationService)
|
||||
* [login](#login)
|
||||
* [logout](#logout)
|
||||
* [isUserLoggedIn](#isuserloggedin)
|
||||
|
@ -463,58 +463,6 @@ tns.nsCloudPublishService
|
|||
.catch(err => console.error(err));
|
||||
```
|
||||
|
||||
### nsCloudEmulatorLauncher
|
||||
The `nsCloudEmulatorLauncher` provides a way for initial interaction with cloud emulators. You can call the following methods:
|
||||
* `startEmulator` method - starts an cloud emulator and returns a url where an html page is located, containing an iframe with the actual emulator. </br>
|
||||
Definition:
|
||||
|
||||
```TypeScript
|
||||
/**
|
||||
* Describes options that can be passed when starting a cloud emulator.
|
||||
*/
|
||||
interface ICloudEmulatorStartData {
|
||||
/**
|
||||
* Path to the package file (.apk or .zip) to load - can either be a local path or a url.
|
||||
*/
|
||||
packageFile: string;
|
||||
/**
|
||||
* Platform for the emulator - android or ios
|
||||
*/
|
||||
platform: string;
|
||||
/**
|
||||
* Model of the emulator - for example nexus5, iphone5s, iphone6 - etc
|
||||
*/
|
||||
model: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes service for initial interaction with cloud emulators.
|
||||
*/
|
||||
interface ICloudEmulatorLauncher {
|
||||
/**
|
||||
* Starts a cloud emulator.
|
||||
* @param {ICloudEmulatorStartData} data Options for starting emulator.
|
||||
* @param optional {IConfigOptions} options The config options.
|
||||
* @returns {string} A url containing an html page with the emulator inside an iframe. The url's host is localhost.
|
||||
*/
|
||||
startEmulator(data: ICloudEmulatorStartData): Promise<string>;
|
||||
}
|
||||
|
||||
```
|
||||
Usage:
|
||||
```JavaScript
|
||||
const tns = require("nativescript");
|
||||
|
||||
tns.nsCloudEmulatorLauncher.startEmulator({
|
||||
packageFile: "test.apk",
|
||||
platform: "android",
|
||||
model: "nexus5"
|
||||
}).then(address => {
|
||||
console.log("address is", address);
|
||||
// http://localhost:56760/?publicKey=somekey&device=nexus5
|
||||
});
|
||||
```
|
||||
|
||||
### nsCloudAuthenticationService
|
||||
The `nsCloudAuthenticationService` is used for authentication related operations (login, logout etc.). You can call the following methods </br>
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ import * as path from "path";
|
|||
$injector.require("nsCloudHttpServer", path.join(__dirname, "http-server"));
|
||||
$injector.require("nsCloudItmsServicesPlistHelper", path.join(__dirname, "itms-services-plist-helper"));
|
||||
$injector.require("nsCloudOutputFilter", path.join(__dirname, "cloud-output-filter"));
|
||||
$injector.require("nsCloudDeviceEmulator", path.join(__dirname, "cloud-device-emulator"));
|
||||
$injector.require("nsCloudOptionsProvider", path.join(__dirname, "cloud-options-provider"));
|
||||
$injector.require("nsCloudBuildHelper", path.join(__dirname, "cloud-build-helper"));
|
||||
$injector.require("nsAccountUtils", path.join(__dirname, "account-utils"));
|
||||
|
@ -20,15 +19,11 @@ $injector.require("nsCloudOperationFactory", path.join(__dirname, "cloud-operati
|
|||
$injector.require("nsCloudCommunicationChannelFactory", path.join(__dirname, "cloud-operation", "communication", "communication-channel-factory"));
|
||||
$injector.require("nsCloudWebSocketFactory", path.join(__dirname, "cloud-operation", "communication", "websocket-factory"));
|
||||
|
||||
// Mobile.
|
||||
$injector.require("nsCloudEmulatorDeviceDiscovery", path.join(__dirname, "mobile", "mobile-core", "cloud-emulator-device-discovery"));
|
||||
|
||||
// Public API.
|
||||
$injector.requirePublicClass("nsCloudApplicationService", path.join(__dirname, "services", "application-service"));
|
||||
$injector.requirePublicClass("nsCloudAuthenticationService", path.join(__dirname, "services", "authentication-service"));
|
||||
$injector.requirePublicClass("nsCloudBuildService", path.join(__dirname, "services", "cloud-build-service"));
|
||||
$injector.requirePublicClass("nsCloudCodesignService", path.join(__dirname, "services", "cloud-codesign-service"));
|
||||
$injector.requirePublicClass("nsCloudEmulatorLauncher", path.join(__dirname, "services", "cloud-emulator-emulator-launcher"));
|
||||
$injector.requirePublicClass("nsCloudPublishService", path.join(__dirname, "services", "cloud-publish-service"));
|
||||
$injector.requirePublicClass("nsCloudProjectService", path.join(__dirname, "services", "cloud-project-service"));
|
||||
$injector.requirePublicClass("nsCloudUserService", path.join(__dirname, "services", "user-service"));
|
||||
|
@ -46,7 +41,6 @@ $injector.require("nsCloudServerAuthService", path.join(__dirname, "services", "
|
|||
$injector.require("nsCloudServerBuildService", path.join(__dirname, "services", "server", "server-build-service"));
|
||||
$injector.require("nsCloudServerServicesProxy", path.join(__dirname, "services", "server", "server-services-proxy"));
|
||||
$injector.require("nsCloudServerRequestService", path.join(__dirname, "services", "server", "server-request-service"));
|
||||
$injector.require("nsCloudServerEmulatorsService", path.join(__dirname, "services", "server", "server-emulators-service"));
|
||||
$injector.require("nsCloudServerAccountsService", path.join(__dirname, "services", "server", "server-accounts-service"));
|
||||
$injector.require("nsCloudServerProjectService", path.join(__dirname, "services", "server", "server-project-service"));
|
||||
$injector.require("nsCloudKinveyRequestService", path.join(__dirname, "services", "server", "mbaas", "kinvey-request-service"));
|
||||
|
@ -76,7 +70,6 @@ $injector.requireCommand("logout", path.join(__dirname, "commands", "logout"));
|
|||
$injector.requireCommand("cloud|dev-apple-login", path.join(__dirname, "commands", "cloud-dev-apple-login"));
|
||||
|
||||
$injector.requireCommand("user", path.join(__dirname, "commands", "user"));
|
||||
$injector.requireCommand("kill-server", path.join(__dirname, "commands", "kill-server"));
|
||||
|
||||
$injector.requireCommand(["deploy|cloud", "cloud|deploy"], path.join(__dirname, "commands", "cloud-deploy"));
|
||||
$injector.requireCommand(["run|cloud|*all", "cloud|run|*all"], path.join(__dirname, "commands", "cloud-run"));
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
export class CloudDeviceEmulatorWrapper implements ICloudDeviceEmulator {
|
||||
private _isCloudDeviceEmulatorInstanceInitialized = false;
|
||||
private get cloudDeviceEmulatorInstance(): ICloudDeviceEmulator {
|
||||
this._isCloudDeviceEmulatorInstanceInitialized = true;
|
||||
return require("cloud-device-emulator");
|
||||
}
|
||||
|
||||
public get deviceEmitter(): CloudDeviceEmitter {
|
||||
return this.cloudDeviceEmulatorInstance.deviceEmitter;
|
||||
}
|
||||
|
||||
constructor(private $options: IOptions,
|
||||
private $usbLiveSyncService: any,
|
||||
private $processService: IProcessService) {
|
||||
this.$processService.attachToProcessExitSignals(this, this._dispose);
|
||||
}
|
||||
|
||||
public getSeverAddress(): Promise<ICloudDeviceServerInfo> {
|
||||
return this.cloudDeviceEmulatorInstance.getSeverAddress();
|
||||
}
|
||||
|
||||
public refresh(deviceIdentifier: string): Promise<void> {
|
||||
return this.cloudDeviceEmulatorInstance.refresh(deviceIdentifier);
|
||||
}
|
||||
|
||||
public killServer(): Promise<any> {
|
||||
return this.cloudDeviceEmulatorInstance.killServer();
|
||||
}
|
||||
|
||||
public dispose() {
|
||||
if (!this.$options.watch || !this.$usbLiveSyncService.isInitialized) {
|
||||
this._dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private _dispose() {
|
||||
if (this._isCloudDeviceEmulatorInstanceInitialized) {
|
||||
this.cloudDeviceEmulatorInstance.deviceEmitter.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$injector.register("nsCloudDeviceEmulator", CloudDeviceEmulatorWrapper);
|
|
@ -1,13 +0,0 @@
|
|||
export class KillServer implements ICommand {
|
||||
public allowedParameters: ICommandParameter[] = [];
|
||||
|
||||
constructor(private $nsCloudDeviceEmulator: ICloudDeviceEmulator,
|
||||
private $logger: ILogger) { }
|
||||
|
||||
public async execute(args: string[]): Promise<void> {
|
||||
this.$logger.info("Killing server");
|
||||
await this.$nsCloudDeviceEmulator.killServer();
|
||||
}
|
||||
}
|
||||
|
||||
$injector.registerCommand("kill-server", KillServer);
|
|
@ -21,7 +21,6 @@ export const PROVISION_TYPES = {
|
|||
|
||||
export const AUTH_SERVICE_NAME = "auth-service";
|
||||
export const BUILD_SERVICE_NAME = "build-service";
|
||||
export const EMULATORS_SERVICE_NAME = "emulators-service";
|
||||
export const MISC_SERVICE_NAME = "misc-service";
|
||||
export const ACCOUNTS_SERVICE_NAME = "accounts-service";
|
||||
export const PROJECT_SERVICE_NAME = "project-service";
|
||||
|
@ -49,12 +48,6 @@ export const CLOUD_BUILD_DIRECTORY_NAMES = {
|
|||
EMULATOR: "emulator"
|
||||
};
|
||||
|
||||
export const DEVICE_INFO = {
|
||||
TYPE: "Emulator",
|
||||
STATUS: "Connected",
|
||||
VENDOR: "Cloud Emulator"
|
||||
};
|
||||
|
||||
export const CONTENT_TYPES = {
|
||||
APPLICATION_JSON: "application/json",
|
||||
TEXT_HTML: "text/html",
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
/**
|
||||
* Describes options that can be passed when starting a cloud emulator.
|
||||
*/
|
||||
interface ICloudEmulatorStartData extends IPlatform {
|
||||
/**
|
||||
* Path to the package file (.apk or .zip) to load - can either be a local path or a url.
|
||||
*/
|
||||
packageFile: string;
|
||||
/**
|
||||
* Model of the emulator - for example nexus5, iphone5s, iphone6 - etc
|
||||
*/
|
||||
model: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes service for initial interaction with cloud emulators.
|
||||
*/
|
||||
interface ICloudEmulatorLauncher {
|
||||
/**
|
||||
* Starts a cloud emulator.
|
||||
* @param {ICloudEmulatorStartData} data Options for starting emulator.
|
||||
* @param optional {IConfigOptions} options The config options.
|
||||
* @returns {string} A url containing an html page with the emulator inside an iframe. The url's host is localhost.
|
||||
*/
|
||||
startEmulator(data: ICloudEmulatorStartData): Promise<string>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes service for interaction with server which communicates with cloud emulators.
|
||||
*/
|
||||
interface ICloudDeviceEmulator extends IDisposable {
|
||||
/**
|
||||
* Event emitter instance that raises events upon finding/losing a device.
|
||||
*/
|
||||
deviceEmitter: CloudDeviceEmitter;
|
||||
|
||||
/**
|
||||
* Retrieves information about the currently running server for communication with cloud emulators.
|
||||
* @returns {Promise<ICloudDeviceServerInfo>} Information about the server.
|
||||
*/
|
||||
getSeverAddress(): Promise<ICloudDeviceServerInfo>;
|
||||
|
||||
/**
|
||||
* Refreshes a cloud emulator.
|
||||
* @param {string} deviceIdentifier The device's identifier.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
refresh(deviceIdentifier: string): Promise<void>;
|
||||
|
||||
/**
|
||||
* Disposes the cloud-device-emulator package.
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
killServer(): Promise<any>;
|
||||
}
|
|
@ -13,45 +13,16 @@ interface IUploadService {
|
|||
uploadToS3(filePathOrContent: string, fileNameInS3?: string, uploadPreSignedUrl?: string): Promise<string>;
|
||||
}
|
||||
|
||||
interface IEmulatorCredentials {
|
||||
[key: string]: ICloudEmulatorKeys;
|
||||
}
|
||||
|
||||
interface IServerEmulatorsService {
|
||||
startEmulator(publicKey: string, platform: string, deviceType: string): Promise<any>;
|
||||
deployApp(fileLocation: string, platform: string): Promise<ICloudEmulatorResponse>;
|
||||
refereshEmulator(deviceIdentifier: string): Promise<void>;
|
||||
}
|
||||
|
||||
interface IAmazonStorageEntryData extends IAmazonStorageEntry {
|
||||
filePath: string;
|
||||
disposition: string;
|
||||
}
|
||||
|
||||
interface ICloudEmulatorResponse extends IPlatform {
|
||||
appPermissions: any;
|
||||
appURL: string;
|
||||
architectures: [string];
|
||||
created: Date;
|
||||
email: string;
|
||||
manageURL: string;
|
||||
privateKey: string;
|
||||
publicKey: string;
|
||||
publicURL: string;
|
||||
updated: Date;
|
||||
versionCode: Number;
|
||||
}
|
||||
|
||||
interface IPresignURLResponse {
|
||||
uploadPreSignedUrl: string;
|
||||
publicDownloadUrl: string;
|
||||
}
|
||||
|
||||
interface ICloudEmulatorKeys {
|
||||
publicKey: string;
|
||||
privateKey: string;
|
||||
}
|
||||
|
||||
interface IServerRequestService {
|
||||
call<T>(options: ICloudRequestOptions): Promise<T>;
|
||||
}
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
import { EventEmitter } from "events";
|
||||
|
||||
export class CloudEmulatorApplicationManager extends EventEmitter implements Mobile.IDeviceApplicationManager {
|
||||
|
||||
constructor(private basicInfo: ICloudEmulatorDeviceBasicInfo,
|
||||
private $nsCloudServerEmulatorsService: IServerEmulatorsService) {
|
||||
super();
|
||||
}
|
||||
|
||||
public async getInstalledApplications(): Promise<string[]> {
|
||||
return [];
|
||||
}
|
||||
|
||||
public async installApplication(packageFilePath: string): Promise<void> {
|
||||
await this.$nsCloudServerEmulatorsService.deployApp(packageFilePath, this.basicInfo.os);
|
||||
return this.$nsCloudServerEmulatorsService.refereshEmulator(this.basicInfo.identifier);
|
||||
}
|
||||
|
||||
public async isApplicationInstalled(appIdentifier: string): Promise<boolean> {
|
||||
return true;
|
||||
}
|
||||
|
||||
public async uninstallApplication(appIdentifier: string): Promise<void> { /* currently empty */ }
|
||||
|
||||
public async startApplication(appData: Mobile.IApplicationData): Promise<void> { /* currently empty */ }
|
||||
|
||||
public async stopApplication(appData: Mobile.IApplicationData): Promise<void> { /* currently empty */ }
|
||||
|
||||
public async getApplicationInfo(applicationIdentifier: string): Promise<Mobile.IApplicationInfo> {
|
||||
return null;
|
||||
}
|
||||
|
||||
public canStartApplication(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
public async isLiveSyncSupported(appIdentifier: string): Promise<boolean> {
|
||||
return false;
|
||||
}
|
||||
|
||||
public async getDebuggableApps(): Promise<Mobile.IDeviceApplicationInformation[]> {
|
||||
return [];
|
||||
}
|
||||
|
||||
public async getDebuggableAppViews(appIdentifiers: string[]): Promise<IDictionary<Mobile.IDebugWebViewInfo[]>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
public async reinstallApplication(appIdentifier: string, packageFilePath: string): Promise<void> {
|
||||
return this.installApplication(packageFilePath);
|
||||
}
|
||||
|
||||
public async restartApplication(appData: Mobile.IApplicationData): Promise<void> { /* currently empty */ }
|
||||
|
||||
public async checkForApplicationUpdates(): Promise<void> { /* currently empty */ }
|
||||
|
||||
public async tryStartApplication(appData: Mobile.IApplicationData): Promise<void> { /* currently empty */ }
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
export class CloudEmulatorDeviceFileSystem implements Mobile.IDeviceFileSystem {
|
||||
public async listFiles(devicePath: string, appIdentifier?: string): Promise<any> { /* currently empty */ }
|
||||
|
||||
public async getFile(deviceFilePath: string, appIdentifier: string, outputPath?: string): Promise<void> { /* currently empty */ }
|
||||
|
||||
public async putFile(localFilePath: string, deviceFilePath: string, appIdentifier: string): Promise<void> { /* currently empty */ }
|
||||
|
||||
public async transferFiles(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]): Promise<Mobile.ILocalToDevicePathData[]> { return []; }
|
||||
|
||||
public async transferDirectory(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string): Promise<Mobile.ILocalToDevicePathData[]> { return []; }
|
||||
|
||||
public async transferFile(localPath: string, devicePath: string): Promise<void> { /* currently empty */ }
|
||||
|
||||
public async createFileOnDevice(deviceFilePath: string, fileContent: string): Promise<void> { /* currently empty */ }
|
||||
|
||||
public async deleteFile(deviceFilePath: string, appIdentifier: string): Promise<void> { /* currently empty */ }
|
||||
|
||||
public async updateHashesOnDevice(hashes: IStringDictionary, appIdentifier: string): Promise<void> { /* currently empty */ }
|
||||
|
||||
public async getFileContent(deviceFilePath: string, appIdentifier: string): Promise<string> { return null; }
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
import { CloudEmulatorApplicationManager } from "./cloud-emulator-application-manager";
|
||||
import { CloudEmulatorDeviceFileSystem } from "./cloud-emulator-device-file-system";
|
||||
import { DEVICE_INFO } from "../../constants";
|
||||
|
||||
export class CloudEmulatorDevice implements Mobile.IDevice {
|
||||
public applicationManager: Mobile.IDeviceApplicationManager;
|
||||
public fileSystem: Mobile.IDeviceFileSystem;
|
||||
public deviceInfo: Mobile.IDeviceInfo;
|
||||
|
||||
constructor(private basicInfo: ICloudEmulatorDeviceBasicInfo,
|
||||
private $mobileHelper: Mobile.IMobileHelper,
|
||||
private $injector: IInjector) {
|
||||
this.init();
|
||||
}
|
||||
|
||||
public get isEmulator(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
public async openDeviceLogStream(): Promise<void> { /* currently empty */ }
|
||||
|
||||
public getApplicationInfo(applicationIdentifier: string): Promise<Mobile.IApplicationInfo> {
|
||||
const deviceInfo: Mobile.IApplicationInfo = {
|
||||
applicationIdentifier: applicationIdentifier,
|
||||
deviceIdentifier: this.basicInfo.identifier,
|
||||
configuration: "debug"
|
||||
};
|
||||
|
||||
return Promise.resolve(deviceInfo);
|
||||
}
|
||||
|
||||
private init(): void {
|
||||
this.applicationManager = this.$injector.resolve(CloudEmulatorApplicationManager, { basicInfo: this.basicInfo });
|
||||
this.fileSystem = this.$injector.resolve(CloudEmulatorDeviceFileSystem);
|
||||
this.deviceInfo = {
|
||||
identifier: this.basicInfo.identifier,
|
||||
model: this.basicInfo.model,
|
||||
platform: this.$mobileHelper.normalizePlatformName(this.basicInfo.os),
|
||||
isTablet: false,
|
||||
displayName: this.basicInfo.model,
|
||||
version: "",
|
||||
vendor: DEVICE_INFO.VENDOR,
|
||||
type: DEVICE_INFO.TYPE,
|
||||
errorHelp: "",
|
||||
status: DEVICE_INFO.STATUS
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
import { EventEmitter } from "events";
|
||||
import { DEVICE_DISCOVERY_EVENTS } from "../../constants";
|
||||
import { CloudEmulatorDevice } from "../device/cloud-emulator-device";
|
||||
|
||||
export class CloudEmulatorDeviceDiscovery extends EventEmitter implements Mobile.IDeviceDiscovery {
|
||||
private devices: IDictionary<Mobile.IDevice> = {};
|
||||
private _hasStartedLookingForDevices = false;
|
||||
|
||||
constructor(private $nsCloudDeviceEmulator: ICloudDeviceEmulator,
|
||||
private $injector: IInjector) {
|
||||
super();
|
||||
}
|
||||
|
||||
public addDevice(device: Mobile.IDevice) {
|
||||
this.devices[device.deviceInfo.identifier] = device;
|
||||
this.raiseOnDeviceFound(device);
|
||||
}
|
||||
|
||||
public removeDevice(deviceIdentifier: string) {
|
||||
let device = this.devices[deviceIdentifier];
|
||||
if (!device) {
|
||||
return;
|
||||
}
|
||||
|
||||
delete this.devices[deviceIdentifier];
|
||||
this.raiseOnDeviceLost(device);
|
||||
}
|
||||
|
||||
public async startLookingForDevices(): Promise<void> {
|
||||
if (!this._hasStartedLookingForDevices) {
|
||||
this._hasStartedLookingForDevices = true;
|
||||
_.values(this.$nsCloudDeviceEmulator.deviceEmitter.getCurrentlyAttachedDevices()).forEach(basicInfo => {
|
||||
this.addCloudDevice(basicInfo);
|
||||
});
|
||||
|
||||
this.$nsCloudDeviceEmulator.deviceEmitter.on(DEVICE_DISCOVERY_EVENTS.DEVICE_FOUND, (basicInfo: ICloudEmulatorDeviceBasicInfo) => {
|
||||
this.addCloudDevice(basicInfo);
|
||||
});
|
||||
|
||||
this.$nsCloudDeviceEmulator.deviceEmitter.on(DEVICE_DISCOVERY_EVENTS.DEVICE_LOST, (basicInfo: ICloudEmulatorDeviceBasicInfo) => {
|
||||
this.removeDevice(basicInfo.identifier);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public async checkForDevices(): Promise<void> { /* currently empty */ }
|
||||
|
||||
private raiseOnDeviceFound(device: Mobile.IDevice) {
|
||||
this.emit(DEVICE_DISCOVERY_EVENTS.DEVICE_FOUND, device);
|
||||
}
|
||||
|
||||
private raiseOnDeviceLost(device: Mobile.IDevice) {
|
||||
this.emit(DEVICE_DISCOVERY_EVENTS.DEVICE_LOST, device);
|
||||
}
|
||||
|
||||
private addCloudDevice(basicInfo: ICloudEmulatorDeviceBasicInfo) {
|
||||
const device: Mobile.IDevice = this.$injector.resolve(CloudEmulatorDevice, { basicInfo: basicInfo });
|
||||
this.addDevice(device);
|
||||
}
|
||||
}
|
||||
|
||||
$injector.register("nsCloudEmulatorDeviceDiscovery", CloudEmulatorDeviceDiscovery);
|
|
@ -1,11 +0,0 @@
|
|||
export class CloudEmulatorLauncher implements ICloudEmulatorLauncher {
|
||||
|
||||
constructor(private $nsCloudServerEmulatorsService: IServerEmulatorsService) { }
|
||||
|
||||
public async startEmulator(data: ICloudEmulatorStartData): Promise<string> {
|
||||
const response: ICloudEmulatorResponse = await this.$nsCloudServerEmulatorsService.deployApp(data.packageFile, data.platform);
|
||||
return this.$nsCloudServerEmulatorsService.startEmulator(response.publicKey, data.platform, data.model);
|
||||
}
|
||||
}
|
||||
|
||||
$injector.register("nsCloudEmulatorLauncher", CloudEmulatorLauncher);
|
|
@ -1,73 +0,0 @@
|
|||
import * as path from "path";
|
||||
|
||||
import { EMULATORS_SERVICE_NAME, HTTP_METHODS } from "../../constants";
|
||||
import { ServerServiceBase } from "./server-service-base";
|
||||
|
||||
export class ServerEmulatorsService extends ServerServiceBase implements IServerEmulatorsService {
|
||||
|
||||
protected serviceName = EMULATORS_SERVICE_NAME;
|
||||
|
||||
constructor(private $nsCloudDeviceEmulator: ICloudDeviceEmulator,
|
||||
protected $nsCloudServerRequestService: IServerRequestService,
|
||||
private $nsCloudUploadService: IUploadService,
|
||||
private $fs: IFileSystem,
|
||||
protected $options: IProfileDir,
|
||||
$injector: IInjector) {
|
||||
|
||||
super($nsCloudServerRequestService, $injector);
|
||||
}
|
||||
|
||||
public async startEmulator(publicKey: string, platform: string, deviceType: string): Promise<string> {
|
||||
const serverInfo = await this.$nsCloudDeviceEmulator.getSeverAddress();
|
||||
return `http://${serverInfo.host}:${serverInfo.port}?publicKey=${publicKey}&device=${deviceType}`;
|
||||
}
|
||||
|
||||
public async deployApp(fileLocation: string, platform: string): Promise<ICloudEmulatorResponse> {
|
||||
if (this.$fs.exists(path.resolve(fileLocation))) {
|
||||
fileLocation = await this.$nsCloudUploadService.uploadToS3(fileLocation);
|
||||
}
|
||||
|
||||
const cloudEmulatorKeys = this.getEmulatorCredentials(platform);
|
||||
if (!cloudEmulatorKeys) {
|
||||
return this.createApp(fileLocation, platform);
|
||||
}
|
||||
|
||||
return this.updateApp(fileLocation, platform, cloudEmulatorKeys.publicKey, cloudEmulatorKeys.privateKey);
|
||||
}
|
||||
|
||||
public refereshEmulator(deviceIdentifier: string): Promise<void> {
|
||||
return this.$nsCloudDeviceEmulator.refresh(deviceIdentifier);
|
||||
}
|
||||
|
||||
private async createApp(url: string, platform: string): Promise<ICloudEmulatorResponse> {
|
||||
const response = await this.sendRequest<ICloudEmulatorResponse>(HTTP_METHODS.POST, "api/apps", { url, platform });
|
||||
this.setEmulatorCredentials(response.publicKey, response.privateKey, response.platform);
|
||||
return response;
|
||||
}
|
||||
|
||||
private updateApp(url: string, platform: string, publicKey: string, privateKey: string): Promise<ICloudEmulatorResponse> {
|
||||
return this.sendRequest<ICloudEmulatorResponse>(HTTP_METHODS.PUT, `api/apps/${publicKey}`, { url, platform });
|
||||
}
|
||||
|
||||
private setEmulatorCredentials(publicKey: string, privateKey: string, platform: string): void {
|
||||
const configPath = this.getCredentialsPath();
|
||||
let emulatorCredential = this.loadCredentials();
|
||||
emulatorCredential[platform] = { publicKey, privateKey };
|
||||
this.$fs.writeJson(configPath, emulatorCredential);
|
||||
}
|
||||
|
||||
private getEmulatorCredentials(platform: string): ICloudEmulatorKeys {
|
||||
return this.loadCredentials()[platform];
|
||||
}
|
||||
|
||||
private loadCredentials(): IEmulatorCredentials {
|
||||
const configFileName = this.getCredentialsPath();
|
||||
return this.$fs.exists(configFileName) ? this.$fs.readJson(configFileName) : {};
|
||||
}
|
||||
|
||||
private getCredentialsPath(): string {
|
||||
return path.join(this.$options.profileDir, "cloud-emulator.json");
|
||||
}
|
||||
}
|
||||
|
||||
$injector.register("nsCloudServerEmulatorsService", ServerEmulatorsService);
|
|
@ -49,7 +49,6 @@
|
|||
"dependencies": {
|
||||
"aws4": "1.6.0",
|
||||
"cli-table": "https://github.com/telerik/cli-table/tarball/v0.3.1.2",
|
||||
"cloud-device-emulator": "0.5.0",
|
||||
"cookie": "0.3.1",
|
||||
"lodash": "4.17.4",
|
||||
"minimatch": "3.0.4",
|
||||
|
|
|
@ -1,127 +0,0 @@
|
|||
import { CloudEmulatorDeviceDiscovery } from "../../../lib/mobile/mobile-core/cloud-emulator-device-discovery";
|
||||
import { DEVICE_DISCOVERY_EVENTS } from "../../../lib/constants";
|
||||
import { EventEmitter } from "events";
|
||||
import { Yok } from "nativescript/lib/common/yok";
|
||||
import { assert } from "chai";
|
||||
|
||||
class CustomDeviceEmitter extends EventEmitter implements CloudDeviceEmitter {
|
||||
private _initialDevices: IAttachedDevices;
|
||||
|
||||
constructor(initialDevices?: IAttachedDevices) {
|
||||
super();
|
||||
this._initialDevices = initialDevices || {};
|
||||
}
|
||||
public getCurrentlyAttachedDevices(): IAttachedDevices {
|
||||
return this._initialDevices;
|
||||
}
|
||||
public dispose(): void { /* empty */ }
|
||||
}
|
||||
|
||||
describe("cloud emulator device discovery", () => {
|
||||
describe("startLookingForDevices", async () => {
|
||||
const customDevice = {
|
||||
identifier: "id",
|
||||
publicKey: "publicKey",
|
||||
model: "model",
|
||||
os: "os"
|
||||
};
|
||||
|
||||
const initialDevices: IAttachedDevices = {
|
||||
id: customDevice
|
||||
};
|
||||
|
||||
function createTestInjector(devices?: IAttachedDevices): IInjector {
|
||||
const customEventEmitter = new CustomDeviceEmitter(devices);
|
||||
const testInjector = new Yok();
|
||||
testInjector.register("injector", testInjector);
|
||||
testInjector.register("nsCloudDeviceEmulator", {
|
||||
get deviceEmitter() {
|
||||
return customEventEmitter;
|
||||
}
|
||||
});
|
||||
testInjector.register("nsCloudServerEmulatorsService", { /* empty */ });
|
||||
testInjector.register("mobileHelper", {
|
||||
normalizePlatformName: (platform: string) => platform.toLowerCase()
|
||||
});
|
||||
|
||||
return testInjector;
|
||||
}
|
||||
|
||||
it(`should attach ${DEVICE_DISCOVERY_EVENTS.DEVICE_FOUND}/${DEVICE_DISCOVERY_EVENTS.DEVICE_LOST}`, async () => {
|
||||
const injector = createTestInjector();
|
||||
|
||||
const nsCloudEmulatorDeviceDiscovery: Mobile.IDeviceDiscovery = injector.resolve(CloudEmulatorDeviceDiscovery);
|
||||
await nsCloudEmulatorDeviceDiscovery.startLookingForDevices();
|
||||
|
||||
const deviceEmitter = injector.resolve("nsCloudDeviceEmulator").deviceEmitter;
|
||||
|
||||
assert.deepEqual(deviceEmitter.listenerCount(DEVICE_DISCOVERY_EVENTS.DEVICE_FOUND), 1);
|
||||
assert.deepEqual(deviceEmitter.listenerCount(DEVICE_DISCOVERY_EVENTS.DEVICE_LOST), 1);
|
||||
});
|
||||
|
||||
it(`should not attach ${DEVICE_DISCOVERY_EVENTS.DEVICE_FOUND}/${DEVICE_DISCOVERY_EVENTS.DEVICE_LOST} multiple times upon multiple calls`, async () => {
|
||||
const injector = createTestInjector();
|
||||
|
||||
const nsCloudEmulatorDeviceDiscovery: Mobile.IDeviceDiscovery = injector.resolve(CloudEmulatorDeviceDiscovery);
|
||||
await nsCloudEmulatorDeviceDiscovery.startLookingForDevices();
|
||||
await nsCloudEmulatorDeviceDiscovery.startLookingForDevices();
|
||||
|
||||
const deviceEmitter = injector.resolve("nsCloudDeviceEmulator").deviceEmitter;
|
||||
|
||||
assert.deepEqual(deviceEmitter.listenerCount(DEVICE_DISCOVERY_EVENTS.DEVICE_FOUND), 1);
|
||||
assert.deepEqual(deviceEmitter.listenerCount(DEVICE_DISCOVERY_EVENTS.DEVICE_LOST), 1);
|
||||
});
|
||||
|
||||
it("should detect already running devices", async () => {
|
||||
const injector = createTestInjector(initialDevices);
|
||||
let hasDetectedDevice = false;
|
||||
|
||||
const nsCloudEmulatorDeviceDiscovery: Mobile.IDeviceDiscovery = injector.resolve(CloudEmulatorDeviceDiscovery);
|
||||
nsCloudEmulatorDeviceDiscovery.on(DEVICE_DISCOVERY_EVENTS.DEVICE_FOUND, (device: Mobile.IDevice) => {
|
||||
hasDetectedDevice = true;
|
||||
assert.deepEqual(device.deviceInfo.identifier, customDevice.identifier);
|
||||
assert.deepEqual(device.deviceInfo.model, customDevice.model);
|
||||
});
|
||||
|
||||
await nsCloudEmulatorDeviceDiscovery.startLookingForDevices();
|
||||
assert.isTrue(hasDetectedDevice);
|
||||
});
|
||||
|
||||
it(`should detect devices on ${DEVICE_DISCOVERY_EVENTS.DEVICE_FOUND}`, async () => {
|
||||
const injector = createTestInjector();
|
||||
let hasDetectedDevice = false;
|
||||
|
||||
const deviceEmitter: EventEmitter = injector.resolve("nsCloudDeviceEmulator").deviceEmitter;
|
||||
|
||||
const nsCloudEmulatorDeviceDiscovery: Mobile.IDeviceDiscovery = injector.resolve(CloudEmulatorDeviceDiscovery);
|
||||
nsCloudEmulatorDeviceDiscovery.on(DEVICE_DISCOVERY_EVENTS.DEVICE_FOUND, (device: Mobile.IDevice) => {
|
||||
hasDetectedDevice = true;
|
||||
assert.deepEqual(device.deviceInfo.identifier, customDevice.identifier);
|
||||
assert.deepEqual(device.deviceInfo.model, customDevice.model);
|
||||
});
|
||||
|
||||
await nsCloudEmulatorDeviceDiscovery.startLookingForDevices();
|
||||
deviceEmitter.emit(DEVICE_DISCOVERY_EVENTS.DEVICE_FOUND, customDevice);
|
||||
assert.isTrue(hasDetectedDevice);
|
||||
});
|
||||
|
||||
it(`should lose devices on ${DEVICE_DISCOVERY_EVENTS.DEVICE_LOST}`, async () => {
|
||||
const injector = createTestInjector(initialDevices);
|
||||
let hasLostDevice = false;
|
||||
|
||||
const deviceEmitter: EventEmitter = injector.resolve("nsCloudDeviceEmulator").deviceEmitter;
|
||||
|
||||
const nsCloudEmulatorDeviceDiscovery: Mobile.IDeviceDiscovery = injector.resolve(CloudEmulatorDeviceDiscovery);
|
||||
nsCloudEmulatorDeviceDiscovery.on(DEVICE_DISCOVERY_EVENTS.DEVICE_LOST, (device: Mobile.IDevice) => {
|
||||
hasLostDevice = true;
|
||||
assert.deepEqual(device.deviceInfo.identifier, customDevice.identifier);
|
||||
assert.deepEqual(device.deviceInfo.model, customDevice.model);
|
||||
});
|
||||
|
||||
await nsCloudEmulatorDeviceDiscovery.startLookingForDevices();
|
||||
deviceEmitter.emit(DEVICE_DISCOVERY_EVENTS.DEVICE_LOST, customDevice);
|
||||
|
||||
assert.isTrue(hasLostDevice);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,86 +0,0 @@
|
|||
import { ServerEmulatorsService } from "../../lib/services/server/server-emulators-service";
|
||||
import { HTTP_METHODS } from "../../lib/constants";
|
||||
import { Yok } from "nativescript/lib/common/yok";
|
||||
import { assert } from "chai";
|
||||
|
||||
describe("cloud emulator service", () => {
|
||||
describe("deployApp", async () => {
|
||||
const emulatorCredentials = { publicKey: "publicKey", privateKey: "privateKey", platform: "platform" };
|
||||
const filePath = "localPath";
|
||||
const platform = "platform";
|
||||
|
||||
function createTestInjector(): IInjector {
|
||||
const testInjector = new Yok();
|
||||
testInjector.register("nsCloudServerRequestService", {
|
||||
call: async () => emulatorCredentials
|
||||
});
|
||||
testInjector.register("fs", {
|
||||
exists: () => true,
|
||||
readJson: () => ({}),
|
||||
writeJson: () => { /* empty */ }
|
||||
});
|
||||
testInjector.register("nsCloudUploadService", {
|
||||
uploadToS3: async (url: string) => url
|
||||
});
|
||||
testInjector.register("nsCloudDeviceEmulator", { /* empty */ });
|
||||
testInjector.register("options", {
|
||||
profileDir: "test"
|
||||
});
|
||||
testInjector.register("nsCloudEulaService", {
|
||||
getEulaDataWithCache: () => Promise.resolve({})
|
||||
});
|
||||
|
||||
return testInjector;
|
||||
}
|
||||
|
||||
it("should upload to S3 in case a local file is passed", async () => {
|
||||
const injector = createTestInjector();
|
||||
let hasUploadedToS3 = false;
|
||||
injector.resolve("nsCloudUploadService").uploadToS3 = (url: string) => {
|
||||
if (url === filePath) {
|
||||
hasUploadedToS3 = true;
|
||||
}
|
||||
};
|
||||
|
||||
const nsCloudServerEmulatorsService: IServerEmulatorsService = injector.resolve(ServerEmulatorsService);
|
||||
await nsCloudServerEmulatorsService.deployApp(filePath, platform);
|
||||
|
||||
assert.isTrue(hasUploadedToS3);
|
||||
});
|
||||
|
||||
it("should call create if emulator credentials not present", async () => {
|
||||
const injector = createTestInjector();
|
||||
let hasCalledCloudRequestService = false;
|
||||
injector.resolve("nsCloudServerRequestService").call = (options: ICloudRequestOptions) => {
|
||||
hasCalledCloudRequestService = true;
|
||||
assert.deepEqual(options.method, HTTP_METHODS.POST, "create is not called upon missing credentials");
|
||||
|
||||
return emulatorCredentials;
|
||||
};
|
||||
|
||||
const nsCloudServerEmulatorsService: IServerEmulatorsService = injector.resolve(ServerEmulatorsService);
|
||||
await nsCloudServerEmulatorsService.deployApp(filePath, platform);
|
||||
|
||||
assert.isTrue(hasCalledCloudRequestService);
|
||||
});
|
||||
|
||||
it("should call update if emulator credentials present", async () => {
|
||||
const injector = createTestInjector();
|
||||
let hasCalledCloudRequestService = false;
|
||||
injector.resolve("fs").readJson = () => ({
|
||||
[platform]: emulatorCredentials
|
||||
});
|
||||
injector.resolve("nsCloudServerRequestService").call = (options: ICloudRequestOptions) => {
|
||||
hasCalledCloudRequestService = true;
|
||||
assert.deepEqual(options.method, HTTP_METHODS.PUT, "update is not called upon existing credentials");
|
||||
|
||||
return emulatorCredentials;
|
||||
};
|
||||
|
||||
const nsCloudServerEmulatorsService: IServerEmulatorsService = injector.resolve(ServerEmulatorsService);
|
||||
await nsCloudServerEmulatorsService.deployApp(filePath, platform);
|
||||
|
||||
assert.isTrue(hasCalledCloudRequestService);
|
||||
});
|
||||
});
|
||||
});
|
Загрузка…
Ссылка в новой задаче