text: "use strict";
  /**
   * @license
   * Copyright Google LLC All Rights Reserved.
   *
   * Use of this source code is governed by an MIT-style license that can be
   * found in the LICENSE file at https://angular.io/license
   */
  Object.defineProperty(exports, "__esModule", { value: true });
  const schematics_1 = require("@angular-devkit/schematics");
  const tasks_1 = require("@angular-devkit/schematics/tasks");
  const validation_1 = require("../utility/validation");
  function default_1(options) {
      if (!options.name) {
          throw new schematics_1.SchematicsException(`Invalid options, "name" is required.`);
      }
      validation_1.validateProjectName(options.name);
      if (!options.directory) {
          options.directory = options.name;
      }
      const workspaceOptions = {
          name: options.name,
          version: options.version,
          newProjectRoot: options.newProjectRoot,
          minimal: options.minimal,
          strict: options.strict,
          packageManager: options.packageManager,
      };
      const applicationOptions = {
          projectRoot: '',
          name: options.name,
          inlineStyle: options.inlineStyle,
          inlineTemplate: options.inlineTemplate,
          prefix: options.prefix,
          viewEncapsulation: options.viewEncapsulation,
          routing: options.routing,
          style: options.style,
          skipTests: options.skipTests,
          skipPackageJson: false,
          // always 'skipInstall' here, so that we do it after the move
          skipInstall: true,
          strict: options.strict,
          minimal: options.minimal,
          legacyBrowsers: options.legacyBrowsers || undefined,
      };
      return schematics_1.chain([
          schematics_1.mergeWith(schematics_1.apply(schematics_1.empty(), [
              schematics_1.schematic('workspace', workspaceOptions),
              options.createApplication ? schematics_1.schematic('application', applicationOptions) : schematics_1.noop,
              schematics_1.move(options.directory),
          ])),
          (_host, context) => {
              let packageTask;
              if (!options.skipInstall) {
                  packageTask = context.addTask(new tasks_1.NodePackageInstallTask({
                      workingDirectory: options.directory,
                      packageManager: options.packageManager,
                  }));
                  if (options.linkCli) {
                      packageTask = context.addTask(new tasks_1.NodePackageLinkTask('@angular/cli', options.directory), [packageTask]);
                  }
              }
              if (!options.skipGit) {
                  const commit = typeof options.commit == 'object' ? options.commit : options.commit ? {} : false;
                  context.addTask(new tasks_1.RepositoryInitializerTask(options.directory, commit), packageTask ? [packageTask] : []);
              }
          },
      ]);
  }
  exports.default = default_1;
  