Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Get rid of $projectData dependency in services #900

Merged
merged 1 commit into from
Mar 3, 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
15 changes: 13 additions & 2 deletions child-process.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import * as child_process from "child_process";
import { EventEmitter } from "events";

export class ChildProcess implements IChildProcess {
export class ChildProcess extends EventEmitter implements IChildProcess {
constructor(private $logger: ILogger,
private $errors: IErrors) { }
private $errors: IErrors) {
super();
}

public async exec(command: string, options?: any, execOptions?: IExecOptions): Promise<any> {
return new Promise<any>((resolve, reject) => {
Expand Down Expand Up @@ -62,12 +65,20 @@ export class ChildProcess implements IChildProcess {

if (childProcess.stdout) {
childProcess.stdout.on("data", (data: string) => {
if (spawnFromEventOptions && spawnFromEventOptions.emitOptions && spawnFromEventOptions.emitOptions.eventName) {
this.emit(spawnFromEventOptions.emitOptions.eventName, { data, pipe: 'stdout' });
}

capturedOut += data;
});
}

if (childProcess.stderr) {
childProcess.stderr.on("data", (data: string) => {
if (spawnFromEventOptions && spawnFromEventOptions.emitOptions && spawnFromEventOptions.emitOptions.eventName) {
this.emit(spawnFromEventOptions.emitOptions.eventName, { data, pipe: 'stdout' });
}

capturedErr += data;
});
}
Expand Down
59 changes: 40 additions & 19 deletions declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ interface IQueue<T> {
dequeue(): Promise<T>;
}

interface IChildProcess {
interface IChildProcess extends NodeJS.EventEmitter {
exec(command: string, options?: any, execOptions?: IExecOptions): Promise<any>;
execFile(command: string, args: string[]): Promise<any>;
spawn(command: string, args?: string[], options?: any): any; // it returns child_process.ChildProcess you can safely cast to it
Expand Down Expand Up @@ -478,6 +478,9 @@ interface ISpawnResult {

interface ISpawnFromEventOptions {
throwError: boolean;
emitOptions?: {
eventName: string;
}
}

interface IProjectHelper {
Expand Down Expand Up @@ -711,7 +714,7 @@ interface ILiveSyncServiceBase {
* If watch option is not specified executes full sync
* If watch option is specified executes partial sync
*/
sync(data: ILiveSyncData[], filePaths?: string[]): Promise<void>;
sync(data: ILiveSyncData[], projectId: string, filePaths?: string[]): Promise<void>;

/**
* Returns the `canExecute` method which defines if LiveSync operation can be executed on specified device.
Expand Down Expand Up @@ -795,7 +798,16 @@ interface ILiveSyncData {
canExecute?(device: Mobile.IDevice): boolean;
}

interface IDeviceLiveSyncService {
interface IDeviceLiveSyncServiceBase {
/**
* Specifies some action that will be executed before every sync operation
*/
beforeLiveSyncAction?(deviceAppData: Mobile.IDeviceAppData): Promise<void>;

debugService?: any;
}

interface IDeviceLiveSyncService extends IDeviceLiveSyncServiceBase {
/**
* Refreshes the application's content on a device
*/
Expand All @@ -804,13 +816,7 @@ interface IDeviceLiveSyncService {
* Removes specified files from a connected device
*/
removeFiles(appIdentifier: string, localToDevicePaths: Mobile.ILocalToDevicePathData[]): Promise<void>;
/**
* Specifies some action that will be executed before every sync operation
*/
beforeLiveSyncAction?(deviceAppData: Mobile.IDeviceAppData): Promise<void>;
afterInstallApplicationAction?(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]): Promise<boolean>;

debugService?: any;
}

interface ISysInfoData {
Expand Down Expand Up @@ -935,7 +941,27 @@ interface Error {
code?: string | number;
}

interface ICommonOptions {
interface IRelease {
release: boolean;
}

interface IDeviceIdentifier {
device: string;
}

interface IJustLaunch {
justlaunch: boolean;
}

interface IAvd {
avd: string;
}

interface IAvailableDevices {
availableDevices: boolean;
}

interface ICommonOptions extends IRelease, IDeviceIdentifier, IJustLaunch, IAvd, IAvailableDevices {
argv: IYargArgv;
validateOptions(commandSpecificDashedOptions?: IDictionary<IDashedOption>): void;
options: IDictionary<any>;
Expand All @@ -953,19 +979,15 @@ interface ICommonOptions {
help: boolean;
json: boolean;
watch: boolean;
avd: string;
profileDir: string;
timeout: string;
device: string;
availableDevices: boolean;
appid: string;
geny: string;
debugBrk: boolean;
debugPort: number;
start: boolean;
stop: boolean;
ddi: string; // the path to developer disk image
justlaunch: boolean;
skipRefresh: boolean;
app: string;
file: string;
Expand All @@ -977,7 +999,6 @@ interface ICommonOptions {
template: string;
var: Object;
default: Boolean;
release: boolean;
count: number;
hooks: boolean;
debug: boolean;
Expand Down Expand Up @@ -1321,7 +1342,7 @@ interface IProjectFilesProvider {
/**
* Performs local file path mapping
*/
mapFilePath(filePath: string, platform: string): string;
mapFilePath(filePath: string, platform: string, projectData?: any): string;

/**
* Returns information about file in the project, that includes file's name on device after removing platform or configuration from the name.
Expand Down Expand Up @@ -1363,16 +1384,16 @@ interface ILiveSyncProvider {
/**
* Builds the application and returns the package file path
*/
buildForDevice(device: Mobile.IDevice): Promise<string>;
buildForDevice(device: Mobile.IDevice, projectData?: any): Promise<string>;
/**
* Prepares the platform for sync
*/
preparePlatformForSync(platform: string): Promise<void>;
preparePlatformForSync(platform: string, provision: any, projectData?: any): Promise<void>;

/**
* Checks if the specified file can be fast synced.
*/
canExecuteFastSync(filePath: string, platform?: string): boolean;
canExecuteFastSync(filePath: string, projectData?: any, platform?: string): boolean;

transferFiles(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string, isFullSync: boolean): Promise<void>;

Expand Down
7 changes: 5 additions & 2 deletions definitions/mobile.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,12 @@ declare module Mobile {
* Filters data for specified platform.
* @param {string} platform The platform for which is the device log.
* @param {string} data The input data for filtering.
* @param {string} projectDir The project's root directory.
* @param {string} pid @optional The application PID for this device.
* @param {string} logLevel @optional The logging level based on which input data will be filtered.
* @return {string} The filtered result based on the input or null when the input data shouldn't be shown.
*/
filterData(platform: string, data: string, pid?: string, logLevel?: string): string;
filterData(platform: string, data: string, projectDir: string, pid?: string, logLevel?: string): string;
}

/**
Expand All @@ -224,9 +225,10 @@ declare module Mobile {
* @param {string} data The string data that will be checked based on the logging level.
* @param {string} logLevel Selected logging level.
* @param {string} pid The Process ID of the currently running application for which we need the logs.
* @param {string} projectDir The root directory of the project.
* @return {string} The filtered result based on the input or null when the input data shouldn't be shown.
*/
filterData(data: string, logLevel: string, pid: string): string;
filterData(data: string, logLevel: string, projectDir: string, pid: string): string;
}

interface ILoggingLevels {
Expand Down Expand Up @@ -327,6 +329,7 @@ declare module Mobile {

interface IDevicesServicesInitializationOptions {
platform?: string;
emulator?: boolean;
deviceId?: string;
skipInferPlatform?: boolean;
}
Expand Down
2 changes: 1 addition & 1 deletion mobile/ios/ios-log-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export class IOSLogFilter implements Mobile.IPlatformLogFilter {

constructor(private $loggingLevels: Mobile.ILoggingLevels) { }

public filterData(data: string, logLevel: string, pid?: string): string {
public filterData(data: string, logLevel: string, projectDir: string, pid?: string): string {
let specifiedLogLevel = (logLevel || '').toUpperCase();

if (specifiedLogLevel === this.$loggingLevels.info) {
Expand Down
4 changes: 2 additions & 2 deletions mobile/log-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export class LogFilter implements Mobile.ILogFilter {
}
}

public filterData(platform: string, data: string, pid?: string, logLevel?: string): string {
public filterData(platform: string, data: string, projectDir: string, pid?: string, logLevel?: string): string {
let deviceLogFilter = this.getDeviceLogFilterInstance(platform);
if (deviceLogFilter) {
return deviceLogFilter.filterData(data, logLevel || this.loggingLevel, pid);
return deviceLogFilter.filterData(data, logLevel || this.loggingLevel, projectDir, pid);
}

// In case the platform is not valid, just return the data without filtering.
Expand Down
14 changes: 7 additions & 7 deletions services/livesync-service-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ class LiveSyncServiceBase implements ILiveSyncServiceBase {
this.fileHashes = Object.create(null);
}

public async sync(data: ILiveSyncData[], filePaths?: string[]): Promise<void> {
public async sync(data: ILiveSyncData[], projectId: string, filePaths?: string[]): Promise<void> {
await this.syncCore(data, filePaths);
if (this.$options.watch) {
await this.$hooksService.executeBeforeHooks('watch');
this.partialSync(data, data[0].syncWorkingDirectory);
this.partialSync(data, data[0].syncWorkingDirectory, projectId);
}
}

Expand All @@ -48,7 +48,7 @@ class LiveSyncServiceBase implements ILiveSyncServiceBase {
return isFileExcluded;
}

private partialSync(data: ILiveSyncData[], syncWorkingDirectory: string): void {
private partialSync(data: ILiveSyncData[], syncWorkingDirectory: string, projectId: string): void {
let that = this;
this.showFullLiveSyncInformation = true;
const gazeInstance = gaze(["**/*", "!node_modules/**/*", "!platforms/**/*"], { cwd: syncWorkingDirectory }, function (err: any, watcher: any) {
Expand Down Expand Up @@ -76,15 +76,15 @@ class LiveSyncServiceBase implements ILiveSyncServiceBase {
that.$logger.trace(`Skipping livesync for changed file ${filePath} as it is excluded in the patterns: ${dataItem.excludedProjectDirsAndFiles.join(", ")}`);
continue;
}
let mappedFilePath = that.$projectFilesProvider.mapFilePath(filePath, dataItem.platform);
let mappedFilePath = that.$projectFilesProvider.mapFilePath(filePath, dataItem.platform, projectId);
that.$logger.trace(`Syncing filePath ${filePath}, mappedFilePath is ${mappedFilePath}`);
if (!mappedFilePath) {
that.$logger.warn(`Unable to sync ${filePath}.`);
continue;
}

if (event === "added" || event === "changed" || event === "renamed") {
that.batchSync(dataItem, mappedFilePath);
that.batchSync(dataItem, mappedFilePath, projectId);
} else if (event === "deleted") {
that.fileHashes = <any>(_.omit(that.fileHashes, filePath));
await that.syncRemovedFile(dataItem, mappedFilePath);
Expand All @@ -105,7 +105,7 @@ class LiveSyncServiceBase implements ILiveSyncServiceBase {
private batch: IDictionary<ISyncBatch> = Object.create(null);
private livesyncData: IDictionary<ILiveSyncData> = Object.create(null);

private batchSync(data: ILiveSyncData, filePath: string): void {
private batchSync(data: ILiveSyncData, filePath: string, projectId: string): void {
let platformBatch: ISyncBatch = this.batch[data.platform];
if (!platformBatch || !platformBatch.syncPending) {
let done = () => {
Expand All @@ -116,7 +116,7 @@ class LiveSyncServiceBase implements ILiveSyncServiceBase {
let batch = this.batch[platformName];
let livesyncData = this.livesyncData[platformName];
await batch.syncFiles(async (filesToSync: string[]) => {
await this.$liveSyncProvider.preparePlatformForSync(platformName);
await this.$liveSyncProvider.preparePlatformForSync(platformName, projectId);
this.syncCore([livesyncData], filesToSync);
});
}
Expand Down
2 changes: 1 addition & 1 deletion services/project-files-provider-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Configurations } from "../constants";

export abstract class ProjectFilesProviderBase implements IProjectFilesProvider {
abstract isFileExcluded(filePath: string): boolean;
abstract mapFilePath(filePath: string, platform: string): string;
abstract mapFilePath(filePath: string, platform: string, projectData: any): string;

constructor(private $mobileHelper: Mobile.IMobileHelper,
protected $options: ICommonOptions) { }
Expand Down
2 changes: 1 addition & 1 deletion test/unit-tests/ios-log-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe("iOSLogFilter", () => {
let testInjector = new Yok();
testInjector.register("loggingLevels", LoggingLevels);
let iOSLogFilter = testInjector.resolve(IOSLogFilter);
let filteredData = iOSLogFilter.filterData(inputData, logLevel, pid);
let filteredData = iOSLogFilter.filterData(inputData, logLevel, "", pid);
assert.deepEqual(filteredData, expectedOutput, `The actual result '${filteredData}' did NOT match expected output '${expectedOutput}'.`);
};

Expand Down
18 changes: 9 additions & 9 deletions test/unit-tests/log-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@ describe("logFilter", () => {
describe("filterData", () => {
describe("when logLevel is not specified and default log level is not changed", () => {
it("returns same data when platform is not correct", () => {
let actualData = logFilter.filterData("invalidPlatform", testData);
let actualData = logFilter.filterData("invalidPlatform", testData, "");
assert.deepEqual(actualData, testData);
});

it("returns same data when platform is not passed", () => {
let actualData = logFilter.filterData(null, testData);
let actualData = logFilter.filterData(null, testData, "");
assert.deepEqual(actualData, testData);
});

it("returns correct data when platform is android", () => {
let actualData = logFilter.filterData("android", testData);
let actualData = logFilter.filterData("android", testData, "");
assert.deepEqual(actualData, androidInfoTestData);
});

it("returns correct data when platform is ios", () => {
let actualData = logFilter.filterData("ios", testData);
let actualData = logFilter.filterData("ios", testData, "");
assert.deepEqual(actualData, iosInfoTestData);
});
});
Expand All @@ -91,17 +91,17 @@ describe("logFilter", () => {
beforeEach(() => logFilter.loggingLevel = fullLogLevel);

it("returns same data when platform is not correct", () => {
let actualData = logFilter.filterData("invalidPlatform", testData);
let actualData = logFilter.filterData("invalidPlatform", testData, "");
assert.deepEqual(actualData, testData);
});

it("returns correct data when platform is android", () => {
let actualData = logFilter.filterData("android", testData);
let actualData = logFilter.filterData("android", testData, "");
assert.deepEqual(actualData, androidFullTestData);
});

it("returns correct data when platform is ios", () => {
let actualData = logFilter.filterData("ios", testData);
let actualData = logFilter.filterData("ios", testData, "");
assert.deepEqual(actualData, iosFullTestData);
});
});
Expand Down Expand Up @@ -134,12 +134,12 @@ describe("logFilter", () => {
});

it("returns correct data when platform is android", () => {
let actualData = logFilter.filterData("android", testData, null, logLevel);
let actualData = logFilter.filterData("android", testData, null, null, logLevel);
assert.deepEqual(actualData, androidFullTestData);
});

it("returns correct data when platform is ios", () => {
let actualData = logFilter.filterData("ios", testData, null, logLevel);
let actualData = logFilter.filterData("ios", testData, null, null, logLevel);
assert.deepEqual(actualData, iosFullTestData);
});
});
Expand Down