Code coverage report for lib/services/project-data-service.js

Statements: 79.17% (38 / 48)      Branches: 91.67% (11 / 12)      Functions: 69.23% (9 / 13)      Lines: 79.17% (38 / 48)      Ignored: none     

All files » lib/services/ » project-data-service.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    1 1 1 1 26 26 26 26   1 22 15     1 15 15 15 15     1 7 7 7 7 2   7 7     1               1               1 22 22 22 22 15 2   15       1 1   1 1  
///<reference path="../.d.ts"/>
"use strict";
var path = require("path");
var assert = require("assert");
var ProjectDataService = (function () {
    function ProjectDataService($fs, $staticConfig, $errors, $logger) {
        this.$fs = $fs;
        this.$staticConfig = $staticConfig;
        this.$errors = $errors;
        this.$logger = $logger;
    }
    ProjectDataService.prototype.initialize = function (projectDir) {
        if (!this.projectFilePath) {
            this.projectFilePath = path.join(projectDir, this.$staticConfig.PROJECT_FILE_NAME);
        }
    };
    ProjectDataService.prototype.getValue = function (propertyName) {
        var _this = this;
        return (function () {
            _this.loadProjectFile().wait();
            return _this.projectData ? _this.projectData[_this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE][propertyName] : null;
        }).future()();
    };
    ProjectDataService.prototype.setValue = function (key, value) {
        var _this = this;
        return (function () {
            _this.loadProjectFile().wait();
            if (!_this.projectData[_this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE]) {
                _this.projectData[_this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE] = Object.create(null);
            }
            _this.projectData[_this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE][key] = value;
            _this.$fs.writeJson(_this.projectFilePath, _this.projectData, "\t").wait();
        }).future()();
    };
    ProjectDataService.prototype.removeProperty = function (propertyName) {
        var _this = this;
        return (function () {
            _this.loadProjectFile().wait();
            delete _this.projectData[_this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE][propertyName];
            _this.$fs.writeJson(_this.projectFilePath, _this.projectData, "\t").wait();
        }).future()();
    };
    ProjectDataService.prototype.removeDependency = function (dependencyName) {
        var _this = this;
        return (function () {
            _this.loadProjectFile().wait();
            delete _this.projectData[ProjectDataService.DEPENDENCIES_KEY_NAME][dependencyName];
            _this.$fs.writeJson(_this.projectFilePath, _this.projectData, "\t").wait();
        }).future()();
    };
    ProjectDataService.prototype.loadProjectFile = function () {
        var _this = this;
        return (function () {
            assert.ok(_this.projectFilePath, "Initialize method of projectDataService is not called.");
            if (!_this.projectData) {
                if (!_this.$fs.exists(_this.projectFilePath).wait()) {
                    _this.$fs.writeFile(_this.projectFilePath, null).wait();
                }
                _this.projectData = _this.$fs.readJson(_this.projectFilePath).wait() || Object.create(null);
            }
        }).future()();
    };
    ProjectDataService.DEPENDENCIES_KEY_NAME = "dependencies";
    return ProjectDataService;
})();
exports.ProjectDataService = ProjectDataService;
$injector.register("projectDataService", ProjectDataService);