"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.getProjectStyleFile = void 0; const core_1 = require("@angular-devkit/core"); const project_targets_1 = require("./project-targets"); /** Regular expression that matches all possible Angular CLI default style files. */ const defaultStyleFileRegex = /styles\.(c|le|sc)ss/; /** Regular expression that matches all files that have a proper stylesheet extension. */ const validStyleFileRegex = /\.(c|le|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) { const buildOptions = project_targets_1.getProjectTargetOptions(project, 'build'); if (buildOptions.styles && core_1.isJsonArray(buildOptions.styles) && buildOptions.styles.length) { const styles = buildOptions.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 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 core_1.normalize(fallbackStylePath); } } return null; } exports.getProjectStyleFile = getProjectStyleFile; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJvamVjdC1zdHlsZS1maWxlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vc3JjL2Nkay9zY2hlbWF0aWNzL3V0aWxzL3Byb2plY3Qtc3R5bGUtZmlsZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Ozs7OztHQU1HOzs7QUFFSCwrQ0FBNEQ7QUFFNUQsdURBQTBEO0F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