source: trip-planner-front/node_modules/@angular/material/schematics/ng-add/theming/theming.mjs@ e29cc2e

Last change on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 25.7 KB
Line 
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 */
9var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
10 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
11 return new (P || (P = Promise))(function (resolve, reject) {
12 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
13 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
14 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
15 step((generator = generator.apply(thisArg, _arguments || [])).next());
16 });
17};
18Object.defineProperty(exports, "__esModule", { value: true });
19exports.addTypographyClass = exports.addThemeToAppStyles = void 0;
20const core_1 = require("@angular-devkit/core");
21const schematics_1 = require("@angular-devkit/schematics");
22const schematics_2 = require("@angular/cdk/schematics");
23const change_1 = require("@schematics/angular/utility/change");
24const workspace_1 = require("@schematics/angular/utility/workspace");
25const path_1 = require("path");
26const create_custom_theme_1 = require("./create-custom-theme");
27/** Path segment that can be found in paths that refer to a prebuilt theme. */
28const prebuiltThemePathSegment = '@angular/material/prebuilt-themes';
29/** Default file name of the custom theme that can be generated. */
30const defaultCustomThemeFilename = 'custom-theme.scss';
31/** Add pre-built styles to the main project style file. */
32function addThemeToAppStyles(options) {
33 return (host, context) => {
34 const themeName = options.theme || 'indigo-pink';
35 return themeName === 'custom' ?
36 insertCustomTheme(options.project, host, context.logger) :
37 insertPrebuiltTheme(options.project, themeName, context.logger);
38 };
39}
40exports.addThemeToAppStyles = addThemeToAppStyles;
41/** Adds the global typography class to the body element. */
42function addTypographyClass(options) {
43 return (host) => __awaiter(this, void 0, void 0, function* () {
44 const workspace = yield workspace_1.getWorkspace(host);
45 const project = schematics_2.getProjectFromWorkspace(workspace, options.project);
46 const projectIndexFiles = schematics_2.getProjectIndexFiles(project);
47 if (!projectIndexFiles.length) {
48 throw new schematics_1.SchematicsException('No project index HTML file could be found.');
49 }
50 if (options.typography) {
51 projectIndexFiles.forEach(path => schematics_2.addBodyClass(host, path, 'mat-typography'));
52 }
53 });
54}
55exports.addTypographyClass = addTypographyClass;
56/**
57 * Insert a custom theme to project style file. If no valid style file could be found, a new
58 * Scss file for the custom theme will be created.
59 */
60function insertCustomTheme(projectName, host, logger) {
61 return __awaiter(this, void 0, void 0, function* () {
62 const workspace = yield workspace_1.getWorkspace(host);
63 const project = schematics_2.getProjectFromWorkspace(workspace, projectName);
64 const stylesPath = schematics_2.getProjectStyleFile(project, 'scss');
65 const themeContent = create_custom_theme_1.createCustomTheme(projectName);
66 if (!stylesPath) {
67 if (!project.sourceRoot) {
68 throw new schematics_1.SchematicsException(`Could not find source root for project: "${projectName}". ` +
69 `Please make sure that the "sourceRoot" property is set in the workspace config.`);
70 }
71 // Normalize the path through the devkit utilities because we want to avoid having
72 // unnecessary path segments and windows backslash delimiters.
73 const customThemePath = core_1.normalize(path_1.join(project.sourceRoot, defaultCustomThemeFilename));
74 if (host.exists(customThemePath)) {
75 logger.warn(`Cannot create a custom Angular Material theme because
76 ${customThemePath} already exists. Skipping custom theme generation.`);
77 return schematics_1.noop();
78 }
79 host.create(customThemePath, themeContent);
80 return addThemeStyleToTarget(projectName, 'build', customThemePath, logger);
81 }
82 const insertion = new change_1.InsertChange(stylesPath, 0, themeContent);
83 const recorder = host.beginUpdate(stylesPath);
84 recorder.insertLeft(insertion.pos, insertion.toAdd);
85 host.commitUpdate(recorder);
86 return schematics_1.noop();
87 });
88}
89/** Insert a pre-built theme into the angular.json file. */
90function insertPrebuiltTheme(project, theme, logger) {
91 // Path needs to be always relative to the `package.json` or workspace root.
92 const themePath = `./node_modules/@angular/material/prebuilt-themes/${theme}.css`;
93 return schematics_1.chain([
94 addThemeStyleToTarget(project, 'build', themePath, logger),
95 addThemeStyleToTarget(project, 'test', themePath, logger)
96 ]);
97}
98/** Adds a theming style entry to the given project target options. */
99function addThemeStyleToTarget(projectName, targetName, assetPath, logger) {
100 return workspace_1.updateWorkspace(workspace => {
101 const project = schematics_2.getProjectFromWorkspace(workspace, projectName);
102 // Do not update the builder options in case the target does not use the default CLI builder.
103 if (!validateDefaultTargetBuilder(project, targetName, logger)) {
104 return;
105 }
106 const targetOptions = schematics_2.getProjectTargetOptions(project, targetName);
107 const styles = targetOptions.styles;
108 if (!styles) {
109 targetOptions.styles = [assetPath];
110 }
111 else {
112 const existingStyles = styles.map(s => typeof s === 'string' ? s : s.input);
113 for (let [index, stylePath] of existingStyles.entries()) {
114 // If the given asset is already specified in the styles, we don't need to do anything.
115 if (stylePath === assetPath) {
116 return;
117 }
118 // In case a prebuilt theme is already set up, we can safely replace the theme with the new
119 // theme file. If a custom theme is set up, we are not able to safely replace the custom
120 // theme because these files can contain custom styles, while prebuilt themes are
121 // always packaged and considered replaceable.
122 if (stylePath.includes(defaultCustomThemeFilename)) {
123 logger.error(`Could not add the selected theme to the CLI project ` +
124 `configuration because there is already a custom theme file referenced.`);
125 logger.info(`Please manually add the following style file to your configuration:`);
126 logger.info(` ${assetPath}`);
127 return;
128 }
129 else if (stylePath.includes(prebuiltThemePathSegment)) {
130 styles.splice(index, 1);
131 }
132 }
133 styles.unshift(assetPath);
134 }
135 });
136}
137/**
138 * Validates that the specified project target is configured with the default builders which are
139 * provided by the Angular CLI. If the configured builder does not match the default builder,
140 * this function can either throw or just show a warning.
141 */
142function validateDefaultTargetBuilder(project, targetName, logger) {
143 const defaultBuilder = schematics_2.defaultTargetBuilders[targetName];
144 const targetConfig = project.targets && project.targets.get(targetName);
145 const isDefaultBuilder = targetConfig && targetConfig['builder'] === defaultBuilder;
146 // Because the build setup for the Angular CLI can be customized by developers, we can't know
147 // where to put the theme file in the workspace configuration if custom builders are being
148 // used. In case the builder has been changed for the "build" target, we throw an error and
149 // exit because setting up a theme is a primary goal of `ng-add`. Otherwise if just the "test"
150 // builder has been changed, we warn because a theme is not mandatory for running tests
151 // with Material. See: https://github.com/angular/components/issues/14176
152 if (!isDefaultBuilder && targetName === 'build') {
153 throw new schematics_1.SchematicsException(`Your project is not using the default builders for ` +
154 `"${targetName}". The Angular Material schematics cannot add a theme to the workspace ` +
155 `configuration if the builder has been changed.`);
156 }
157 else if (!isDefaultBuilder) {
158 // for non-build targets we gracefully report the error without actually aborting the
159 // setup schematic. This is because a theme is not mandatory for running tests.
160 logger.warn(`Your project is not using the default builders for "${targetName}". This ` +
161 `means that we cannot add the configured theme to the "${targetName}" target.`);
162 }
163 return isDefaultBuilder;
164}
165//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGhlbWluZy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uLy4uL3NyYy9tYXRlcmlhbC9zY2hlbWF0aWNzL25nLWFkZC90aGVtaW5nL3RoZW1pbmcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBOzs7Ozs7R0FNRzs7Ozs7Ozs7Ozs7O0FBRUgsK0NBQXdEO0FBRXhELDJEQU9vQztBQUNwQyx3REFPaUM7QUFDakMsK0RBQWdFO0FBQ2hFLHFFQUFvRjtBQUNwRiwrQkFBMEI7QUFFMUIsK0RBQXdEO0FBRXhELDhFQUE4RTtBQUM5RSxNQUFNLHdCQUF3QixHQUFHLG1DQUFtQyxDQUFDO0FBRXJFLG1FQUFtRTtBQUNuRSxNQUFNLDBCQUEwQixHQUFHLG1CQUFtQixDQUFDO0FBRXZELDJEQUEyRDtBQUMzRCxTQUFnQixtQkFBbUIsQ0FBQyxPQUFlO0lBQ2pELE9BQU8sQ0FBQyxJQUFVLEVBQUUsT0FBeUIsRUFBRSxFQUFFO1FBQy9DLE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