UNPKG

flowbite-react

Version:

Official React components built for Flowbite and Tailwind CSS

55 lines (52 loc) 2 kB
import { configFilePath, initFilePath, initJsxFilePath } from '../consts.js'; import { createConfig } from './create-config.js'; function createInitLogger(config) { const defaultConfig = createConfig(); return { config, checkedMap: /* @__PURE__ */ new Map(), get isCustomConfig() { return this.config.dark !== defaultConfig.dark || this.config.prefix !== defaultConfig.prefix || this.config.version !== defaultConfig.version; }, get showWarning() { return this.checkedMap.values().find((value) => value) === void 0; }, /** * Checks if `<ThemeInit />` component is used in the given file content * * @param path - The path to the file being checked * @param content - The file content to search in */ check(path, content) { if (this.isCustomConfig) { this.checkedMap.set(path, hasThemeInit(content)); } }, /** * Logs a warning if `<ThemeInit />` component is not used in the project and the configuration `dark`, `prefix` or `version` differs from default values. */ log() { if (this.isCustomConfig && this.showWarning) { console.warn( ` [!] Custom values detected in ${configFilePath}, render '<ThemeInit />' from ${config.tsx ? initFilePath : initJsxFilePath} at root level of your app to sync runtime with node config values.`, ` [!] Otherwise, your app will use the default values instead of your custom configuration.`, ` [!] Example: In case of custom 'prefix' or 'version', the app will not display the correct class names.` ); } } }; } function hasThemeInit(content) { if (/(\/\/|<!--|{\/\*|\/\*|\*|#)\s*<ThemeInit/.test(content)) { return false; } if (/(?:< ThemeInit|<ThemeInit\/ |<<ThemeInit)/.test(content)) { return false; } return /<ThemeInit(?:\s+[^>/]*)?(?:\/>\s*|>\s*<\/ThemeInit>)/.test(content); } export { createInitLogger, hasThemeInit }; //# sourceMappingURL=create-init-logger.js.map