index.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 utility_1 = require("@schematics/angular/utility");
  13. const node_path_1 = require("node:path");
  14. const json_file_1 = require("../utility/json-file");
  15. const latest_versions_1 = require("../utility/latest-versions");
  16. /**
  17. * The list of development dependencies used by the E2E protractor-based builder.
  18. * The versions are sourced from the latest versions `../utility/latest-versions/package.json`
  19. * file which is automatically updated via renovate.
  20. */
  21. const E2E_DEV_DEPENDENCIES = Object.freeze([
  22. 'protractor',
  23. 'jasmine-spec-reporter',
  24. 'ts-node',
  25. '@types/node',
  26. ]);
  27. function addScriptsToPackageJson() {
  28. return (host) => {
  29. const pkgJson = new json_file_1.JSONFile(host, 'package.json');
  30. const e2eScriptPath = ['scripts', 'e2e'];
  31. if (!pkgJson.get(e2eScriptPath)) {
  32. pkgJson.modify(e2eScriptPath, 'ng e2e', false);
  33. }
  34. };
  35. }
  36. function default_1(options) {
  37. const { relatedAppName } = options;
  38. return (0, utility_1.updateWorkspace)((workspace) => {
  39. const project = workspace.projects.get(relatedAppName);
  40. if (!project) {
  41. throw new schematics_1.SchematicsException(`Project name "${relatedAppName}" doesn't not exist.`);
  42. }
  43. const e2eRootPath = node_path_1.posix.join(project.root, 'e2e');
  44. project.targets.add({
  45. name: 'e2e',
  46. builder: utility_1.AngularBuilder.Protractor,
  47. defaultConfiguration: 'development',
  48. options: {
  49. protractorConfig: node_path_1.posix.join(e2eRootPath, 'protractor.conf.js'),
  50. },
  51. configurations: {
  52. production: {
  53. devServerTarget: `${relatedAppName}:serve:production`,
  54. },
  55. development: {
  56. devServerTarget: `${relatedAppName}:serve:development`,
  57. },
  58. },
  59. });
  60. return (0, schematics_1.chain)([
  61. (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)('./files'), [
  62. (0, schematics_1.applyTemplates)({
  63. utils: schematics_1.strings,
  64. ...options,
  65. relativePathToWorkspaceRoot: node_path_1.posix.relative(node_path_1.posix.join('/', e2eRootPath), '/'),
  66. }),
  67. (0, schematics_1.move)(e2eRootPath),
  68. ])),
  69. (0, utility_1.addRootProvider)(relatedAppName, ({ code, external }) => code `${external('provideProtractorTestingSupport', '@angular/platform-browser')}()`),
  70. ...E2E_DEV_DEPENDENCIES.map((name) => (0, utility_1.addDependency)(name, latest_versions_1.latestVersions[name], {
  71. type: utility_1.DependencyType.Dev,
  72. existing: utility_1.ExistingBehavior.Skip,
  73. })),
  74. addScriptsToPackageJson(),
  75. ]);
  76. });
  77. }