"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ngAdd = ngAdd;
const schematics_1 = require("@angular-devkit/schematics");
const tasks_1 = require("@angular-devkit/schematics/tasks");
const dependencies_1 = require("@schematics/angular/utility/dependencies");
const package_config_1 = require("./package-config");
const pkgJson = require("../../package.json");
function ngAdd() {
    return (tree, context) => {
        const pkg = pkgJson;
        context.logger.info(``);
        context.logger.info(`Installing ${pkg.name} dependencies...`);
        const ngCoreVersionTag = (0, package_config_1.getPackageVersionFromPackageJson)(tree, '@angular/core');
        context.logger.info(`@angular/core version ${ngCoreVersionTag}`);
        if (!ngCoreVersionTag) {
            throw new schematics_1.SchematicsException('@angular/core version not found');
        }
        const projectDeps = [
            { name: '@angular/animations', type: dependencies_1.NodeDependencyType.Default, version: ngCoreVersionTag, overwrite: false },
            { name: '@angular/common', type: dependencies_1.NodeDependencyType.Default, version: ngCoreVersionTag, overwrite: false },
            { name: '@angular/core', type: dependencies_1.NodeDependencyType.Default, version: ngCoreVersionTag, overwrite: false },
            { name: '@angular/forms', type: dependencies_1.NodeDependencyType.Default, version: ngCoreVersionTag, overwrite: false },
            { name: '@angular/router', type: dependencies_1.NodeDependencyType.Default, version: ngCoreVersionTag, overwrite: false }
        ];
        projectDeps.forEach((dep) => {
            (0, dependencies_1.addPackageJsonDependency)(tree, dep);
            context.logger.info(`Added dependency: ${dep.name}@${dep.version}`);
        });
        const libraryDeps = [
            {
                name: '@angular/cdk',
                type: dependencies_1.NodeDependencyType.Default,
                version: pkg.peerDependencies['@angular/cdk'],
                overwrite: false
            },
            {
                name: '@coreui/coreui-pro',
                type: dependencies_1.NodeDependencyType.Default,
                version: pkg.peerDependencies['@coreui/coreui-pro'],
                overwrite: true
            },
            {
                name: '@coreui/icons-angular',
                type: dependencies_1.NodeDependencyType.Default,
                version: pkg.peerDependencies['@coreui/icons-angular'],
                overwrite: true
            },
            {
                name: '@popperjs/core',
                type: dependencies_1.NodeDependencyType.Default,
                version: pkg.dependencies['@popperjs/core'],
                overwrite: true
            }
        ];
        libraryDeps.forEach((dep) => {
            (0, dependencies_1.addPackageJsonDependency)(tree, dep);
            context.logger.info(`Added dependency: ${dep.name}@${dep.version}`);
        });
        const library = {
            name: pkg.name,
            type: dependencies_1.NodeDependencyType.Default,
            version: `~${pkg.version}`,
            overwrite: true
        };
        (0, dependencies_1.addPackageJsonDependency)(tree, library);
        context.logger.info(`Installing ${library.name}@${library.version}`);
        context.addTask(new tasks_1.NodePackageInstallTask());
        return tree;
    };
}
//# sourceMappingURL=index.js.map