Code coverage report for lib/services/project-files-manager.js

Statements: 100% (38 / 38)      Branches: 93.75% (15 / 16)      Functions: 100% (9 / 9)      Lines: 100% (38 / 38)      Ignored: none     

All files » lib/services/ » project-files-manager.js
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    1 1 1 1 45 45   1 9 9 9 9 9 20 20 20 4   16 16     9     1 13 13 13 1295 1295 1295 4   1291 4         1 1295 1295 1295 8         1287   1   1 1  
///<reference path="../.d.ts"/>
"use strict";
var path = require("path");
var util = require("util");
var ProjectFilesManager = (function () {
    function ProjectFilesManager($fs, $platformsData) {
        this.$fs = $fs;
        this.$platformsData = $platformsData;
    }
    ProjectFilesManager.prototype.processPlatformSpecificFiles = function (directoryPath, platform, excludedDirs) {
        var _this = this;
        return (function () {
            var contents = _this.$fs.readDirectory(directoryPath).wait();
            var files = [];
            _.each(contents, function (fileName) {
                var filePath = path.join(directoryPath, fileName);
                var fsStat = _this.$fs.getFsStats(filePath).wait();
                if (fsStat.isDirectory() && !_.contains(excludedDirs, fileName)) {
                    _this.processPlatformSpecificFilesCore(platform, _this.$fs.enumerateFilesInDirectorySync(filePath)).wait();
                }
                else Eif (fsStat.isFile()) {
                    files.push(filePath);
                }
            });
            _this.processPlatformSpecificFilesCore(platform, files).wait();
        }).future()();
    };
    ProjectFilesManager.prototype.processPlatformSpecificFilesCore = function (platform, files) {
        var _this = this;
        return (function () {
            _.each(files, function (fileName) {
                var platformInfo = ProjectFilesManager.parsePlatformSpecificFileName(path.basename(fileName), _this.$platformsData.platformsNames);
                var shouldExcludeFile = platformInfo && platformInfo.platform !== platform;
                if (shouldExcludeFile) {
                    _this.$fs.deleteFile(fileName).wait();
                }
                else if (platformInfo && platformInfo.onDeviceName) {
                    _this.$fs.rename(fileName, path.join(path.dirname(fileName), platformInfo.onDeviceName)).wait();
                }
            });
        }).future()();
    };
    ProjectFilesManager.parsePlatformSpecificFileName = function (fileName, platforms) {
        var regex = util.format("^(.+?)\\.(%s)(\\..+?)$", platforms.join("|"));
        var parsed = fileName.match(new RegExp(regex, "i"));
        if (parsed) {
            return {
                platform: parsed[2],
                onDeviceName: parsed[1] + parsed[3]
            };
        }
        return undefined;
    };
    return ProjectFilesManager;
})();
exports.ProjectFilesManager = ProjectFilesManager;
$injector.register("projectFilesManager", ProjectFilesManager);