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

Commit abaed01

Browse files
Merge pull request #900 from telerik/kerezov/local-build-lib
Get rid of $projectData dependency in services
2 parents f956096 + 24d47bb commit abaed01

9 files changed

+79
-44
lines changed

child-process.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import * as child_process from "child_process";
2+
import { EventEmitter } from "events";
23

3-
export class ChildProcess implements IChildProcess {
4+
export class ChildProcess extends EventEmitter implements IChildProcess {
45
constructor(private $logger: ILogger,
5-
private $errors: IErrors) { }
6+
private $errors: IErrors) {
7+
super();
8+
}
69

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

6366
if (childProcess.stdout) {
6467
childProcess.stdout.on("data", (data: string) => {
68+
if (spawnFromEventOptions && spawnFromEventOptions.emitOptions && spawnFromEventOptions.emitOptions.eventName) {
69+
this.emit(spawnFromEventOptions.emitOptions.eventName, { data, pipe: 'stdout' });
70+
}
71+
6572
capturedOut += data;
6673
});
6774
}
6875

6976
if (childProcess.stderr) {
7077
childProcess.stderr.on("data", (data: string) => {
78+
if (spawnFromEventOptions && spawnFromEventOptions.emitOptions && spawnFromEventOptions.emitOptions.eventName) {
79+
this.emit(spawnFromEventOptions.emitOptions.eventName, { data, pipe: 'stdout' });
80+
}
81+
7182
capturedErr += data;
7283
});
7384
}

declarations.d.ts

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ interface IQueue<T> {
448448
dequeue(): Promise<T>;
449449
}
450450

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

479479
interface ISpawnFromEventOptions {
480480
throwError: boolean;
481+
emitOptions?: {
482+
eventName: string;
483+
}
481484
}
482485

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

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

798-
interface IDeviceLiveSyncService {
801+
interface IDeviceLiveSyncServiceBase {
802+
/**
803+
* Specifies some action that will be executed before every sync operation
804+
*/
805+
beforeLiveSyncAction?(deviceAppData: Mobile.IDeviceAppData): Promise<void>;
806+
807+
debugService?: any;
808+
}
809+
810+
interface IDeviceLiveSyncService extends IDeviceLiveSyncServiceBase {
799811
/**
800812
* Refreshes the application's content on a device
801813
*/
@@ -804,13 +816,7 @@ interface IDeviceLiveSyncService {
804816
* Removes specified files from a connected device
805817
*/
806818
removeFiles(appIdentifier: string, localToDevicePaths: Mobile.ILocalToDevicePathData[]): Promise<void>;
807-
/**
808-
* Specifies some action that will be executed before every sync operation
809-
*/
810-
beforeLiveSyncAction?(deviceAppData: Mobile.IDeviceAppData): Promise<void>;
811819
afterInstallApplicationAction?(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]): Promise<boolean>;
812-
813-
debugService?: any;
814820
}
815821

816822
interface ISysInfoData {
@@ -935,7 +941,27 @@ interface Error {
935941
code?: string | number;
936942
}
937943

938-
interface ICommonOptions {
944+
interface IRelease {
945+
release: boolean;
946+
}
947+
948+
interface IDeviceIdentifier {
949+
device: string;
950+
}
951+
952+
interface IJustLaunch {
953+
justlaunch: boolean;
954+
}
955+
956+
interface IAvd {
957+
avd: string;
958+
}
959+
960+
interface IAvailableDevices {
961+
availableDevices: boolean;
962+
}
963+
964+
interface ICommonOptions extends IRelease, IDeviceIdentifier, IJustLaunch, IAvd, IAvailableDevices {
939965
argv: IYargArgv;
940966
validateOptions(commandSpecificDashedOptions?: IDictionary<IDashedOption>): void;
941967
options: IDictionary<any>;
@@ -953,19 +979,15 @@ interface ICommonOptions {
953979
help: boolean;
954980
json: boolean;
955981
watch: boolean;
956-
avd: string;
957982
profileDir: string;
958983
timeout: string;
959-
device: string;
960-
availableDevices: boolean;
961984
appid: string;
962985
geny: string;
963986
debugBrk: boolean;
964987
debugPort: number;
965988
start: boolean;
966989
stop: boolean;
967990
ddi: string; // the path to developer disk image
968-
justlaunch: boolean;
969991
skipRefresh: boolean;
970992
app: string;
971993
file: string;
@@ -977,7 +999,6 @@ interface ICommonOptions {
977999
template: string;
9781000
var: Object;
9791001
default: Boolean;
980-
release: boolean;
9811002
count: number;
9821003
hooks: boolean;
9831004
debug: boolean;
@@ -1321,7 +1342,7 @@ interface IProjectFilesProvider {
13211342
/**
13221343
* Performs local file path mapping
13231344
*/
1324-
mapFilePath(filePath: string, platform: string): string;
1345+
mapFilePath(filePath: string, platform: string, projectData?: any): string;
13251346

13261347
/**
13271348
* Returns information about file in the project, that includes file's name on device after removing platform or configuration from the name.
@@ -1363,16 +1384,16 @@ interface ILiveSyncProvider {
13631384
/**
13641385
* Builds the application and returns the package file path
13651386
*/
1366-
buildForDevice(device: Mobile.IDevice): Promise<string>;
1387+
buildForDevice(device: Mobile.IDevice, projectData?: any): Promise<string>;
13671388
/**
13681389
* Prepares the platform for sync
13691390
*/
1370-
preparePlatformForSync(platform: string): Promise<void>;
1391+
preparePlatformForSync(platform: string, provision: any, projectData?: any): Promise<void>;
13711392

13721393
/**
13731394
* Checks if the specified file can be fast synced.
13741395
*/
1375-
canExecuteFastSync(filePath: string, platform?: string): boolean;
1396+
canExecuteFastSync(filePath: string, projectData?: any, platform?: string): boolean;
13761397

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

definitions/mobile.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,12 @@ declare module Mobile {
208208
* Filters data for specified platform.
209209
* @param {string} platform The platform for which is the device log.
210210
* @param {string} data The input data for filtering.
211+
* @param {string} projectDir The project's root directory.
211212
* @param {string} pid @optional The application PID for this device.
212213
* @param {string} logLevel @optional The logging level based on which input data will be filtered.
213214
* @return {string} The filtered result based on the input or null when the input data shouldn't be shown.
214215
*/
215-
filterData(platform: string, data: string, pid?: string, logLevel?: string): string;
216+
filterData(platform: string, data: string, projectDir: string, pid?: string, logLevel?: string): string;
216217
}
217218

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

232234
interface ILoggingLevels {
@@ -327,6 +329,7 @@ declare module Mobile {
327329

328330
interface IDevicesServicesInitializationOptions {
329331
platform?: string;
332+
emulator?: boolean;
330333
deviceId?: string;
331334
skipInferPlatform?: boolean;
332335
}

mobile/ios/ios-log-filter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export class IOSLogFilter implements Mobile.IPlatformLogFilter {
33

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

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

99
if (specifiedLogLevel === this.$loggingLevels.info) {

mobile/log-filter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ export class LogFilter implements Mobile.ILogFilter {
1515
}
1616
}
1717

18-
public filterData(platform: string, data: string, pid?: string, logLevel?: string): string {
18+
public filterData(platform: string, data: string, projectDir: string, pid?: string, logLevel?: string): string {
1919
let deviceLogFilter = this.getDeviceLogFilterInstance(platform);
2020
if (deviceLogFilter) {
21-
return deviceLogFilter.filterData(data, logLevel || this.loggingLevel, pid);
21+
return deviceLogFilter.filterData(data, logLevel || this.loggingLevel, projectDir, pid);
2222
}
2323

2424
// In case the platform is not valid, just return the data without filtering.

services/livesync-service-base.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ class LiveSyncServiceBase implements ILiveSyncServiceBase {
2828
this.fileHashes = Object.create(null);
2929
}
3030

31-
public async sync(data: ILiveSyncData[], filePaths?: string[]): Promise<void> {
31+
public async sync(data: ILiveSyncData[], projectId: string, filePaths?: string[]): Promise<void> {
3232
await this.syncCore(data, filePaths);
3333
if (this.$options.watch) {
3434
await this.$hooksService.executeBeforeHooks('watch');
35-
this.partialSync(data, data[0].syncWorkingDirectory);
35+
this.partialSync(data, data[0].syncWorkingDirectory, projectId);
3636
}
3737
}
3838

@@ -48,7 +48,7 @@ class LiveSyncServiceBase implements ILiveSyncServiceBase {
4848
return isFileExcluded;
4949
}
5050

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

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

108-
private batchSync(data: ILiveSyncData, filePath: string): void {
108+
private batchSync(data: ILiveSyncData, filePath: string, projectId: string): void {
109109
let platformBatch: ISyncBatch = this.batch[data.platform];
110110
if (!platformBatch || !platformBatch.syncPending) {
111111
let done = () => {
@@ -116,7 +116,7 @@ class LiveSyncServiceBase implements ILiveSyncServiceBase {
116116
let batch = this.batch[platformName];
117117
let livesyncData = this.livesyncData[platformName];
118118
await batch.syncFiles(async (filesToSync: string[]) => {
119-
await this.$liveSyncProvider.preparePlatformForSync(platformName);
119+
await this.$liveSyncProvider.preparePlatformForSync(platformName, projectId);
120120
this.syncCore([livesyncData], filesToSync);
121121
});
122122
}

services/project-files-provider-base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Configurations } from "../constants";
44

55
export abstract class ProjectFilesProviderBase implements IProjectFilesProvider {
66
abstract isFileExcluded(filePath: string): boolean;
7-
abstract mapFilePath(filePath: string, platform: string): string;
7+
abstract mapFilePath(filePath: string, platform: string, projectData: any): string;
88

99
constructor(private $mobileHelper: Mobile.IMobileHelper,
1010
protected $options: ICommonOptions) { }

test/unit-tests/ios-log-filter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ describe("iOSLogFilter", () => {
113113
let testInjector = new Yok();
114114
testInjector.register("loggingLevels", LoggingLevels);
115115
let iOSLogFilter = testInjector.resolve(IOSLogFilter);
116-
let filteredData = iOSLogFilter.filterData(inputData, logLevel, pid);
116+
let filteredData = iOSLogFilter.filterData(inputData, logLevel, "", pid);
117117
assert.deepEqual(filteredData, expectedOutput, `The actual result '${filteredData}' did NOT match expected output '${expectedOutput}'.`);
118118
};
119119

test/unit-tests/log-filter.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,22 @@ describe("logFilter", () => {
6767
describe("filterData", () => {
6868
describe("when logLevel is not specified and default log level is not changed", () => {
6969
it("returns same data when platform is not correct", () => {
70-
let actualData = logFilter.filterData("invalidPlatform", testData);
70+
let actualData = logFilter.filterData("invalidPlatform", testData, "");
7171
assert.deepEqual(actualData, testData);
7272
});
7373

7474
it("returns same data when platform is not passed", () => {
75-
let actualData = logFilter.filterData(null, testData);
75+
let actualData = logFilter.filterData(null, testData, "");
7676
assert.deepEqual(actualData, testData);
7777
});
7878

7979
it("returns correct data when platform is android", () => {
80-
let actualData = logFilter.filterData("android", testData);
80+
let actualData = logFilter.filterData("android", testData, "");
8181
assert.deepEqual(actualData, androidInfoTestData);
8282
});
8383

8484
it("returns correct data when platform is ios", () => {
85-
let actualData = logFilter.filterData("ios", testData);
85+
let actualData = logFilter.filterData("ios", testData, "");
8686
assert.deepEqual(actualData, iosInfoTestData);
8787
});
8888
});
@@ -91,17 +91,17 @@ describe("logFilter", () => {
9191
beforeEach(() => logFilter.loggingLevel = fullLogLevel);
9292

9393
it("returns same data when platform is not correct", () => {
94-
let actualData = logFilter.filterData("invalidPlatform", testData);
94+
let actualData = logFilter.filterData("invalidPlatform", testData, "");
9595
assert.deepEqual(actualData, testData);
9696
});
9797

9898
it("returns correct data when platform is android", () => {
99-
let actualData = logFilter.filterData("android", testData);
99+
let actualData = logFilter.filterData("android", testData, "");
100100
assert.deepEqual(actualData, androidFullTestData);
101101
});
102102

103103
it("returns correct data when platform is ios", () => {
104-
let actualData = logFilter.filterData("ios", testData);
104+
let actualData = logFilter.filterData("ios", testData, "");
105105
assert.deepEqual(actualData, iosFullTestData);
106106
});
107107
});
@@ -134,12 +134,12 @@ describe("logFilter", () => {
134134
});
135135

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

141141
it("returns correct data when platform is ios", () => {
142-
let actualData = logFilter.filterData("ios", testData, null, logLevel);
142+
let actualData = logFilter.filterData("ios", testData, null, null, logLevel);
143143
assert.deepEqual(actualData, iosFullTestData);
144144
});
145145
});

0 commit comments

Comments
 (0)