UNPKG

flowbite-react

Version:

Official React components built for Flowbite and Tailwind CSS

72 lines (63 loc) 2.19 kB
'use strict'; var fs = require('fs/promises'); var recast = require('recast'); var consts = require('../consts.cjs'); var compareNodes = require('../utils/compare-nodes.cjs'); 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 ? consts.initFilePath : consts.initJsxFilePath; const oldPath = config.tsx ? consts.initJsxFilePath : consts.initFilePath; try { let currentContent = ""; try { currentContent = await fs.readFile(targetPath, "utf-8"); } catch { console.log(`Creating ${targetPath} file...`); setTimeout(() => fs.writeFile(targetPath, content), 10); } if (currentContent) { const currentAst = removeReactImport(recast.parse(currentContent)); const newAst = removeReactImport(recast.parse(content)); if (!compareNodes.compareNodes(currentAst.program, newAst.program)) { console.log(`Updating ${targetPath} file...`); setTimeout(() => fs.writeFile(targetPath, content), 10); } } try { await fs.access(oldPath); console.log(`Removing ${oldPath} file...`); await fs.unlink(oldPath); } catch { } } catch (error) { console.error(`Failed to update ${targetPath}:`, error); } } function removeReactImport(ast) { if (ast?.program?.body) { ast.program.body = ast.program.body.filter( (node) => !(node.type === "ImportDeclaration" && "value" in node.source && typeof node.source.value === "string" && node.source.value === "react" && node.specifiers?.[0]?.local?.name === "React") ); } return ast; } exports.setupInit = setupInit; //# sourceMappingURL=setup-init.cjs.map