import { pathToIdent } from "@css-blocks/ember-utils" ; import type { FS as MergedFS } from "fs-merger" ; import { FileLocator } from "./FileLocator" ; export type FS = Pick < MergedFS , "existsSync" | "entries" > ; export class BroccoliFileLocator implements FileLocator { fs : FS ; constructor ( fs ) { this . fs = fs ; } findStylesheetForTemplate ( relativePathToTemplate , extensions ) { let possibleStylesheets = this . possibleStylesheetPathsForTemplate ( relativePathToTemplate , extensions ) ; return possibleStylesheets . find ( ( s ) => this . fs . existsSync ( s ) ) || null ; } blockIdentifier ( relativePathToStylesheet ) { return pathToIdent ( relativePathToStylesheet ) ; } possibleTemplatePaths ( ) { return this . fs . entries ( "." , { globs : [ "**/*.hbs" ] } ) . map ( e => e . relativePath ) ; } possibleStylesheetPathsForTemplate ( templatePath , extensions ) { let path = templatePath . replace ( "/templates/" , "/styles/" ) ; return extensions . map ( ext => path . replace ( /\.hbs$/ , `.block.${ ext }` ) ) ; } }