UNPKG

flowbite-react

Version:

Official React components built for Flowbite and Tailwind CSS

58 lines (54 loc) 2.06 kB
'use strict'; var consts = require('../consts.cjs'); var createConfig = require('./create-config.cjs'); function createInitLogger(config) { const defaultConfig = createConfig.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 ${consts.configFilePath}, render '<ThemeInit />' from ${config.tsx ? consts.initFilePath : consts.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); } exports.createInitLogger = createInitLogger; exports.hasThemeInit = hasThemeInit; //# sourceMappingURL=create-init-logger.cjs.map