@angular/material
Version:
Angular Material
75 lines • 3.44 kB
JavaScript
/**
* @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.dev/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1;
const schematics_1 = require("@angular-devkit/schematics");
const schematics_2 = require("@angular/cdk/schematics");
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
*/
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)([
(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;
};
}
/**
* 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=setup-project.js.map
;