"use strict"; /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ Object.defineProperty(exports, "__esModule", { value: true }); const schematics_1 = require("@angular-devkit/schematics"); const schematics_2 = require("@angular/cdk/schematics"); const components_1 = require("@schematics/angular/private/components"); const workspace_1 = require("@schematics/angular/utility/workspace"); const workspace_models_1 = require("@schematics/angular/utility/workspace-models"); const material_fonts_1 = require("./fonts/material-fonts"); const theming_1 = require("./theming/theming"); /** * Scaffolds the basics of a Angular Material application, this includes: * - Add Packages to package.json * - Adds pre-built themes to styles.ext * - Adds Browser Animation to app.module */ function default_1(options) { return async (host, context) => { const workspace = await (0, workspace_1.getWorkspace)(host); const project = (0, schematics_2.getProjectFromWorkspace)(workspace, options.project); if (project.extensions.projectType === workspace_models_1.ProjectType.Application) { return (0, schematics_1.chain)([ addAnimationsModule(options), (0, theming_1.addThemeToAppStyles)(options), (0, material_fonts_1.addFontsToIndex)(options), addMaterialAppStyles(options), (0, theming_1.addTypographyClass)(options), ]); } context.logger.warn('Angular Material has been set up in your workspace. There is no additional setup ' + 'required for consuming Angular Material in your library project.\n\n' + 'If you intended to run the schematic on a different project, pass the `--project` ' + 'option.'); return; }; } exports.default = default_1; /** * Adds an animation module to the root module of the specified project. In case the "animations" * option is set to false, we still add the `NoopAnimationsModule` because otherwise various * components of Angular Material will throw an exception. */ function addAnimationsModule(options) { return async (host, context) => { const workspace = await (0, workspace_1.getWorkspace)(host); const project = (0, schematics_2.getProjectFromWorkspace)(workspace, options.project); const mainFilePath = (0, schematics_2.getProjectMainFile)(project); if ((0, schematics_2.isStandaloneApp)(host, mainFilePath)) { addAnimationsToStandaloneApp(host, mainFilePath, context, options); } else { addAnimationsToNonStandaloneApp(host, project, mainFilePath, context, options); } }; } /** Adds the animations module to an app that is bootstrap using the standalone component APIs. */ function addAnimationsToStandaloneApp(host, mainFile, context, options) { const animationsFunction = 'provideAnimations'; const noopAnimationsFunction = 'provideNoopAnimations'; if (options.animations === 'enabled') { // In case the project explicitly uses provideNoopAnimations, we should print a warning // message that makes the user aware of the fact that we won't automatically set up // animations. If we would add provideAnimations while provideNoopAnimations // is already configured, we would cause unexpected behavior and runtime exceptions. if ((0, components_1.callsProvidersFunction)(host, mainFile, noopAnimationsFunction)) { context.logger.error(`Could not add "${animationsFunction}" ` + `because "${noopAnimationsFunction}" is already provided.`); context.logger.info(`Please manually set up browser animations.`); } else { (0, components_1.addFunctionalProvidersToStandaloneBootstrap)(host, mainFile, animationsFunction, '@angular/platform-browser/animations'); } } else if (options.animations === 'disabled' && !(0, components_1.importsProvidersFrom)(host, mainFile, animationsFunction)) { // Do not add the provideNoopAnimations if the project already explicitly uses // the provideAnimations. (0, components_1.addFunctionalProvidersToStandaloneBootstrap)(host, mainFile, noopAnimationsFunction, '@angular/platform-browser/animations'); } } /** * Adds the animations module to an app that is bootstrap * using the non-standalone component APIs. */ function addAnimationsToNonStandaloneApp(host, project, mainFile, context, options) { const browserAnimationsModuleName = 'BrowserAnimationsModule'; const noopAnimationsModuleName = 'NoopAnimationsModule'; const appModulePath = (0, schematics_2.getAppModulePath)(host, mainFile); if (options.animations === 'enabled') { // In case the project explicitly uses the NoopAnimationsModule, we should print a warning // message that makes the user aware of the fact that we won't automatically set up // animations. If we would add the BrowserAnimationsModule while the NoopAnimationsModule // is already configured, we would cause unexpected behavior and runtime exceptions. if ((0, schematics_2.hasNgModuleImport)(host, appModulePath, noopAnimationsModuleName)) { context.logger.error(`Could not set up "${browserAnimationsModuleName}" ` + `because "${noopAnimationsModuleName}" is already imported.`); context.logger.info(`Please manually set up browser animations.`); } else { (0, schematics_2.addModuleImportToRootModule)(host, browserAnimationsModuleName, '@angular/platform-browser/animations', project); } } else if (options.animations === 'disabled' && !(0, schematics_2.hasNgModuleImport)(host, appModulePath, browserAnimationsModuleName)) { // Do not add the NoopAnimationsModule module if the project already explicitly uses // the BrowserAnimationsModule. (0, schematics_2.addModuleImportToRootModule)(host, noopAnimationsModuleName, '@angular/platform-browser/animations', project); } } /** * Adds custom Material styles to the project style file. The custom CSS sets up the Roboto font * and reset the default browser body margin. */ function addMaterialAppStyles(options) { return async (host, context) => { const workspace = await (0, workspace_1.getWorkspace)(host); const project = (0, schematics_2.getProjectFromWorkspace)(workspace, options.project); const styleFilePath = (0, schematics_2.getProjectStyleFile)(project); const logger = context.logger; if (!styleFilePath) { logger.error(`Could not find the default style file for this project.`); logger.info(`Consider manually adding the Roboto font to your CSS.`); logger.info(`More information at https://fonts.google.com/specimen/Roboto`); return; } const buffer = host.read(styleFilePath); if (!buffer) { logger.error(`Could not read the default style file within the project ` + `(${styleFilePath})`); logger.info(`Please consider manually setting up the Roboto font.`); return; } const htmlContent = buffer.toString(); const insertion = '\n' + `html, body { height: 100%; }\n` + `body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; }\n`; if (htmlContent.includes(insertion)) { return; } const recorder = host.beginUpdate(styleFilePath); recorder.insertLeft(htmlContent.length, insertion); host.commitUpdate(recorder); }; } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2V0dXAtcHJvamVjdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3NyYy9tYXRlcmlhbC9zY2hlbWF0aWNzL25nLWFkZC9zZXR1cC1wcm9qZWN0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTs7Ozs7O0dBTUc7O0FBRUgsMkRBQStFO0FBQy9FLHdEQVFpQztBQUNqQyx1RUFJZ0Q7QUFDaEQscUVBQXNGO0FBQ3RGLG1GQUF5RTtBQUN6RSwyREFBdUQ7QUFFdkQsK0NBQTBFO0FBRTFFOzs7OztHQUtHO0FBQ0gsbUJBQXlCLE9BQWU7SUFDdEMsT0FBTyxLQUFLLEVBQUUsSUFBVSxFQUFFLE9BQXlCLEVBQUUsRUFBRTtRQUNyRCxNQUFNLFNBQVMs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