Skip to content

Commit 3965c4b

Browse files
Merge pull request #1551 from NativeScript/vladimirov/livesync-platform-files
Fix livesync of platform/configuration specific files
2 parents f456ecf + d221069 commit 3965c4b

File tree

5 files changed

+106
-9
lines changed

5 files changed

+106
-9
lines changed

lib/declarations.ts

-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ interface IOptions extends ICommonOptions {
6565
frameworkVersion: string;
6666
copyFrom: string;
6767
linkTo: string;
68-
release: boolean;
6968
emulator: boolean;
7069
symlink: boolean;
7170
forDevice: boolean;

lib/options.ts

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export class Options extends commonOptionsLibPath.OptionsBase {
1818
frameworkVersion: { type: OptionType.String },
1919
copyFrom: { type: OptionType.String },
2020
linkTo: { type: OptionType.String },
21-
release: { type: OptionType.Boolean },
2221
symlink: { type: OptionType.Boolean },
2322
forDevice: { type: OptionType.Boolean },
2423
client: { type: OptionType.Boolean, default: true},

lib/providers/project-files-provider.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,33 @@
44
import minimatch = require("minimatch");
55
import * as constants from "../constants";
66
import * as path from "path";
7+
import { ProjectFilesProviderBase } from "../common/services/project-files-provider-base";
78

8-
export class ProjectFilesProvider implements IProjectFilesProvider {
9+
export class ProjectFilesProvider extends ProjectFilesProviderBase {
910
constructor(private $platformsData: IPlatformsData,
10-
private $projectData: IProjectData) { }
11+
private $projectData: IProjectData,
12+
$mobileHelper: Mobile.IMobileHelper,
13+
$options:IOptions) {
14+
super($mobileHelper, $options);
15+
}
1116

1217
private static INTERNAL_NONPROJECT_FILES = [ "**/*.ts" ];
1318

1419
public mapFilePath(filePath: string, platform: string): string {
1520
let platformData = this.$platformsData.getPlatformData(platform.toLowerCase());
1621
let projectFilesPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME);
17-
let mappedFilePath = path.join(projectFilesPath, path.relative(path.join(this.$projectData.projectDir, constants.APP_FOLDER_NAME), filePath));
22+
let parsedFilePath = this.getPreparedFilePath(filePath);
23+
let mappedFilePath = path.join(projectFilesPath, path.relative(path.join(this.$projectData.projectDir, constants.APP_FOLDER_NAME), parsedFilePath));
1824

1925
let appResourcesDirectoryPath = path.join(constants.APP_FOLDER_NAME, constants.APP_RESOURCES_FOLDER_NAME);
2026
let platformSpecificAppResourcesDirectoryPath = path.join(appResourcesDirectoryPath, platformData.normalizedPlatformName);
21-
if (filePath.indexOf(appResourcesDirectoryPath) > -1 && filePath.indexOf(platformSpecificAppResourcesDirectoryPath) === -1) {
27+
if (parsedFilePath.indexOf(appResourcesDirectoryPath) > -1 && parsedFilePath.indexOf(platformSpecificAppResourcesDirectoryPath) === -1) {
2228
return null;
2329
}
24-
if (filePath.indexOf(platformSpecificAppResourcesDirectoryPath) > -1) {
30+
31+
if (parsedFilePath.indexOf(platformSpecificAppResourcesDirectoryPath) > -1) {
2532
let appResourcesRelativePath = path.relative(path.join(this.$projectData.projectDir, constants.APP_FOLDER_NAME, constants.APP_RESOURCES_FOLDER_NAME,
26-
platformData.normalizedPlatformName), filePath);
33+
platformData.normalizedPlatformName), parsedFilePath);
2734
mappedFilePath = path.join(platformData.platformProjectService.getAppResourcesDestinationDirectoryPath().wait(), appResourcesRelativePath);
2835
}
2936

test/project-files-provider.ts

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/// <reference path=".d.ts" />
2+
"use strict";
3+
4+
import { Yok } from "../lib/common/yok";
5+
import { ProjectFilesProvider } from "../lib/providers/project-files-provider";
6+
import { assert } from "chai";
7+
import * as path from "path";
8+
import Future = require("fibers/future");
9+
10+
let projectDir = "projectDir",
11+
appDestinationDirectoryPath = "appDestinationDirectoryPath",
12+
appResourcesDestinationDirectoryPath = "appResourcesDestinationDirectoryPath",
13+
appSourceDir = path.join(projectDir, "app");
14+
15+
function createTestInjector(): IInjector {
16+
let testInjector = new Yok();
17+
testInjector.register("mobileHelper", {
18+
platformNames: ["Android", "iOS"]
19+
});
20+
21+
testInjector.register("platformsData", {
22+
getPlatformData: (platform: string) => {
23+
return {
24+
appDestinationDirectoryPath: appDestinationDirectoryPath,
25+
normalizedPlatformName: platform.toLowerCase(),
26+
platformProjectService: {
27+
getAppResourcesDestinationDirectoryPath: () => Future.fromResult(appResourcesDestinationDirectoryPath)
28+
}
29+
};
30+
},
31+
});
32+
33+
testInjector.register("projectData", {
34+
projectDir: projectDir
35+
});
36+
37+
testInjector.register("options", { release: false });
38+
39+
return testInjector;
40+
}
41+
42+
describe("project-files-provider", () => {
43+
let testInjector: IInjector,
44+
projectFilesProvider: IProjectFilesProvider;
45+
46+
beforeEach(() => {
47+
testInjector = createTestInjector();
48+
projectFilesProvider = testInjector.resolve(ProjectFilesProvider);
49+
});
50+
51+
describe("isFileExcluded", () => {
52+
it("returns true for .ts files", () => {
53+
assert.isTrue(projectFilesProvider.isFileExcluded("test.ts"));
54+
});
55+
56+
it("returns false for .js files", () => {
57+
assert.isFalse(projectFilesProvider.isFileExcluded("test.js"));
58+
});
59+
});
60+
61+
describe("mapFilePath", () => {
62+
it("returns file path from prepared project when path from app dir is passed", () => {
63+
let mappedFilePath = projectFilesProvider.mapFilePath(path.join(appSourceDir, "test.js"), "android");
64+
assert.deepEqual(mappedFilePath, path.join(appDestinationDirectoryPath, "app", "test.js"));
65+
});
66+
67+
it("returns file path from prepared project when path from app/App_Resources/platform dir is passed", () => {
68+
let mappedFilePath = projectFilesProvider.mapFilePath(path.join(appSourceDir, "App_Resources", "android", "test.js"), "android");
69+
assert.deepEqual(mappedFilePath, path.join(appResourcesDestinationDirectoryPath, "test.js"));
70+
});
71+
72+
it("returns null when path from app/App_Resources/android dir is passed and iOS platform is specified", () => {
73+
let mappedFilePath = projectFilesProvider.mapFilePath(path.join(appSourceDir, "App_Resources", "android", "test.js"), "iOS");
74+
assert.deepEqual(mappedFilePath, null);
75+
});
76+
77+
it("returns null when path from app/App_Resources/ dir (not platform specific) is passed", () => {
78+
let mappedFilePath = projectFilesProvider.mapFilePath(path.join(appSourceDir, "App_Resources", "test.js"), "android");
79+
assert.deepEqual(mappedFilePath, null);
80+
});
81+
82+
it("returns file path from prepared project when path from app dir is passed and it contains platform in its name", () => {
83+
let mappedFilePath = projectFilesProvider.mapFilePath(path.join(appSourceDir, "test.android.js"), "android");
84+
assert.deepEqual(mappedFilePath, path.join(appDestinationDirectoryPath, "app", "test.js"));
85+
});
86+
87+
it("returns file path from prepared project when path from app dir is passed and it contains configuration in its name", () => {
88+
let mappedFilePath = projectFilesProvider.mapFilePath(path.join(appSourceDir, "test.debug.js"), "android");
89+
assert.deepEqual(mappedFilePath, path.join(appDestinationDirectoryPath, "app", "test.js"));
90+
});
91+
});
92+
});

0 commit comments

Comments
 (0)