index.js 3.4 KB

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