index.js 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 core_1 = require("@angular-devkit/core");
  19. const schematics_2 = require("@angular-devkit/schematics");
  20. const utility_1 = require("@schematics/angular/utility");
  21. const app_config_1 = require("@schematics/angular/utility/standalone/app_config");
  22. const util_1 = require("@schematics/angular/utility/standalone/util");
  23. const workspace_1 = require("@schematics/angular/utility/workspace");
  24. const apply_changes_1 = require("../../utils/apply-changes");
  25. const root_module_1 = require("../../utils/root-module");
  26. function default_1(options) {
  27. return (host) => __awaiter(this, void 0, void 0, function* () {
  28. const workspace = (yield (0, workspace_1.getWorkspace)(host));
  29. const project = (0, schematics_1.getProjectFromWorkspace)(workspace, options.project);
  30. const mainFile = (0, schematics_1.getProjectMainFile)(project);
  31. const prefix = options.prefix || project.prefix;
  32. const isStandalone = (0, schematics_1.isStandaloneApp)(host, mainFile);
  33. const templateSourcePath = isStandalone ? './standalone' : './files';
  34. return (0, schematics_2.chain)([
  35. (0, schematics_2.mergeWith)((0, schematics_2.apply)((0, schematics_2.url)(`${templateSourcePath}/src`), [
  36. (0, schematics_2.applyTemplates)(Object.assign(Object.assign(Object.assign({}, core_1.strings), options), { prefix })),
  37. (0, schematics_2.move)(project.sourceRoot),
  38. (0, schematics_2.forEach)((fileEntry) => {
  39. if (host.exists(fileEntry.path)) {
  40. host.overwrite(fileEntry.path, fileEntry.content);
  41. }
  42. return fileEntry;
  43. })
  44. ]), schematics_2.MergeStrategy.Overwrite),
  45. isStandalone ? addIconsProvider(options.project, mainFile) : addModules(options.project)
  46. ]);
  47. });
  48. }
  49. function addModules(project) {
  50. return (0, schematics_2.chain)([
  51. (0, root_module_1.addModule)('AppRoutingModule', './app-routing.module', project),
  52. (0, root_module_1.addModule)('IconsProviderModule', './icons-provider.module', project),
  53. (0, root_module_1.addModule)('NzLayoutModule', 'ng-zorro-antd/layout', project),
  54. (0, root_module_1.addModule)('NzMenuModule', 'ng-zorro-antd/menu', project)
  55. ]);
  56. }
  57. function addIconsProvider(project, mainFile) {
  58. return (0, schematics_2.chain)([
  59. importIconDefinitions(mainFile),
  60. (0, utility_1.addRootProvider)(project, ({ code, external }) => {
  61. return code `${external('provideNzIcons', 'ng-zorro-antd/icon')}(icons)`;
  62. })
  63. ]);
  64. }
  65. function importIconDefinitions(mainFile) {
  66. return (host) => __awaiter(this, void 0, void 0, function* () {
  67. const bootstrapCall = (0, util_1.findBootstrapApplicationCall)(host, mainFile);
  68. const appConfig = (0, app_config_1.findAppConfig)(bootstrapCall, host, mainFile);
  69. const appConfigFile = appConfig.filePath;
  70. const appConfigSource = (0, schematics_1.parseSourceFile)(host, appConfig.filePath);
  71. (0, apply_changes_1.applyChangesToFile)(host, appConfigFile, [
  72. (0, schematics_1.insertImport)(appConfigSource, appConfigFile, 'icons', './icons-provider')
  73. ]);
  74. });
  75. }
  76. //# sourceMappingURL=index.js.map