"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 = (0, project_targets_1.getProjectTargetOptions)(project, 'build'); if (buildOptions.styles && (0, 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 (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; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJvamVjdC1zdHlsZS1maWxlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vc3JjL2Nkay9zY2hlbWF0aWNzL3V0aWxzL3Byb2plY3Qtc3R5bGUtZmlsZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Ozs7OztHQU1HOzs7QUFFSCwrQ0FBd0U7QUF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