diff --git a/src/bin/shared/getImplementedThemeTypes.ts b/src/bin/shared/getImplementedThemeTypes.ts index 14af6de1..0a8955ab 100644 --- a/src/bin/shared/getImplementedThemeTypes.ts +++ b/src/bin/shared/getImplementedThemeTypes.ts @@ -4,9 +4,22 @@ import * as fs from "fs"; import { type ThemeType } from "./constants"; import { getThemeSrcDirPath } from "./getThemeSrcDirPath"; +type ImplementedThemeTypes = Readonly>; + +let cache: + | { projectDirPath: string; implementedThemeTypes: ImplementedThemeTypes } + | undefined; + export function getImplementedThemeTypes(params: { projectDirPath: string }) { const { projectDirPath } = params; + if (cache !== undefined && cache.projectDirPath === projectDirPath) { + const { implementedThemeTypes } = cache; + return { implementedThemeTypes }; + } + + cache = undefined; + const { themeSrcDirPath } = getThemeSrcDirPath({ projectDirPath }); @@ -19,5 +32,7 @@ export function getImplementedThemeTypes(params: { projectDirPath: string }) { ]) ); + cache = { projectDirPath, implementedThemeTypes }; + return { implementedThemeTypes }; }