[6a3a178] | 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.io/license
|
---|
| 8 | */
|
---|
| 9 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 10 | const core_1 = require("@angular-devkit/core");
|
---|
| 11 | const schematics_1 = require("@angular-devkit/schematics");
|
---|
| 12 | const dependencies_1 = require("../utility/dependencies");
|
---|
| 13 | const json_file_1 = require("../utility/json-file");
|
---|
| 14 | const paths_1 = require("../utility/paths");
|
---|
| 15 | const workspace_1 = require("../utility/workspace");
|
---|
| 16 | const workspace_models_1 = require("../utility/workspace-models");
|
---|
| 17 | function addScriptsToPackageJson() {
|
---|
| 18 | return (host) => {
|
---|
| 19 | const pkgJson = new json_file_1.JSONFile(host, 'package.json');
|
---|
| 20 | const e2eScriptPath = ['scripts', 'e2e'];
|
---|
| 21 | if (!pkgJson.get(e2eScriptPath)) {
|
---|
| 22 | pkgJson.modify(e2eScriptPath, 'ng e2e', false);
|
---|
| 23 | }
|
---|
| 24 | };
|
---|
| 25 | }
|
---|
| 26 | function default_1(options) {
|
---|
| 27 | return async (host) => {
|
---|
| 28 | const appProject = options.relatedAppName;
|
---|
| 29 | const workspace = await workspace_1.getWorkspace(host);
|
---|
| 30 | const project = workspace.projects.get(appProject);
|
---|
| 31 | if (!project) {
|
---|
| 32 | throw new schematics_1.SchematicsException(`Project name "${appProject}" doesn't not exist.`);
|
---|
| 33 | }
|
---|
| 34 | const root = core_1.join(core_1.normalize(project.root), 'e2e');
|
---|
| 35 | project.targets.add({
|
---|
| 36 | name: 'e2e',
|
---|
| 37 | builder: workspace_models_1.Builders.Protractor,
|
---|
| 38 | defaultConfiguration: 'development',
|
---|
| 39 | options: {
|
---|
| 40 | protractorConfig: `${root}/protractor.conf.js`,
|
---|
| 41 | },
|
---|
| 42 | configurations: {
|
---|
| 43 | production: {
|
---|
| 44 | devServerTarget: `${options.relatedAppName}:serve:production`,
|
---|
| 45 | },
|
---|
| 46 | development: {
|
---|
| 47 | devServerTarget: `${options.relatedAppName}:serve:development`,
|
---|
| 48 | },
|
---|
| 49 | },
|
---|
| 50 | });
|
---|
| 51 | return schematics_1.chain([
|
---|
| 52 | workspace_1.updateWorkspace(workspace),
|
---|
| 53 | schematics_1.mergeWith(schematics_1.apply(schematics_1.url('./files'), [
|
---|
| 54 | schematics_1.applyTemplates({
|
---|
| 55 | utils: core_1.strings,
|
---|
| 56 | ...options,
|
---|
| 57 | relativePathToWorkspaceRoot: paths_1.relativePathToWorkspaceRoot(root),
|
---|
| 58 | }),
|
---|
| 59 | schematics_1.move(root),
|
---|
| 60 | ])),
|
---|
| 61 | (host) => [
|
---|
| 62 | {
|
---|
| 63 | type: dependencies_1.NodeDependencyType.Dev,
|
---|
| 64 | name: 'protractor',
|
---|
| 65 | version: '~7.0.0',
|
---|
| 66 | },
|
---|
| 67 | {
|
---|
| 68 | type: dependencies_1.NodeDependencyType.Dev,
|
---|
| 69 | name: 'jasmine-spec-reporter',
|
---|
| 70 | version: '~7.0.0',
|
---|
| 71 | },
|
---|
| 72 | {
|
---|
| 73 | type: dependencies_1.NodeDependencyType.Dev,
|
---|
| 74 | name: 'ts-node',
|
---|
| 75 | version: '~9.1.1',
|
---|
| 76 | },
|
---|
| 77 | ].forEach((dep) => dependencies_1.addPackageJsonDependency(host, dep)),
|
---|
| 78 | addScriptsToPackageJson(),
|
---|
| 79 | ]);
|
---|
| 80 | };
|
---|
| 81 | }
|
---|
| 82 | exports.default = default_1;
|
---|