Code coverage report for lib/common/project-helper.js

Statements: 89.8% (44 / 49)      Branches: 66.67% (12 / 18)      Functions: 100% (7 / 7)      Lines: 89.58% (43 / 48)      Ignored: none     

All files » lib/common/ » project-helper.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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73    1 1 1 30 30 30 30 30 30   1   28     28 28 28 46 46 46 25 25 25   21 21 3 3   18   28         1 1 1 1             1   1 1033 28   1 26 26 26 26 26               1   1 1  
///<reference path=".d.ts"/>
"use strict";
var path = require("path");
var ProjectHelper = (function () {
    function ProjectHelper($logger, $fs, $staticConfig, $errors, $options) {
        this.$logger = $logger;
        this.$fs = $fs;
        this.$staticConfig = $staticConfig;
        this.$errors = $errors;
        this.$options = $options;
        this.cachedProjectDir = "";
    }
    Object.defineProperty(ProjectHelper.prototype, "projectDir", {
        get: function () {
            Iif (this.cachedProjectDir !== "") {
                return this.cachedProjectDir;
            }
            this.cachedProjectDir = null;
            var projectDir = path.resolve(this.$options.path || ".");
            while (true) {
                this.$logger.trace("Looking for project in '%s'", projectDir);
                var projectFilePath = path.join(projectDir, this.$staticConfig.PROJECT_FILE_NAME);
                if (this.$fs.exists(projectFilePath).wait() && this.isProjectFileCorrect(projectFilePath)) {
                    this.$logger.debug("Project directory is '%s'.", projectDir);
                    this.cachedProjectDir = projectDir;
                    break;
                }
                var dir = path.dirname(projectDir);
                if (dir === projectDir) {
                    this.$logger.debug("No project found at or above '%s'.", this.$options.path || path.resolve("."));
                    break;
                }
                projectDir = dir;
            }
            return this.cachedProjectDir;
        },
        enumerable: true,
        configurable: true
    });
    ProjectHelper.prototype.generateDefaultAppId = function (appName, baseAppId) {
        var sanitizedName = this.sanitizeName(appName);
        Eif (sanitizedName) {
            Iif (/^\d+$/.test(sanitizedName)) {
                sanitizedName = "the" + sanitizedName;
            }
        }
        else {
            sanitizedName = "the";
        }
        return baseAppId + "." + sanitizedName;
    };
    ProjectHelper.prototype.sanitizeName = function (appName) {
        var sanitizedName = _.filter(appName.split(""), function (c) { return /[a-zA-Z0-9]/.test(c); }).join("");
        return sanitizedName;
    };
    ProjectHelper.prototype.isProjectFileCorrect = function (projectFilePath) {
        Eif (this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE) {
            try {
                var fileContent = this.$fs.readJson(projectFilePath).wait();
                var clientSpecificData = fileContent[this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE];
                return !!clientSpecificData;
            }
            catch (err) {
                this.$errors.failWithoutHelp("The project file is corrupted. Additional technical information: %s", err);
            }
        }
        return true;
    };
    return ProjectHelper;
})();
exports.ProjectHelper = ProjectHelper;
$injector.register("projectHelper", ProjectHelper);