"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProjectFilesProvider = void 0;
const minimatch_1 = require("minimatch");
const constants = require("../constants");
const path = require("path");
const _ = require("lodash");
const project_files_provider_base_1 = require("../common/services/project-files-provider-base");
const yok_1 = require("../common/yok");
class ProjectFilesProvider extends project_files_provider_base_1.ProjectFilesProviderBase {
    constructor($platformsDataService, $mobileHelper, $options) {
        super($mobileHelper, $options);
        this.$platformsDataService = $platformsDataService;
    }
    mapFilePath(filePath, platform, projectData, projectFilesConfig) {
        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.hostProjectModuleName, 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;
    }
    isFileExcluded(filePath) {
        return !!_.find(ProjectFilesProvider.INTERNAL_NONPROJECT_FILES, (pattern) => (0, minimatch_1.minimatch)(filePath, pattern, { nocase: true }));
    }
}
ProjectFilesProvider.INTERNAL_NONPROJECT_FILES = ["**/*.ts"];
exports.ProjectFilesProvider = ProjectFilesProvider;
yok_1.injector.register("projectFilesProvider", ProjectFilesProvider);
//# sourceMappingURL=project-files-provider.js.map