From 513c43f5649f2f426c50015e698b69f0c36a4cba Mon Sep 17 00:00:00 2001 From: Alican Erdurmaz Date: Fri, 31 May 2024 16:03:25 +0300 Subject: [PATCH] feat: add tailwind vite --- presets.js | 13 +++ refine-vite/plugins/_base/extend.js | 28 +++--- .../auth-provider-auth0/src/pages/login.tsx | 2 +- .../src/pages/forgotPassword/index.tsx | 2 +- .../src/pages/login/index.tsx | 2 +- .../src/pages/register/index.tsx | 2 +- .../auth-provider-google/src/pages/login.tsx | 2 +- .../src/pages/login.tsx | 2 +- refine-vite/plugins/tailwindcss/meta.json | 4 + refine-vite/plugins/tailwindcss/package.json | 7 ++ .../plugins/tailwindcss/postcss.config.js | 6 ++ refine-vite/plugins/tailwindcss/src/App.css | 92 +++++++++++++++++++ .../plugins/tailwindcss/tailwind.config.js | 8 ++ refine-vite/prompt.js | 13 ++- refine-vite/template/src/App.tsx | 4 +- 15 files changed, 162 insertions(+), 25 deletions(-) create mode 100644 refine-vite/plugins/tailwindcss/meta.json create mode 100644 refine-vite/plugins/tailwindcss/package.json create mode 100644 refine-vite/plugins/tailwindcss/postcss.config.js create mode 100644 refine-vite/plugins/tailwindcss/src/App.css create mode 100644 refine-vite/plugins/tailwindcss/tailwind.config.js diff --git a/presets.js b/presets.js index db7e097e..03d0d875 100644 --- a/presets.js +++ b/presets.js @@ -99,5 +99,18 @@ module.exports = { "headless-example": "no", }, }, + { + name: "refine-vite-tailwind", + type: "refine-vite", + answers: { + "ui-framework": "tailwindcss", + "router-provider": "react-router-v6", + "data-provider": "data-provider-custom-json-rest", + "auth-provider": "none", + "antd-example": "no", + "mui-example": "no", + "headless-example": "no", + }, + }, ], }; diff --git a/refine-vite/plugins/_base/extend.js b/refine-vite/plugins/_base/extend.js index ce734aba..801cd7bf 100644 --- a/refine-vite/plugins/_base/extend.js +++ b/refine-vite/plugins/_base/extend.js @@ -28,6 +28,8 @@ module.exports = { extend(answers) { const uiFramework = answers["ui-framework"]; const dataProvider = answers["data-provider"]; + const isHeadless = + uiFramework === "no" || uiFramework === "tailwindcss"; switch (uiFramework) { case "antd": @@ -102,7 +104,7 @@ module.exports = { ]; // update for headless - if (uiFramework === "no") { + if (isHeadless) { base._app.authPageProps = [ ` renderContent={(content) => ( @@ -160,16 +162,13 @@ module.exports = { base.selectedSvg = svgFromAnswers; } - if ( - answers["ui-framework"] !== "no" && - (answers["title"] || answers["svg"]) - ) { + if (!isHeadless && (answers["title"] || answers["svg"])) { base._app.localImport.push( 'import { AppIcon } from "./components/app-icon";', ); } - if (answers["ui-framework"] === "no") { + if (isHeadless) { base._app.localImport.push( `import { Layout } from "./components/layout";`, ); @@ -200,7 +199,7 @@ module.exports = { } else if (dataProvider === "data-provider-supabase") { base.blogPostCategoryIdFormField = `"categoryId"`; } else { - if (uiFramework === "mui" || uiFramework === "no") { + if (uiFramework === "mui" || isHeadless) { base.blogPostCategoryIdFormField = `"category.id"`; } else { base.blogPostCategoryIdFormField = `["category", "id"]`; @@ -209,7 +208,7 @@ module.exports = { // ## blogPostCategoryTableField if (base.isGraphQL) { - if (uiFramework === "no") { + if (isHeadless) { base.blogPostCategoryTableField = `"category.title"`; } if (uiFramework === "antd") { @@ -240,7 +239,7 @@ module.exports = { { value: "rejected", label: "Rejected" }, ]); } - if (uiFramework === "no" || uiFramework === "mui") { + if (isHeadless || uiFramework === "mui") { base.blogPostStatusOptions = JSON.parse(base.blogPostStatusOptions); } @@ -252,17 +251,16 @@ module.exports = { } // ## Refine options.title - if ( - answers["ui-framework"] !== "no" && - (answers["title"] || answers["svg"]) - ) { + if (!isHeadless && (answers["title"] || answers["svg"])) { if (!base._app.refineOptions) { base._app.refineOptions = []; } - const textLine = answers["title"] ? `text: "${answers["title"]}",` : ""; + const textLine = answers["title"] + ? `text: "${answers["title"]}",` + : ""; const iconLine = answers["svg"] ? `icon: ,` : ""; const template = `title: { ${textLine} ${iconLine} },`; - + base._app.refineOptions.push(template); } diff --git a/refine-vite/plugins/auth-provider-auth0/src/pages/login.tsx b/refine-vite/plugins/auth-provider-auth0/src/pages/login.tsx index 9c4661c1..feeb66fe 100644 --- a/refine-vite/plugins/auth-provider-auth0/src/pages/login.tsx +++ b/refine-vite/plugins/auth-provider-auth0/src/pages/login.tsx @@ -95,7 +95,7 @@ export const Login: React.FC = () => { ); <%_ } _%> - <%_ if (answers["ui-framework"] === "no") { _%> + <%_ if (answers["ui-framework"] === "no" || answers["ui-framework"] === "tailwindcss") { _%> return(
+<%_ if (answers[`ui-framework`] === "no" || answers[`ui-framework`] === "tailwindcss") { _%> import { AuthPage } from "@refinedev/core"; <%_ } _%> <%_ if (answers["ui-framework"] === 'antd') { _%> diff --git a/refine-vite/plugins/auth-provider-custom/src/pages/login/index.tsx b/refine-vite/plugins/auth-provider-custom/src/pages/login/index.tsx index 45df0e9a..fb51f7d7 100644 --- a/refine-vite/plugins/auth-provider-custom/src/pages/login/index.tsx +++ b/refine-vite/plugins/auth-provider-custom/src/pages/login/index.tsx @@ -1,4 +1,4 @@ -<%_ if (answers[`ui-framework`] === "no") { _%> +<%_ if (answers[`ui-framework`] === "no" || answers[`ui-framework`] === "tailwindcss") { _%> import { AuthPage } from "@refinedev/core"; <%_ } _%> <%_ if (answers["ui-framework"] === 'antd') { _%> diff --git a/refine-vite/plugins/auth-provider-custom/src/pages/register/index.tsx b/refine-vite/plugins/auth-provider-custom/src/pages/register/index.tsx index 427219d0..05d5dd87 100644 --- a/refine-vite/plugins/auth-provider-custom/src/pages/register/index.tsx +++ b/refine-vite/plugins/auth-provider-custom/src/pages/register/index.tsx @@ -1,4 +1,4 @@ -<%_ if (answers[`ui-framework`] === "no") { _%> +<%_ if (answers[`ui-framework`] === "no" || answers[`ui-framework`] === "tailwindcss") { _%> import { AuthPage } from "@refinedev/core"; <%_ } _%> <%_ if (answers["ui-framework"] === 'antd') { _%> diff --git a/refine-vite/plugins/auth-provider-google/src/pages/login.tsx b/refine-vite/plugins/auth-provider-google/src/pages/login.tsx index 4390edab..a84ba3e2 100644 --- a/refine-vite/plugins/auth-provider-google/src/pages/login.tsx +++ b/refine-vite/plugins/auth-provider-google/src/pages/login.tsx @@ -129,7 +129,7 @@ export const Login: React.FC = () => { ); <%_ } _%> - <%_ if (answers["ui-framework"] === "no") { _%> + <%_ if (answers["ui-framework"] === "no" || answers["ui-framework"] === "tailwindcss") { _%> return(
{ ); <%_ } _%> - <%_ if (answers["ui-framework"] === "no") { _%> + <%_ if (answers["ui-framework"] === "no" || answers["ui-framework"] === "tailwindcss") { _%> return(
} > - <%_ if (answers["ui-framework"] === 'no') { _%> + <%_ if (answers["ui-framework"] === 'no' || answers["ui-framework"] === 'tailwindcss') { _%> @@ -174,7 +174,7 @@ function App() { + <%_ if (answers["ui-framework"] === 'no' || answers["ui-framework"] === 'tailwindcss') { _%>