index.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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.dev/license
  8. */
  9. Object.defineProperty(exports, "__esModule", { value: true });
  10. exports.default = default_1;
  11. const schematics_1 = require("@angular-devkit/schematics");
  12. const add_declaration_to_ng_module_1 = require("../utility/add-declaration-to-ng-module");
  13. const find_module_1 = require("../utility/find-module");
  14. const parse_name_1 = require("../utility/parse-name");
  15. const validation_1 = require("../utility/validation");
  16. const workspace_1 = require("../utility/workspace");
  17. function default_1(options) {
  18. return async (host) => {
  19. options.path ??= await (0, workspace_1.createDefaultPath)(host, options.project);
  20. options.module = (0, find_module_1.findModuleFromOptions)(host, options);
  21. const parsedPath = (0, parse_name_1.parseName)(options.path, options.name);
  22. options.name = parsedPath.name;
  23. options.path = parsedPath.path;
  24. (0, validation_1.validateClassName)(schematics_1.strings.classify(options.name));
  25. const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
  26. options.skipTests ? (0, schematics_1.filter)((path) => !path.endsWith('.spec.ts.template')) : (0, schematics_1.noop)(),
  27. (0, schematics_1.applyTemplates)({
  28. ...schematics_1.strings,
  29. 'if-flat': (s) => (options.flat ? '' : s),
  30. ...options,
  31. }),
  32. (0, schematics_1.move)(parsedPath.path),
  33. ]);
  34. return (0, schematics_1.chain)([
  35. (0, add_declaration_to_ng_module_1.addDeclarationToNgModule)({
  36. type: 'pipe',
  37. ...options,
  38. }),
  39. (0, schematics_1.mergeWith)(templateSource),
  40. ]);
  41. };
  42. }