forked from NativeScript/nativescript-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject-files-provider.ts
More file actions
101 lines (94 loc) · 2.86 KB
/
project-files-provider.ts
File metadata and controls
101 lines (94 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { minimatch } from "minimatch";
import * as constants from "../constants";
import * as path from "path";
import * as _ from "lodash";
import { ProjectFilesProviderBase } from "../common/services/project-files-provider-base";
import { IPlatformsDataService } from "../definitions/platform";
import { IOptions } from "../declarations";
import { IProjectData } from "../definitions/project";
import { IProjectFilesConfig } from "../common/declarations";
import { injector } from "../common/yok";
export class ProjectFilesProvider extends ProjectFilesProviderBase {
constructor(
private $platformsDataService: IPlatformsDataService,
$mobileHelper: Mobile.IMobileHelper,
$options: IOptions
) {
super($mobileHelper, $options);
}
private static INTERNAL_NONPROJECT_FILES = ["**/*.ts"];
public mapFilePath(
filePath: string,
platform: string,
projectData: IProjectData,
projectFilesConfig: IProjectFilesConfig
): string {
const platformData = this.$platformsDataService.getPlatformData(
platform.toLowerCase(),
projectData
);
const parsedFilePath = this.getPreparedFilePath(
filePath,
projectFilesConfig
);
let mappedFilePath = "";
let relativePath;
if (parsedFilePath.indexOf(constants.NODE_MODULES_FOLDER_NAME) > -1) {
relativePath = path.relative(
path.join(projectData.projectDir, constants.NODE_MODULES_FOLDER_NAME),
parsedFilePath
);
mappedFilePath = path.join(
platformData.appDestinationDirectoryPath,
constants.APP_FOLDER_NAME,
constants.TNS_MODULES_FOLDER_NAME,
relativePath
);
} else {
relativePath = path.relative(
projectData.appDirectoryPath,
parsedFilePath
);
mappedFilePath = path.join(
platformData.appDestinationDirectoryPath,
this.$options.nativeHostModule,
relativePath
);
}
const appResourcesDirectoryPath = projectData.appResourcesDirectoryPath;
const platformSpecificAppResourcesDirectoryPath = path.join(
appResourcesDirectoryPath,
platformData.normalizedPlatformName
);
if (
parsedFilePath.indexOf(appResourcesDirectoryPath) > -1 &&
parsedFilePath.indexOf(platformSpecificAppResourcesDirectoryPath) === -1
) {
return null;
}
if (
parsedFilePath.indexOf(platformSpecificAppResourcesDirectoryPath) > -1
) {
const appResourcesRelativePath = path.relative(
path.join(
projectData.appResourcesDirectoryPath,
platformData.normalizedPlatformName
),
parsedFilePath
);
mappedFilePath = path.join(
platformData.platformProjectService.getAppResourcesDestinationDirectoryPath(
projectData
),
appResourcesRelativePath
);
}
return mappedFilePath;
}
public isFileExcluded(filePath: string): boolean {
return !!_.find(ProjectFilesProvider.INTERNAL_NONPROJECT_FILES, (pattern) =>
minimatch(filePath, pattern, { nocase: true })
);
}
}
injector.register("projectFilesProvider", ProjectFilesProvider);