project-targets.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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.getProjectTargetOptions = getProjectTargetOptions;
  11. exports.getProjectBuildTargets = getProjectBuildTargets;
  12. exports.getProjectTestTargets = getProjectTestTargets;
  13. const schematics_1 = require("@angular-devkit/schematics");
  14. /** Possible names of CLI builders used to configure the project. */
  15. const PROJECT_BUILDERS = new Set([
  16. '@angular-devkit/build-angular:browser-esbuild',
  17. '@angular-devkit/build-angular:application',
  18. '@angular-devkit/build-angular:browser',
  19. '@angular/build:application',
  20. ]);
  21. /** Possible name of CLI builders used to run tests in the project. */
  22. const TEST_BUILDERS = new Set(['@angular-devkit/build-angular:karma', '@angular/build:karma']);
  23. /** Resolves the architect options for the build target of the given project. */
  24. function getProjectTargetOptions(project, buildTarget) {
  25. var _a, _b;
  26. const options = (_b = (_a = project.targets) === null || _a === void 0 ? void 0 : _a.get(buildTarget)) === null || _b === void 0 ? void 0 : _b.options;
  27. if (!options) {
  28. throw new schematics_1.SchematicsException(`Cannot determine project target configuration for: ${buildTarget}.`);
  29. }
  30. return options;
  31. }
  32. /** Gets all of the default CLI-provided build targets in a project. */
  33. function getProjectBuildTargets(project) {
  34. return getTargetsByBuilderName(project, builder => !!builder && PROJECT_BUILDERS.has(builder));
  35. }
  36. /** Gets all of the default CLI-provided testing targets in a project. */
  37. function getProjectTestTargets(project) {
  38. return getTargetsByBuilderName(project, builder => !!builder && TEST_BUILDERS.has(builder));
  39. }
  40. /** Gets all targets from the given project that pass a predicate check. */
  41. function getTargetsByBuilderName(project, predicate) {
  42. return Array.from(project.targets.keys())
  43. .filter(name => { var _a; return predicate((_a = project.targets.get(name)) === null || _a === void 0 ? void 0 : _a.builder); })
  44. .map(name => project.targets.get(name));
  45. }
  46. //# sourceMappingURL=project-targets.js.map