UNPKG

@syncfusion/ej2-angular-base

Version:

A common package of Essential JS 2 base Angular libraries, methods and class definitions

66 lines (65 loc) 3.73 kB
"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 }); exports.assertDefaultBuildersConfigured = exports.getProjectStyleFile = void 0; const core_1 = require("@angular-devkit/core"); const schematics_1 = require("@angular-devkit/schematics"); /** Regular expression that matches all possible Angular CLI default style files. */ const defaultStyleFileRegex = /styles\.(c|le|sa|sc)ss/; /** Regular expression that matches all files that have a proper stylesheet extension. */ const validStyleFileRegex = /\.(c|le|sa|sc)ss/; /** * Gets a style file with the given extension in a project and returns its path. If no * extension is specified, any style file with a valid extension will be returned. */ function getProjectStyleFile(project, extension) { var _a, _b; const buildTarget = ((_a = project.architect) === null || _a === void 0 ? void 0 : _a['build']) || ((_b = project.targets) === null || _b === void 0 ? void 0 : _b['build']); if (buildTarget.options && buildTarget.options.styles && buildTarget.options.styles.length) { const styles = buildTarget.options.styles.map(s => typeof s === 'string' ? s : s.input); // Look for the default style file that is generated for new projects by the Angular CLI. This // default style file is usually called `styles.ext` unless it has been changed explicitly. const defaultMainStylePath = styles .find(file => extension ? file === `styles.${extension}` : defaultStyleFileRegex.test(file)); if (defaultMainStylePath) { return (0, core_1.normalize)(defaultMainStylePath); } // If no default style file could be found, use the first style file that matches the given // extension. If no extension specified explicitly, we look for any file with a valid style // file extension. const fallbackStylePath = styles .find(file => extension ? file.endsWith(`.${extension}`) : validStyleFileRegex.test(file)); if (fallbackStylePath) { return (0, core_1.normalize)(fallbackStylePath); } } return null; } exports.getProjectStyleFile = getProjectStyleFile; /** Throws if the project is not using the default Angular devkit builders. */ function assertDefaultBuildersConfigured(project) { const defaultBuilder = '@angular-devkit/build-angular:browser'; const defaultApplicationBuilder = '@angular-devkit/build-angular:application'; const modernApplicationBuilder = '@angular/build:application'; const defaultTestBuilder = '@angular-devkit/build-angular:karma'; const modernTestBuilder = '@angular/build:unit-test'; const hasDefaultBuilders = project.architect && project.architect['build'] && (project.architect['build']['builder'] === defaultBuilder || project.architect['build']['builder'] === defaultApplicationBuilder || project.architect['build']['builder'] === modernApplicationBuilder) && project.architect['test'] && (project.architect['test']['builder'] === defaultTestBuilder || project.architect['test']['builder'] === modernTestBuilder); if (!hasDefaultBuilders) { throw new schematics_1.SchematicsException('Your project is not using the default builders for build and test. The Angular Material ' + 'schematics can only be used if the original builders from the Angular CLI are configured.'); } } exports.assertDefaultBuildersConfigured = assertDefaultBuildersConfigured;