"use strict";
/**
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
 */
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 });
exports.default = default_1;
const schematics_1 = require("@angular/cdk/schematics");
const schematics_2 = require("@angular-devkit/schematics");
const tasks_1 = require("@angular-devkit/schematics/tasks");
const utility_1 = require("@schematics/angular/utility");
const dependencies_1 = require("@schematics/angular/utility/dependencies");
const latest_versions_1 = require("@schematics/angular/utility/latest-versions");
const project_style_1 = require("../utils/project-style");
// generated by scripts/schematics/set-version.ts
// @ts-ignore
const version_names_1 = require("../utils/version-names");
function default_1(options) {
    return (0, schematics_2.chain)([
        (host, context) => {
            // The CLI inserts `ng-zorro-antd` into the `package.json` before this schematic runs.
            // This means that we do not need to insert Angular Material into `package.json` files again.
            // In some cases though, it could happen that this schematic runs outside of the CLI `ng add`
            // command, or Material is only listed a dev dependency. If that is the case, we insert a
            // version based on the current build version (substituted version placeholder).
            if (!options.skipPackageJson) {
                (0, dependencies_1.addPackageJsonDependency)(host, { name: 'ng-zorro-antd', version: version_names_1.zorroVersion, type: dependencies_1.NodeDependencyType.Default });
                if (options.gestures) {
                    (0, dependencies_1.addPackageJsonDependency)(host, { name: 'hammerjs', version: version_names_1.hammerjsVersion, type: dependencies_1.NodeDependencyType.Default });
                }
                // Since Angular CLI v20 no longer installs `less` for the project which prefers `css` or 
                // `scss` as default stylesheet format, and ng-zorro-antd's custom theming requires `less`,
                // we should add `less` as a dev dependency.
                if (options.theme) {
                    (0, dependencies_1.addPackageJsonDependency)(host, { name: 'less', version: latest_versions_1.latestVersions['less'], type: dependencies_1.NodeDependencyType.Dev });
                }
            }
            // Since the Angular Material schematics depend on the schematic utility functions from the
            // CDK, we need to install the CDK before loading the schematic files that import from the CDK.
            if (!options.skipInstall) {
                const installTaskId = context.addTask(new tasks_1.NodePackageInstallTask());
                context.addTask(new tasks_1.RunSchematicTask('ng-add-setup-project', options), [installTaskId]);
            }
        },
        options.template ? applyTemplate(options) : (0, schematics_2.noop)()
    ]);
}
function applyTemplate(options) {
    return (host) => __awaiter(this, void 0, void 0, function* () {
        const workspace = yield (0, utility_1.readWorkspace)(host);
        const project = (0, schematics_1.getProjectFromWorkspace)(workspace, options.project);
        const style = (0, project_style_1.getProjectStyle)(project);
        return (0, schematics_2.schematic)(options.template, Object.assign(Object.assign({}, options), { style }));
    });
}
//# sourceMappingURL=index.js.map