index.js 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. "use strict";
  2. /**
  3. * Use of this source code is governed by an MIT-style license that can be
  4. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  5. */
  6. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  7. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  8. return new (P || (P = Promise))(function (resolve, reject) {
  9. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  10. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  11. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  12. step((generator = generator.apply(thisArg, _arguments || [])).next());
  13. });
  14. };
  15. Object.defineProperty(exports, "__esModule", { value: true });
  16. exports.default = default_1;
  17. const schematics_1 = require("@angular/cdk/schematics");
  18. const schematics_2 = require("@angular-devkit/schematics");
  19. const tasks_1 = require("@angular-devkit/schematics/tasks");
  20. const workspace_1 = require("@schematics/angular/utility/workspace");
  21. const package_config_1 = require("../utils/package-config");
  22. const project_style_1 = require("../utils/project-style");
  23. // generated by scripts/schematics/set-version.ts
  24. // @ts-ignore
  25. const version_names_1 = require("../utils/version-names");
  26. function default_1(options) {
  27. return (0, schematics_2.chain)([
  28. (host, context) => {
  29. // The CLI inserts `ng-zorro-antd` into the `package.json` before this schematic runs.
  30. // This means that we do not need to insert Angular Material into `package.json` files again.
  31. // In some cases though, it could happen that this schematic runs outside of the CLI `ng add`
  32. // command, or Material is only listed a dev dependency. If that is the case, we insert a
  33. // version based on the current build version (substituted version placeholder).
  34. if (!options.skipPackageJson) {
  35. (0, package_config_1.addPackageToPackageJson)(host, 'ng-zorro-antd', version_names_1.zorroVersion);
  36. if (options.gestures) {
  37. (0, package_config_1.addPackageToPackageJson)(host, 'hammerjs', version_names_1.hammerjsVersion);
  38. }
  39. }
  40. // Since the Angular Material schematics depend on the schematic utility functions from the
  41. // CDK, we need to install the CDK before loading the schematic files that import from the CDK.
  42. if (!options.skipInstall) {
  43. const installTaskId = context.addTask(new tasks_1.NodePackageInstallTask());
  44. context.addTask(new tasks_1.RunSchematicTask('ng-add-setup-project', options), [installTaskId]);
  45. }
  46. },
  47. options.template ? applyTemplate(options) : (0, schematics_2.noop)(),
  48. ]);
  49. }
  50. function applyTemplate(options) {
  51. return (host) => __awaiter(this, void 0, void 0, function* () {
  52. const workspace = yield (0, workspace_1.getWorkspace)(host);
  53. const project = (0, schematics_1.getProjectFromWorkspace)(workspace, options.project);
  54. const style = (0, project_style_1.getProjectStyle)(project);
  55. return (0, schematics_2.schematic)(options.template, Object.assign(Object.assign({}, options), { style }));
  56. });
  57. }
  58. //# sourceMappingURL=index.js.map