Skip to content

Commit

Permalink
feat: Adds TS support for tailwind config (#973)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianGonz97 authored Mar 29, 2024
1 parent c5afe89 commit 231f674
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/plenty-dogs-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"shadcn-svelte": minor
---

feat: Added TypeScript support for the tailwind config
8 changes: 3 additions & 5 deletions packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,9 @@ export async function runInit(cwd: string, config: Config) {
}

// Write tailwind config.
await fs.writeFile(
config.resolvedPaths.tailwindConfig,
templates.TAILWIND_CONFIG_WITH_VARIABLES,
"utf8"
);
const { TS, JS } = templates.TAILWIND_CONFIG_WITH_VARIABLES;
const tailwindConfigContent = config.resolvedPaths.tailwindConfig.endsWith(".ts") ? TS : JS;
await fs.writeFile(config.resolvedPaths.tailwindConfig, tailwindConfigContent, "utf8");

// Write css file.
const baseColor = await getRegistryBaseColor(config.tailwind.baseColor);
Expand Down
16 changes: 14 additions & 2 deletions packages/cli/src/utils/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,17 @@ export const flyAndScale = (
};
};`;

export const TAILWIND_CONFIG_WITH_VARIABLES = `import { fontFamily } from "tailwindcss/defaultTheme";
const TAILWIND_JS = `import { fontFamily } from "tailwindcss/defaultTheme";
/** @type {import('tailwindcss').Config} */
const config = {
const config = {`;

const TAILWIND_TS = `import { fontFamily } from "tailwindcss/defaultTheme";
import type { Config } from "tailwindcss";
const config: Config = {`;

const TAILWIND_WITH_VARIABLES = `
darkMode: ["class"],
content: ["./src/**/*.{html,js,svelte,ts}"],
safelist: ["dark"],
Expand Down Expand Up @@ -176,6 +183,11 @@ const config = {
export default config;
`;

export const TAILWIND_CONFIG_WITH_VARIABLES = {
TS: TAILWIND_TS + TAILWIND_WITH_VARIABLES,
JS: TAILWIND_JS + TAILWIND_WITH_VARIABLES,
};

export const TAILWIND_CONFIG = `import { fontFamily } from "tailwindcss/defaultTheme";
/** @type {import('tailwindcss').Config} */
Expand Down

0 comments on commit 231f674

Please sign in to comment.