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

Commit f15dba7

Browse files
committed
Filter configuration specific files
1 parent c6898cf commit f15dba7

7 files changed

+80
-35
lines changed

declarations.d.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ interface ILiveSyncServiceBase {
867867
* If watch option is not specified executes full sync
868868
* If watch option is specified executes partial sync
869869
*/
870-
sync(data: ILiveSyncData[], projectId: string, filePaths?: string[]): Promise<void>;
870+
sync(data: ILiveSyncData[], projectId: string, projectFilesConfig: IProjectFilesConfig, filePaths?: string[]): Promise<void>;
871871

872872
/**
873873
* Returns the `canExecute` method which defines if LiveSync operation can be executed on specified device.
@@ -1489,7 +1489,7 @@ interface IProjectFilesManager {
14891489
* @param {string[]} excludedDirs Directories which should be skipped.
14901490
* @returns {void}
14911491
*/
1492-
processPlatformSpecificFiles(directoryPath: string, platform: string, excludedDirs?: string[]): void;
1492+
processPlatformSpecificFiles(directoryPath: string, platform: string, projectFilesConfig?: IProjectFilesConfig, excludedDirs?: string[]): void;
14931493
}
14941494

14951495
interface IProjectFilesProvider {
@@ -1500,7 +1500,7 @@ interface IProjectFilesProvider {
15001500
/**
15011501
* Performs local file path mapping
15021502
*/
1503-
mapFilePath(filePath: string, platform: string, projectData?: any): string;
1503+
mapFilePath(filePath: string, platform: string, projectData: any, projectFilesConfig?: IProjectFilesConfig): string;
15041504

15051505
/**
15061506
* Returns information about file in the project, that includes file's name on device after removing platform or configuration from the name.
@@ -1509,13 +1509,13 @@ interface IProjectFilesProvider {
15091509
* @param {IProjectFilesConfig} projectFilesConfig configuration for additional parsing
15101510
* @return {IProjectFileInfo}
15111511
*/
1512-
getProjectFileInfo(filePath: string, platform: string, projectFilesConfig?: IProjectFilesConfig): IProjectFileInfo;
1512+
getProjectFileInfo(filePath: string, platform: string, projectFilesConfig: IProjectFilesConfig): IProjectFileInfo;
15131513
/**
15141514
* Parses file by removing platform or configuration from its name.
15151515
* @param {string} filePath Path to the project file.
15161516
* @return {string} Parsed file name or original file name in case it does not have platform/configuration in the filename.
15171517
*/
1518-
getPreparedFilePath(filePath: string): string;
1518+
getPreparedFilePath(filePath: string, projectFilesConfig: IProjectFilesConfig): string;
15191519
}
15201520

15211521
/**

helpers.ts

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as net from "net";
33
let Table = require("cli-table");
44
import { platform, EOL } from "os";
55
import { ReadStream } from "tty";
6+
import { Configurations } from "../common/constants";
67
import { EventEmitter } from "events";
78

89
export function deferPromise<T>(): IDeferPromise<T> {
@@ -400,6 +401,13 @@ export async function connectEventuallyUntilTimeout(factory: () => net.Socket, t
400401
});
401402
}
402403

404+
export function getProjectFilesConfig(release: boolean): IProjectFilesConfig {
405+
const projectFilesConfig: IProjectFilesConfig = {
406+
configuration: release ? Configurations.Release.toLowerCase() : Configurations.Debug.toLowerCase()
407+
};
408+
return projectFilesConfig;
409+
}
410+
403411
/**
404412
* Tries to find the process id (PID) of the specified application identifier.
405413
* This is specific implementation for iOS Simulator, where the running applications are real processes.

services/livesync-service-base.ts

+4-4
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[], projectId: string, filePaths?: string[]): Promise<void> {
31+
public async sync(data: ILiveSyncData[], projectId: string, projectFilesConfig: IProjectFilesConfig, 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, projectId);
35+
this.partialSync(data, data[0].syncWorkingDirectory, projectId, projectFilesConfig);
3636
}
3737
}
3838

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

51-
private partialSync(data: ILiveSyncData[], syncWorkingDirectory: string, projectId: string): void {
51+
private partialSync(data: ILiveSyncData[], syncWorkingDirectory: string, projectId: string, projectFilesConfig: IProjectFilesConfig): void {
5252
let that = this;
5353
this.showFullLiveSyncInformation = true;
5454
const gazeInstance = gaze(["**/*", "!node_modules/**/*", "!platforms/**/*"], { cwd: syncWorkingDirectory }, function (err: any, watcher: any) {
@@ -76,7 +76,7 @@ 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, projectId);
79+
let mappedFilePath = that.$projectFilesProvider.mapFilePath(filePath, dataItem.platform, projectId, projectFilesConfig);
8080
that.$logger.trace(`Syncing filePath ${filePath}, mappedFilePath is ${mappedFilePath}`);
8181
if (!mappedFilePath) {
8282
that.$logger.warn(`Unable to sync ${filePath}.`);

services/project-files-manager.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,27 @@ export class ProjectFilesManager implements IProjectFilesManager {
3737
return localToDevicePaths;
3838
}
3939

40-
public processPlatformSpecificFiles(directoryPath: string, platform: string, excludedDirs?: string[]): void {
40+
public processPlatformSpecificFiles(directoryPath: string, platform: string, projectFilesConfig: IProjectFilesConfig, excludedDirs?: string[]): void {
4141
let contents = this.$fs.readDirectory(directoryPath);
4242
let files: string[] = [];
4343

4444
_.each(contents, fileName => {
4545
let filePath = path.join(directoryPath, fileName);
4646
let fsStat = this.$fs.getFsStats(filePath);
4747
if (fsStat.isDirectory() && !_.includes(excludedDirs, fileName)) {
48-
this.processPlatformSpecificFilesCore(platform, this.$fs.enumerateFilesInDirectorySync(filePath));
48+
this.processPlatformSpecificFilesCore(platform, this.$fs.enumerateFilesInDirectorySync(filePath), projectFilesConfig);
4949
} else if (fsStat.isFile()) {
5050
files.push(filePath);
5151
}
5252
});
5353

54-
this.processPlatformSpecificFilesCore(platform, files);
54+
this.processPlatformSpecificFilesCore(platform, files, projectFilesConfig);
5555
}
5656

57-
private processPlatformSpecificFilesCore(platform: string, files: string[]): void {
57+
private processPlatformSpecificFilesCore(platform: string, files: string[], projectFilesConfig: IProjectFilesConfig): void {
5858
// Renames the files that have `platform` as substring and removes the files from other platform
5959
_.each(files, filePath => {
60-
let projectFileInfo = this.$projectFilesProvider.getProjectFileInfo(filePath, platform);
60+
let projectFileInfo = this.$projectFilesProvider.getProjectFileInfo(filePath, platform, projectFilesConfig);
6161
if (!projectFileInfo.shouldIncludeFile) {
6262
this.$fs.deleteFile(filePath);
6363
} else if (projectFileInfo.onDeviceFileName) {

services/project-files-provider-base.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@ 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, projectData: any): string;
7+
abstract mapFilePath(filePath: string, platform: string, projectData: any, projectFilesConfig: IProjectFilesConfig): string;
88

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

12-
public getPreparedFilePath(filePath: string): string {
13-
let projectFileInfo = this.getProjectFileInfo(filePath, "");
12+
public getPreparedFilePath(filePath: string, projectFilesConfig?: IProjectFilesConfig): string {
13+
let projectFileInfo = this.getProjectFileInfo(filePath, "", projectFilesConfig);
1414
return path.join(path.dirname(filePath), projectFileInfo.onDeviceFileName);
1515
}
1616

1717
public getProjectFileInfo(filePath: string, platform: string, projectFilesConfig?: IProjectFilesConfig): IProjectFileInfo {
1818
let parsed = this.parseFile(filePath, this.$mobileHelper.platformNames, platform || "");
1919
let basicConfigurations = [Configurations.Debug.toLowerCase(), Configurations.Release.toLowerCase()];
2020
if (!parsed) {
21+
2122
let validValues = basicConfigurations.concat(projectFilesConfig && projectFilesConfig.additionalConfigurations || []),
2223
value = projectFilesConfig && projectFilesConfig.configuration || basicConfigurations[0];
2324
parsed = this.parseFile(filePath, validValues, value);

test/unit-tests/mobile/project-files-manager.ts

+41-5
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,18 @@ function createTestInjector(): IInjector {
104104
}
105105

106106
async function createFiles(testInjector: IInjector, filesToCreate: string[]): Promise<string> {
107-
let fs = testInjector.resolve("fs");
108107
let directoryPath = temp.mkdirSync("Project Files Manager Tests");
109108

110-
_.each(filesToCreate, file => fs.writeFile(path.join(directoryPath, file), ""));
109+
_.each(filesToCreate, file => createFile(testInjector, file, "", directoryPath));
110+
111+
return directoryPath;
112+
}
113+
114+
function createFile(testInjector: IInjector, fileToCreate: string, fileContent: string, directoryPath?: string): string {
115+
let fs = testInjector.resolve("fs");
116+
directoryPath = !directoryPath ? temp.mkdirSync("Project Files Manager Tests") : directoryPath;
117+
118+
fs.writeFile(path.join(directoryPath, fileToCreate), fileContent);
111119

112120
return directoryPath;
113121
}
@@ -170,7 +178,7 @@ describe("Project Files Manager Tests", () => {
170178
let files = ["test.ios.x", "test.android.x"];
171179
let directoryPath = await createFiles(testInjector, files);
172180

173-
projectFilesManager.processPlatformSpecificFiles(directoryPath, "android");
181+
projectFilesManager.processPlatformSpecificFiles(directoryPath, "android", {});
174182

175183
let fs = testInjector.resolve("fs");
176184
assert.isFalse(fs.exists(path.join(directoryPath, "test.ios.x")));
@@ -182,7 +190,7 @@ describe("Project Files Manager Tests", () => {
182190
let files = ["index.ios.html", "index1.android.html", "a.test"];
183191
let directoryPath = await createFiles(testInjector, files);
184192

185-
projectFilesManager.processPlatformSpecificFiles(directoryPath, "ios");
193+
projectFilesManager.processPlatformSpecificFiles(directoryPath, "ios", {});
186194

187195
let fs = testInjector.resolve("fs");
188196
assert.isFalse(fs.exists(path.join(directoryPath, "index1.android.html")));
@@ -191,11 +199,39 @@ describe("Project Files Manager Tests", () => {
191199
assert.isTrue(fs.exists(path.join(directoryPath, "a.test")));
192200
});
193201

202+
it("filters release specific files", async () => {
203+
const directoryPath = await createFile(testInjector, "test.debug.x", "debug");
204+
const releaseFileContent = "release";
205+
await createFile(testInjector, "test.release.x", releaseFileContent, directoryPath);
206+
207+
projectFilesManager.processPlatformSpecificFiles(directoryPath, "android", { configuration: "release" });
208+
209+
const fs = testInjector.resolve("fs");
210+
assert.isFalse(fs.exists(path.join(directoryPath, "test.debug.x")));
211+
assert.isTrue(fs.exists(path.join(directoryPath, "test.x")));
212+
assert.isFalse(fs.exists(path.join(directoryPath, "test.release.x")));
213+
assert.isTrue(fs.readFile(path.join(directoryPath, "test.x")).toString() === releaseFileContent);
214+
});
215+
216+
it("filters debug specific files by default", async () => {
217+
const directoryPath = await createFile(testInjector, "test.release.x", "release");
218+
const debugFileContent = "debug";
219+
await createFile(testInjector, "test.debug.x", debugFileContent, directoryPath);
220+
221+
projectFilesManager.processPlatformSpecificFiles(directoryPath, "android", {});
222+
223+
const fs = testInjector.resolve("fs");
224+
assert.isFalse(fs.exists(path.join(directoryPath, "test.debug.x")));
225+
assert.isTrue(fs.exists(path.join(directoryPath, "test.x")));
226+
assert.isFalse(fs.exists(path.join(directoryPath, "test.release.x")));
227+
assert.isTrue(fs.readFile(path.join(directoryPath, "test.x")).toString() === debugFileContent);
228+
});
229+
194230
it("doesn't filter non platform specific files", async () => {
195231
let files = ["index1.js", "index2.js", "index3.js"];
196232
let directoryPath = await createFiles(testInjector, files);
197233

198-
projectFilesManager.processPlatformSpecificFiles(directoryPath, "ios");
234+
projectFilesManager.processPlatformSpecificFiles(directoryPath, "ios", {});
199235

200236
let fs = testInjector.resolve("fs");
201237
assert.isTrue(fs.exists(path.join(directoryPath, "index1.js")));

test/unit-tests/project-files-provider-base.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -42,49 +42,49 @@ describe("ProjectFilesProviderBase", () => {
4242
describe("getPreparedFilePath", () => {
4343
it("returns correct path, when fileName does not contain platforms", () => {
4444
let filePath = "/test/filePath.ts",
45-
preparedPath = projectFilesProviderBase.getPreparedFilePath(filePath);
45+
preparedPath = projectFilesProviderBase.getPreparedFilePath(filePath, {});
4646

4747
assert.deepEqual(preparedPath, expectedFilePath);
4848
});
4949

5050
it("returns correct path, when fileName contains android platform", () => {
5151
let filePath = "/test/filePath.android.ts",
52-
preparedPath = projectFilesProviderBase.getPreparedFilePath(filePath);
52+
preparedPath = projectFilesProviderBase.getPreparedFilePath(filePath, {});
5353

5454
assert.deepEqual(preparedPath, expectedFilePath);
5555
});
5656

5757
it("returns correct path, when fileName contains ios platform", () => {
5858
let filePath = "/test/filePath.iOS.ts",
59-
preparedPath = projectFilesProviderBase.getPreparedFilePath(filePath);
59+
preparedPath = projectFilesProviderBase.getPreparedFilePath(filePath, {});
6060

6161
assert.deepEqual(preparedPath, expectedFilePath);
6262
});
6363

6464
it("returns correct path, when fileName contains platform (case insensitive test)", () => {
6565
let filePath = "/test/filePath.AnDroId.ts",
66-
preparedPath = projectFilesProviderBase.getPreparedFilePath(filePath);
66+
preparedPath = projectFilesProviderBase.getPreparedFilePath(filePath, {});
6767

6868
assert.deepEqual(preparedPath, expectedFilePath);
6969
});
7070

7171
it("returns correct path, when fileName contains debug configuration", () => {
7272
let filePath = "/test/filePath.debug.ts",
73-
preparedPath = projectFilesProviderBase.getPreparedFilePath(filePath);
73+
preparedPath = projectFilesProviderBase.getPreparedFilePath(filePath, {});
7474

7575
assert.deepEqual(preparedPath, expectedFilePath);
7676
});
7777

7878
it("returns correct path, when fileName contains debug configuration (case insensitive test)", () => {
7979
let filePath = "/test/filePath.DebUG.ts",
80-
preparedPath = projectFilesProviderBase.getPreparedFilePath(filePath);
80+
preparedPath = projectFilesProviderBase.getPreparedFilePath(filePath, {});
8181

8282
assert.deepEqual(preparedPath, expectedFilePath);
8383
});
8484

8585
it("returns correct path, when fileName contains release configuration", () => {
8686
let filePath = "/test/filePath.release.ts",
87-
preparedPath = projectFilesProviderBase.getPreparedFilePath(filePath);
87+
preparedPath = projectFilesProviderBase.getPreparedFilePath(filePath, {});
8888

8989
assert.deepEqual(preparedPath, expectedFilePath);
9090
});
@@ -101,42 +101,42 @@ describe("ProjectFilesProviderBase", () => {
101101

102102
it("process file without platforms in the name", () => {
103103
let filePath = "/test/filePath.ts",
104-
projectFileInfo = projectFilesProviderBase.getProjectFileInfo(filePath, "");
104+
projectFileInfo = projectFilesProviderBase.getProjectFileInfo(filePath, "", {});
105105

106106
assert.deepEqual(projectFileInfo, getExpectedProjectFileInfo(filePath, true));
107107
});
108108

109109
it("process file with android platform in the name", () => {
110110
let filePath = "/test/filePath.android.ts",
111-
projectFileInfo = projectFilesProviderBase.getProjectFileInfo(filePath, "android");
111+
projectFileInfo = projectFilesProviderBase.getProjectFileInfo(filePath, "android", {});
112112

113113
assert.deepEqual(projectFileInfo, getExpectedProjectFileInfo(filePath, true));
114114
});
115115

116116
it("process file with android platform in the name (case insensitive test)", () => {
117117
let filePath = "/test/filePath.AndRoID.ts",
118-
projectFileInfo = projectFilesProviderBase.getProjectFileInfo(filePath, "android");
118+
projectFileInfo = projectFilesProviderBase.getProjectFileInfo(filePath, "android", {});
119119

120120
assert.deepEqual(projectFileInfo, getExpectedProjectFileInfo(filePath, true));
121121
});
122122

123123
it("process file with iOS platform in the name", () => {
124124
let filePath = "/test/filePath.ios.ts",
125-
projectFileInfo = projectFilesProviderBase.getProjectFileInfo(filePath, "android");
125+
projectFileInfo = projectFilesProviderBase.getProjectFileInfo(filePath, "android", {});
126126

127127
assert.deepEqual(projectFileInfo, getExpectedProjectFileInfo(filePath, false));
128128
});
129129

130130
it("process file with debug configuration in the name", () => {
131131
let filePath = "/test/filePath.debug.ts",
132-
projectFileInfo = projectFilesProviderBase.getProjectFileInfo(filePath, "android");
132+
projectFileInfo = projectFilesProviderBase.getProjectFileInfo(filePath, "android", {});
133133

134134
assert.deepEqual(projectFileInfo, getExpectedProjectFileInfo(filePath, true));
135135
});
136136

137137
it("process file with release configuration in the name", () => {
138138
let filePath = "/test/filePath.release.ts",
139-
projectFileInfo = projectFilesProviderBase.getProjectFileInfo(filePath, "android");
139+
projectFileInfo = projectFilesProviderBase.getProjectFileInfo(filePath, "android", {});
140140

141141
assert.deepEqual(projectFileInfo, getExpectedProjectFileInfo(filePath, false));
142142
});

0 commit comments

Comments
 (0)