flowbite-react
Version:
Official React components built for Flowbite and Tailwind CSS
1 lines • 4.3 kB
Source Map (JSON)
{"version":3,"file":"create-init-logger.cjs","sources":["../../../src/cli/utils/create-init-logger.ts"],"sourcesContent":["import { configFilePath, initFilePath, initJsxFilePath } from \"../consts\";\nimport { createConfig, type Config } from \"./create-config\";\n\n/**\n * Creates a logger to track and warn about `<ThemeInit />` component usage.\n *\n * @param {Config} config - The configuration object used to check\n */\nexport function createInitLogger(config: Config) {\n const defaultConfig = createConfig();\n\n return {\n config,\n checkedMap: new Map<string, boolean>(),\n get isCustomConfig() {\n return (\n this.config.dark !== defaultConfig.dark ||\n this.config.prefix !== defaultConfig.prefix ||\n this.config.version !== defaultConfig.version\n );\n },\n get showWarning() {\n return this.checkedMap.values().find((value) => value) === undefined;\n },\n /**\n * Checks if `<ThemeInit />` component is used in the given file content\n *\n * @param path - The path to the file being checked\n * @param content - The file content to search in\n */\n check(path: string, content: string) {\n if (this.isCustomConfig) {\n this.checkedMap.set(path, hasThemeInit(content));\n }\n },\n /**\n * Logs a warning if `<ThemeInit />` component is not used in the project and the configuration `dark`, `prefix` or `version` differs from default values.\n */\n log() {\n if (this.isCustomConfig && this.showWarning) {\n console.warn(\n `\\n[!] 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.`,\n `\\n[!] Otherwise, your app will use the default values instead of your custom configuration.`,\n `\\n[!] Example: In case of custom 'prefix' or 'version', the app will not display the correct class names.`,\n );\n }\n },\n };\n}\n\n/**\n * Checks if `<ThemeInit />` component is used in the given file content\n *\n * @param content - The file content to search in\n * @returns boolean indicating if ThemeInit is used\n */\nexport function hasThemeInit(content: string): boolean {\n // First check for commented out ThemeInit\n if (/(\\/\\/|<!--|{\\/\\*|\\/\\*|\\*|#)\\s*<ThemeInit/.test(content)) {\n return false;\n }\n\n // Check for malformed tags (space after < or before /, or multiple <)\n if (/(?:< ThemeInit|<ThemeInit\\/ |<<ThemeInit)/.test(content)) {\n return false;\n }\n\n // Check for valid ThemeInit tags with optional attributes\n // This regex matches:\n // 1. Opening < followed immediately by ThemeInit\n // 2. Optional attributes (anything that's not > or />)\n // 3. Self-closing /> or opening/closing tag pair with only whitespace between\n return /<ThemeInit(?:\\s+[^>/]*)?(?:\\/>\\s*|>\\s*<\\/ThemeInit>)/.test(content);\n}\n"],"names":["createConfig","configFilePath","initFilePath","initJsxFilePath"],"mappings":";;;;;AAGO,SAAS,gBAAgB,CAAC,MAAM,EAAE;AACzC,EAAE,MAAM,aAAa,GAAGA,yBAAY,EAAE;AACtC,EAAE,OAAO;AACT,IAAI,MAAM;AACV,IAAI,UAAU,kBAAkB,IAAI,GAAG,EAAE;AACzC,IAAI,IAAI,cAAc,GAAG;AACzB,MAAM,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,aAAa,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,aAAa,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,KAAK,aAAa,CAAC,OAAO;AACpJ,KAAK;AACL,IAAI,IAAI,WAAW,GAAG;AACtB,MAAM,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,KAAK,MAAM;AACvE,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE;AACzB,MAAM,IAAI,IAAI,CAAC,cAAc,EAAE;AAC/B,QAAQ,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;AACxD;AACA,KAAK;AACL;AACA;AACA;AACA,IAAI,GAAG,GAAG;AACV,MAAM,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,WAAW,EAAE;AACnD,QAAQ,OAAO,CAAC,IAAI;AACpB,UAAU;AACV,8BAA8B,EAAEC,qB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