(project: ProjectDefinition, extension?: string)
| 21 | * extension is specified, any style file with a valid extension will be returned. |
| 22 | */ |
| 23 | export function getProjectStyleFile(project: ProjectDefinition, extension?: string): string | null { |
| 24 | const buildOptions = getProjectTargetOptions(project, 'build'); |
| 25 | const buildStyles = buildOptions['styles']; |
| 26 | |
| 27 | if (buildStyles && isJsonArray(buildStyles) && buildStyles.length) { |
| 28 | const styles = buildStyles.map(s => (typeof s === 'string' ? s : (s as {input: string}).input)); |
| 29 | |
| 30 | // Look for the default style file that is generated for new projects by the Angular CLI. This |
| 31 | // default style file is usually called `styles.ext` unless it has been changed explicitly. |
| 32 | const defaultMainStylePath = styles.find(file => |
| 33 | extension ? file === `styles.${extension}` : defaultStyleFileRegex.test(file), |
| 34 | ); |
| 35 | |
| 36 | if (defaultMainStylePath) { |
| 37 | return normalize(defaultMainStylePath); |
| 38 | } |
| 39 | |
| 40 | // If no default style file could be found, use the first style file that matches the given |
| 41 | // extension. If no extension specified explicitly, we look for any file with a valid style |
| 42 | // file extension. |
| 43 | const fallbackStylePath = styles.find(file => |
| 44 | extension ? file.endsWith(`.${extension}`) : validStyleFileRegex.test(file), |
| 45 | ); |
| 46 | |
| 47 | if (fallbackStylePath) { |
| 48 | return normalize(fallbackStylePath); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | return null; |
| 53 | } |
no test coverage detected