"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TemplateManager = void 0;
const angular_templates_1 = require("@igniteui/angular-templates");
const cli_core_1 = require("@igniteui/cli-core");
const path = require("path");
const AngularTemplate_1 = require("./templates/AngularTemplate");
const IgniteUIForWebComponentsTemplate_1 = require("./templates/IgniteUIForWebComponentsTemplate");
const jQueryTemplate_1 = require("./templates/jQueryTemplate");
const ReactTemplate_1 = require("./templates/ReactTemplate");
const TEMPLATES_PATH = "../templates";
class TemplateManager extends cli_core_1.BaseTemplateManager {
    constructor(templatesPath) {
        super(path.join(__dirname, templatesPath || TEMPLATES_PATH));
    }
    /**
     * Loads properties from a JSON file and initializes a base Template implementation
     * @param filePath Path to a json config file representing a template
     * @returns null if no proper file is found
     */
    loadFromConfig(filePath) {
        let template = null;
        if (cli_core_1.Util.fileExists(filePath)) {
            const rootPath = path.dirname(filePath);
            const settings = require(filePath);
            switch (`${settings.framework}|${settings.projectType}`) {
                case "jquery|js":
                    template = new jQueryTemplate_1.jQueryTemplate(rootPath);
                    break;
                case "react|es6":
                    template = new ReactTemplate_1.ReactTemplate(rootPath);
                    break;
                case "angular|ig-ts":
                    template = new AngularTemplate_1.AngularTemplate(rootPath);
                    break;
                case "angular|igx-ts":
                    template = new angular_templates_1.IgniteUIForAngularTemplate(rootPath);
                    break;
                case "webcomponents|igc-ts":
                    template = new IgniteUIForWebComponentsTemplate_1.IgniteUIForWebComponentsTemplate(rootPath);
                    break;
                default:
                    cli_core_1.Util.error(`The framework/project type for template with id "${settings.id}" is not supported.`);
                    cli_core_1.Util.error(`File path: ${filePath}`);
                    break;
            }
            if (template !== null) {
                Object.assign(template, settings);
            }
        }
        return template;
    }
}
exports.TemplateManager = TemplateManager;
