UNPKG

flowbite-react

Version:

Official React components built for Flowbite and Tailwind CSS

63 lines (55 loc) 1.96 kB
import fs__default from 'fs/promises'; import { parseSync } from 'oxc-parser'; import { initFilePath, initJsxFilePath } from '../consts.js'; import { compareNodes } from '../utils/compare-nodes.js'; import { removeReactImport } from '../utils/remove-react-import.js'; async function setupInit(config) { const content = ` /* eslint-disable */ // @ts-nocheck // biome-ignore-all lint: auto-generated file // This file is auto-generated by the flowbite-react CLI. // Do not edit this file directly. // Instead, edit the .flowbite-react/config.json file. import { StoreInit } from "flowbite-react/store/init"; import React from "react"; export const CONFIG = { dark: ${config.dark}, prefix: "${config.prefix}", version: ${config.version}, }; export function ThemeInit() { return <StoreInit {...CONFIG} />; } ThemeInit.displayName = "ThemeInit"; `.trim(); const targetPath = config.tsx ? initFilePath : initJsxFilePath; const oldPath = config.tsx ? initJsxFilePath : initFilePath; try { let currentContent = ""; try { currentContent = await fs__default.readFile(targetPath, "utf-8"); } catch { console.log(`Creating ${targetPath} file...`); setTimeout(() => fs__default.writeFile(targetPath, content), 10); } if (currentContent) { const currentAst = removeReactImport(parseSync("init.tsx", currentContent)); const newAst = removeReactImport(parseSync("init.tsx", content)); if (!compareNodes(currentAst.program, newAst.program)) { console.log(`Updating ${targetPath} file...`); setTimeout(() => fs__default.writeFile(targetPath, content), 10); } } try { await fs__default.access(oldPath); console.log(`Removing ${oldPath} file...`); await fs__default.unlink(oldPath); } catch { } } catch (error) { console.error(`Failed to update ${targetPath}:`, error); } } export { setupInit }; //# sourceMappingURL=setup-init.js.map