index.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. "use strict";
  2. /**
  3. * @license
  4. * Copyright Google LLC All Rights Reserved.
  5. *
  6. * Use of this source code is governed by an MIT-style license that can be
  7. * found in the LICENSE file at https://angular.io/license
  8. */
  9. Object.defineProperty(exports, "__esModule", { value: true });
  10. const tasks_1 = require("@angular-devkit/schematics/tasks");
  11. const package_config_1 = require("./package-config");
  12. const version_names_1 = require("./version-names");
  13. /**
  14. * Schematic factory entry-point for the `ng-add` schematic. The ng-add schematic will be
  15. * automatically executed if developers run `ng add @angular/material`.
  16. *
  17. * Since the Angular Material schematics depend on the schematic utility functions from the CDK,
  18. * we need to install the CDK before loading the schematic files that import from the CDK.
  19. */
  20. function default_1(options) {
  21. return (host, context) => {
  22. // Version tag of the `@angular/core` dependency that has been loaded from the `package.json`
  23. // of the CLI project. This tag should be preferred because all Angular dependencies should
  24. // have the same version tag if possible.
  25. const ngCoreVersionTag = package_config_1.getPackageVersionFromPackageJson(host, '@angular/core');
  26. const angularDependencyVersion = ngCoreVersionTag || version_names_1.requiredAngularVersionRange;
  27. // In order to align the Material and CDK version with the other Angular dependencies,
  28. // we use tilde instead of caret. This is default for Angular dependencies in new CLI projects.
  29. package_config_1.addPackageToPackageJson(host, '@angular/cdk', `~${version_names_1.materialVersion}`);
  30. package_config_1.addPackageToPackageJson(host, '@angular/material', `~${version_names_1.materialVersion}`);
  31. package_config_1.addPackageToPackageJson(host, '@angular/forms', angularDependencyVersion);
  32. package_config_1.addPackageToPackageJson(host, '@angular/animations', angularDependencyVersion);
  33. if (options.gestures) {
  34. package_config_1.addPackageToPackageJson(host, 'hammerjs', version_names_1.hammerjsVersion);
  35. }
  36. // Since the Angular Material schematics depend on the schematic utility functions from the
  37. // CDK, we need to install the CDK before loading the schematic files that import from the CDK.
  38. const installTaskId = context.addTask(new tasks_1.NodePackageInstallTask());
  39. context.addTask(new tasks_1.RunSchematicTask('ng-add-setup-project', options), [installTaskId]);
  40. };
  41. }
  42. exports.default = default_1;
  43. //# sourceMappingURL=index.js.map