"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var libs_1 = require("../common/libs");
exports.NpmPackage = libs_1.NpmPackage;
var ElectronSettings_1 = require("./ElectronSettings");
var WebSettings_1 = require("./WebSettings");
var UIHARNESS_YAML = 'uiharness.yml';
var defaultValue = libs_1.value.defaultValue;
var Settings = (function () {
    function Settings(path) {
        this.path = path;
        this.dir = libs_1.fsPath.dirname(path);
        this.exists = libs_1.fs.existsSync(path);
        this.data = this.exists ? Settings.load(path) : {};
    }
    Settings.create = function (path) {
        path = path ? path : '.';
        path = path.trim();
        path = libs_1.fsPath.resolve(path);
        var lstat = libs_1.fs.existsSync(path) ? libs_1.fs.lstatSync(path) : undefined;
        path =
            lstat && lstat.isDirectory() ? libs_1.fsPath.join(path, UIHARNESS_YAML) : path;
        return new Settings(path);
    };
    Settings.load = function (path) {
        try {
            return libs_1.file.loadAndParseSync(path, {});
        }
        catch (error) {
            libs_1.log.error('💥  ERROR UIHarness');
            libs_1.log.info.yellow("Failed to load UIHarness congfig at path '" + path + "'.");
            libs_1.log.info.yellow(error.message);
            throw error;
        }
    };
    Object.defineProperty(Settings.prototype, "package", {
        get: function () {
            return this._package || (this._package = libs_1.npm.pkg(this.dir));
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Settings.prototype, "electron", {
        get: function () {
            return (this._electron ||
                (this._electron = new ElectronSettings_1.ElectronSettings({
                    dir: this.dir,
                    data: this.data.electron,
                })));
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Settings.prototype, "web", {
        get: function () {
            return (this._web ||
                (this._web = new WebSettings_1.WebSettings({
                    dir: this.dir,
                    data: this.data.web,
                })));
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Settings.prototype, "init", {
        get: function () {
            var init = this.data.init || {};
            return {
                scripts: defaultValue(init.scripts, true),
                files: defaultValue(init.files, true),
                html: defaultValue(init.html, true),
                deps: defaultValue(init.deps, true),
            };
        },
        enumerable: true,
        configurable: true
    });
    return Settings;
}());
exports.Settings = Settings;
//# sourceMappingURL=Settings.js.map