"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 utility_1 = require("@schematics/angular/utility");
const config_1 = require("../../utils/config");
const root_module_1 = require("../../utils/root-module");
function default_1(options) {
    return (host) => __awaiter(this, void 0, void 0, function* () {
        var _a;
        const workspace = yield (0, utility_1.readWorkspace)(host);
        const project = (0, schematics_1.getProjectFromWorkspace)(workspace, options.project);
        const mainFile = (0, schematics_1.getProjectMainFile)(project);
        const { componentOptions, sourceDir } = yield (0, config_1.getAppOptions)(options.project, project.root);
        const prefix = options.prefix || project.prefix;
        const style = options.style || componentOptions.style;
        const exportDefault = (_a = componentOptions.exportDefault) !== null && _a !== void 0 ? _a : false;
        const isStandalone = (0, schematics_1.isStandaloneApp)(host, mainFile);
        const templateSourcePath = isStandalone ? './standalone' : './files';
        return (0, schematics_2.chain)([
            (0, schematics_2.mergeWith)((0, schematics_2.apply)((0, schematics_2.url)(`${templateSourcePath}/src`), [
                (0, schematics_2.applyTemplates)(Object.assign(Object.assign(Object.assign({}, schematics_2.strings), componentOptions), { exportDefault,
                    prefix,
                    style })),
                (0, schematics_2.move)(project.sourceRoot),
                (0, schematics_2.forEach)((fileEntry) => {
                    if (host.exists(fileEntry.path)) {
                        host.overwrite(fileEntry.path, fileEntry.content);
                    }
                    return fileEntry;
                })
            ]), schematics_2.MergeStrategy.Overwrite),
            (0, schematics_2.schematic)('component', Object.assign(Object.assign({ name: 'welcome', project: options.project, standalone: isStandalone }, componentOptions), { path: `${sourceDir}/pages`, skipImport: true, skipTests: true, prefix,
                style })),
            isStandalone ? (0, schematics_2.noop)() : addModules(options.project)
        ]);
    });
}
function addModules(project) {
    return (0, schematics_2.chain)([
        (0, root_module_1.addModule)('AppRoutingModule', './app-routing-module', project),
        (0, root_module_1.addModule)('NzLayoutModule', 'ng-zorro-antd/layout', project),
        (0, root_module_1.addModule)('NzMenuModule', 'ng-zorro-antd/menu', project)
    ]);
}
//# sourceMappingURL=index.js.map