"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
exports.defaultPort = 3333;
class LocalDevServerConfiguration {
    constructor(configFilePath) {
        this._onProxyReq = function () { };
        this._liveReload = true;
        this.entryPoint = '';
        if (configFilePath) {
            let jsonFileContents = null;
            if (fs_1.default.existsSync(configFilePath)) {
                try {
                    jsonFileContents = fs_1.default.readFileSync(configFilePath, 'utf-8');
                }
                catch (e) {
                    console.error(`Loading file ${configFilePath} failed with error: ${e}`);
                }
            }
            if (jsonFileContents !== null && jsonFileContents !== '') {
                try {
                    this.configFromJson = JSON.parse(jsonFileContents);
                }
                catch (e) {
                    console.error(`Loading JSON in '${configFilePath}' failed with the error ${e.message}`);
                    this.configFromJson = {};
                }
            }
            else {
                this.configFromJson = {};
            }
        }
        else {
            this.configFromJson = {};
        }
        if (this.configFromJson.hasOwnProperty('liveReload')) {
            this._liveReload = !!this.configFromJson.liveReload;
        }
    }
    get containerType() {
        return this.configFromJson.containerType || 'component';
    }
    get entryPointComponent() {
        const entryPoint = this.entryPoint || this.configFromJson.main;
        if (!entryPoint) {
            return '';
        }
        if (!entryPoint.includes('/')) {
            return `${this.namespace}/${entryPoint}`;
        }
        return entryPoint;
    }
    get namespace() {
        return this.configFromJson.namespace || 'c';
    }
    set namespace(namespace) {
        this.configFromJson.namespace = namespace;
    }
    get modulesSourceDirectory() {
        return this.configFromJson.modulesSourceDirectory || '';
    }
    set modulesSourceDirectory(directory) {
        this.configFromJson.modulesSourceDirectory = directory;
    }
    get staticResourcesDirectory() {
        return this.configFromJson.staticResourcesDirectory || '';
    }
    set staticResourcesDirectory(directory) {
        this.configFromJson.staticResourcesDirectory = directory;
    }
    get customLabelsFile() {
        return this.configFromJson.customLabelsFile || '';
    }
    set customLabelsFile(file) {
        this.configFromJson.customLabelsFile = file;
    }
    get port() {
        let port = this.configFromJson.port;
        if (port !== undefined && port !== null && port !== '') {
            return port * 1;
        }
        return exports.defaultPort;
    }
    set port(port) {
        this.configFromJson.port = port;
    }
    get api_version() {
        return this.configFromJson.api_version;
    }
    set api_version(api_version) {
        this.configFromJson.api_version = api_version;
    }
    get endpoint() {
        return this.configFromJson.endpoint;
    }
    set endpoint(endpoint) {
        this.configFromJson.endpoint = endpoint;
    }
    get onProxyReq() {
        return this._onProxyReq || function () { };
    }
    set onProxyReq(onProxyReq) {
        this._onProxyReq = onProxyReq;
    }
    get liveReload() {
        return this._liveReload;
    }
    set liveReload(liveReload) {
        this._liveReload = liveReload;
    }
    configureFromCliArguments(config) {
        if (config.hasOwnProperty('main')) {
            this.entryPoint = config.main;
        }
    }
}
exports.default = LocalDevServerConfiguration;
//# sourceMappingURL=LocalDevServerConfiguration.js.map