Skip to content
This repository was archived by the owner on May 5, 2024. It is now read-only.

Commit f3dfaa8

Browse files
committed
⚡️ feat: daisyUI option svelte-add/svelte-add#200
1 parent 518190f commit f3dfaa8

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ This adder supports SvelteKit and Vite-powered Svelte apps (all the environments
2020

2121
- `typography` (default `false`): whether or not to install and set up the [Tailwind CSS Typography plugin](https://github.com/tailwindlabs/tailwindcss-typography).
2222

23+
- `daisyui` (default `false`): whether or not to install and set up [daisyUI](https://github.com/saadeghi/daisyui) as a Tailwind plugin.
24+
2325
## 🛠 Using Tailwind CSS
2426

2527
After the adder runs,

__info.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const gatekeep = async () => {
1111
return { able: true };
1212
};
1313

14-
/** @typedef {{ forms: boolean, typography: boolean }} Options */
14+
/** @typedef {{ forms: boolean, typography: boolean, daisyui: boolean }} Options */
1515

1616
/** @type {import("../..").AdderOptions<Options>} */
1717
export const options = {
@@ -27,6 +27,12 @@ export const options = {
2727
descriptionMarkdown: "whether or not to install and set up the [Tailwind CSS Typography plugin](https://github.com/tailwindlabs/tailwindcss-typography).",
2828
question: "Do you want to use the Tailwind CSS Typography plugin?",
2929
},
30+
daisyui: {
31+
context: "It provides component classes for Tailwind CSS. https://daisyui.com/",
32+
default: false,
33+
descriptionMarkdown: "whether or not to install and set up [daisyUI](https://github.com/saadeghi/daisyui) as a Tailwind plugin.",
34+
question: "Do you want to use daisyUI?",
35+
},
3036
};
3137

3238
/** @type {import("../..").Heuristic[]} */

__run.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,10 @@ const updatePostcssConfig = (postcssConfigAst) => {
139139
* @param {import("../../ast-io.js").RecastAST} tailwindConfigAst
140140
* @param {boolean} forms
141141
* @param {boolean} typography
142+
* @param {boolean} daisyui
142143
* @returns {import("../../ast-io.js").RecastAST}
143144
*/
144-
const updateTailwindConfig = (tailwindConfigAst, forms, typography) => {
145+
const updateTailwindConfig = (tailwindConfigAst, forms, typography, daisyui) => {
145146
const configObject = setDefaultDefaultExport({
146147
cjs: true,
147148
defaultValue: {
@@ -228,6 +229,19 @@ const updateTailwindConfig = (tailwindConfigAst, forms, typography) => {
228229
});
229230
}
230231

232+
if (daisyui) {
233+
let daisyuiImportedAs = findImport({ cjs: true, package: "daisyui", typeScriptEstree: tailwindConfigAst }).require;
234+
// Add a daisyUI plugin import if it's not there
235+
if (!daisyuiImportedAs) {
236+
daisyuiImportedAs = "daisyui";
237+
addImport({ require: daisyuiImportedAs, cjs: true, package: "daisyui", typeScriptEstree: tailwindConfigAst });
238+
}
239+
pluginsList.elements.push({
240+
type: "Identifier",
241+
name: daisyuiImportedAs,
242+
});
243+
}
244+
231245
return tailwindConfigAst;
232246
};
233247

@@ -278,7 +292,7 @@ export const run = async ({ install, options, updateCss, updateJavaScript }) =>
278292
path: tailwindConfigCjsPath,
279293
async script({ typeScriptEstree }) {
280294
return {
281-
typeScriptEstree: updateTailwindConfig(typeScriptEstree, options.forms, options.typography),
295+
typeScriptEstree: updateTailwindConfig(typeScriptEstree, options.forms, options.typography, options.daisyui),
282296
};
283297
},
284298
});
@@ -304,4 +318,5 @@ export const run = async ({ install, options, updateCss, updateJavaScript }) =>
304318
await install({ package: "tailwindcss" });
305319
if (options.forms) await install({ package: "@tailwindcss/forms" });
306320
if (options.typography) await install({ package: "@tailwindcss/typography" });
321+
if (options.daisyui) await install({ package: "daisyui" });
307322
};

0 commit comments

Comments
 (0)