"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const cli_core_1 = require("@igniteui/cli-core");
const path = require("path");
class EmptyAngularProject {
    constructor() {
        this.id = "angular";
        this.name = "empty";
        this.description = "Ignite UI CLI Default empty project structure for Angular";
        this.dependencies = [];
        this.framework = "angular";
        this.projectType = "ig-ts";
        this.hasExtraConfiguration = false;
        this.delimiters = cli_core_1.defaultDelimiters;
        this.fileSystem = new cli_core_1.FsFileSystem();
    }
    get templatePaths() {
        return [path.join(__dirname, "files")];
    }
    installModules() {
        throw new Error("Method not implemented.");
    }
    upgradeIgniteUIPackages(projectPath, packagePath) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a, _b, _c, _d;
            const config = cli_core_1.ProjectConfig.getConfig();
            const files = config.project.sourceFiles;
            config.project.sourceFiles = files.map(x => {
                if (x === "infragistics.core-lite.js") {
                    return "infragistics.core.js";
                }
                else if (x === "infragistics.lob-lite.js") {
                    return "infragistics.lob.js";
                }
                return x;
            });
            cli_core_1.ProjectConfig.setConfig(config);
            // update angular.json to use and refer to the installed @ignite-ui-full package
            let workspaceConfigObj;
            const workspacePath = path.join(projectPath, "angular.json");
            if (this.fileSystem.fileExists(workspacePath)) {
                workspaceConfigObj = JSON.parse(this.fileSystem.readFile(workspacePath));
                const workspace = workspaceConfigObj.projects[Object.keys(workspaceConfigObj.projects)[0]];
                const styles = workspace.architect.build.options.styles;
                const scripts = workspace.architect.build.options.scripts;
                const freeVersionPath = "ignite-ui";
                const fullVersionPath = "@infragistics/ignite-ui-full/en";
                // update free to full packages - resource location + resource name (if it is different for the full version)
                // optionally: can safely strip ./node_modules/ from path
                for (const script of scripts) {
                    if (!!script.input && ((_a = script.input) === null || _a === void 0 ? void 0 : _a.includes(freeVersionPath))) {
                        script.input = script.input.replace(freeVersionPath, fullVersionPath);
                        script.input = script.input.replace("-lite", "");
                    }
                    if (!!script.bundleName && ((_b = script.bundleName) === null || _b === void 0 ? void 0 : _b.includes("-lite"))) {
                        script.bundleName = script.bundleName.replace("-lite", "");
                    }
                    // edge case: Strip modules/ path from "bundleName": "modules/infragistics.gridexcelexporter.js"
                    if (!!script.bundleName && ((_c = script.bundleName) === null || _c === void 0 ? void 0 : _c.includes("modules/"))) {
                        script.bundleName = script.bundleName.replace("modules/", "");
                    }
                }
                for (const style of styles) {
                    if (!!style.input && ((_d = style.input) === null || _d === void 0 ? void 0 : _d.includes(freeVersionPath))) {
                        style.input = style.input.replace(freeVersionPath, fullVersionPath);
                    }
                }
                this.fileSystem.writeFile(workspacePath, cli_core_1.Util.formatAngularJsonOptions(workspaceConfigObj));
                return true;
            }
            else {
                cli_core_1.Util.log(`No angular.json file found! May have to manually add igniteui-angular-wrappers styles and scripts
			(infragistics.core.js, infragistics.lob.js, etc.) to the corresponding angular.json styles and scripts collections`);
                return false;
            }
        });
    }
    getExtraConfiguration() {
        return [];
    }
    setExtraConfiguration(extraConfigKeys) { }
    generateConfig(name, theme, ...options) {
        return {
            "cliVersion": cli_core_1.Util.version(),
            "dash-name": cli_core_1.Util.lowerDashed(name),
            "description": this.description,
            "dot": ".",
            "name": name,
            "path": name,
            "theme": theme
        };
    }
}
module.exports = new EmptyAngularProject();
