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 workspace_1 = require("../../utility/workspace");
|
---|
12 | const workspace_models_1 = require("../../utility/workspace-models");
|
---|
13 | function default_1() {
|
---|
14 | return async (_host, context) => workspace_1.updateWorkspace((workspace) => {
|
---|
15 | for (const [name, target] of workspace_1.allWorkspaceTargets(workspace)) {
|
---|
16 | let defaultConfiguration;
|
---|
17 | // Only interested in 1st party builders
|
---|
18 | switch (target.builder) {
|
---|
19 | case workspace_models_1.Builders.AppShell:
|
---|
20 | case workspace_models_1.Builders.Browser:
|
---|
21 | case workspace_models_1.Builders.Server:
|
---|
22 | case workspace_models_1.Builders.NgPackagr:
|
---|
23 | defaultConfiguration = 'production';
|
---|
24 | break;
|
---|
25 | case workspace_models_1.Builders.DevServer:
|
---|
26 | case workspace_models_1.Builders.Protractor:
|
---|
27 | case '@nguniversal/builders:ssr-dev-server':
|
---|
28 | defaultConfiguration = 'development';
|
---|
29 | break;
|
---|
30 | case workspace_models_1.Builders.TsLint:
|
---|
31 | case workspace_models_1.Builders.ExtractI18n:
|
---|
32 | case workspace_models_1.Builders.Karma:
|
---|
33 | // Nothing to update
|
---|
34 | break;
|
---|
35 | default:
|
---|
36 | context.logger
|
---|
37 | .warn(core_1.tags.stripIndents `Cannot update "${name}" target configuration as it's using "${target.builder}"
|
---|
38 | which is a third-party builder. This target configuration will require manual review.`);
|
---|
39 | continue;
|
---|
40 | }
|
---|
41 | if (!defaultConfiguration) {
|
---|
42 | continue;
|
---|
43 | }
|
---|
44 | updateTarget(name, target, context.logger, defaultConfiguration);
|
---|
45 | }
|
---|
46 | });
|
---|
47 | }
|
---|
48 | exports.default = default_1;
|
---|
49 | function getArchitectTargetWithConfig(currentTarget, overrideConfig) {
|
---|
50 | const [project, target, config = 'development'] = currentTarget.split(':');
|
---|
51 | return `${project}:${target}:${overrideConfig || config}`;
|
---|
52 | }
|
---|
53 | function updateTarget(targetName, target, logger, defaultConfiguration) {
|
---|
54 | var _a, _b;
|
---|
55 | if (!target.configurations) {
|
---|
56 | target.configurations = {};
|
---|
57 | }
|
---|
58 | if ((_a = target.configurations) === null || _a === void 0 ? void 0 : _a.development) {
|
---|
59 | logger.info(core_1.tags.stripIndents `Skipping updating "${targetName}" target configuration as a "development" configuration is already defined.`);
|
---|
60 | return;
|
---|
61 | }
|
---|
62 | if (!((_b = target.configurations) === null || _b === void 0 ? void 0 : _b.production)) {
|
---|
63 | logger.info(core_1.tags.stripIndents `Skipping updating "${targetName}" target configuration as a "production" configuration is not defined.`);
|
---|
64 | return;
|
---|
65 | }
|
---|
66 | const developmentOptions = {};
|
---|
67 | let serverTarget = true;
|
---|
68 | let browserTarget = true;
|
---|
69 | let devServerTarget = true;
|
---|
70 | for (const [, options] of workspace_1.allTargetOptions(target)) {
|
---|
71 | if (typeof options.serverTarget === 'string') {
|
---|
72 | options.serverTarget = getArchitectTargetWithConfig(options.serverTarget);
|
---|
73 | if (!developmentOptions.serverTarget) {
|
---|
74 | developmentOptions.serverTarget = getArchitectTargetWithConfig(options.serverTarget, 'development');
|
---|
75 | }
|
---|
76 | }
|
---|
77 | else {
|
---|
78 | serverTarget = false;
|
---|
79 | }
|
---|
80 | if (typeof options.browserTarget === 'string') {
|
---|
81 | options.browserTarget = getArchitectTargetWithConfig(options.browserTarget);
|
---|
82 | if (!developmentOptions.browserTarget) {
|
---|
83 | developmentOptions.browserTarget = getArchitectTargetWithConfig(options.browserTarget, 'development');
|
---|
84 | }
|
---|
85 | }
|
---|
86 | else {
|
---|
87 | browserTarget = false;
|
---|
88 | }
|
---|
89 | if (typeof options.devServerTarget === 'string') {
|
---|
90 | options.devServerTarget = getArchitectTargetWithConfig(options.devServerTarget);
|
---|
91 | if (!developmentOptions.devServerTarget) {
|
---|
92 | developmentOptions.devServerTarget = getArchitectTargetWithConfig(options.devServerTarget, 'development');
|
---|
93 | }
|
---|
94 | }
|
---|
95 | else {
|
---|
96 | devServerTarget = false;
|
---|
97 | }
|
---|
98 | }
|
---|
99 | // If all configurastions have a target defined delete the one in options.
|
---|
100 | if (target.options) {
|
---|
101 | if (serverTarget) {
|
---|
102 | delete target.options.serverTarget;
|
---|
103 | }
|
---|
104 | if (browserTarget) {
|
---|
105 | delete target.options.browserTarget;
|
---|
106 | }
|
---|
107 | if (devServerTarget) {
|
---|
108 | delete target.options.devServerTarget;
|
---|
109 | }
|
---|
110 | }
|
---|
111 | target.defaultConfiguration = defaultConfiguration;
|
---|
112 | target.configurations.development = developmentOptions;
|
---|
113 | }
|
---|