diff --git a/package.json b/package.json index c00b9916..5070c5a0 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "build:cli": "pnpm --filter shadcn-vue build", "build:registry": "pnpm --filter=www build:registry", "pub:beta": "cd packages/cli && pnpm pub:beta", - "pub:release": "cd packages/cli && pnpm pub:release" + "pub:release": "cd packages/cli && pnpm pub:release", + "test": "pnpm --filter shadcn-vue test" }, "devDependencies": { "@antfu/eslint-config": "^0.39.7", diff --git a/packages/cli/package.json b/packages/cli/package.json index e07bcdf9..18fb0aed 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -75,6 +75,7 @@ "rimraf": "^5.0.1", "tsup": "^7.2.0", "type-fest": "^4.3.0", - "typescript": "^5.2.2" + "typescript": "^5.2.2", + "vite-tsconfig-paths": "^4.2.0" } } diff --git a/packages/cli/src/commands/init.ts b/packages/cli/src/commands/init.ts index 693d4445..c8a96f1d 100644 --- a/packages/cli/src/commands/init.ts +++ b/packages/cli/src/commands/init.ts @@ -8,15 +8,15 @@ import template from 'lodash.template' import ora from 'ora' import prompts from 'prompts' import * as z from 'zod' -import * as templates from '@/src/utils/templates' +import * as templates from '../utils/templates' import { getRegistryBaseColor, getRegistryBaseColors, getRegistryStyles, -} from '@/src/utils/registry' -import { logger } from '@/src/utils/logger' -import { handleError } from '@/src/utils/handle-error' -import { getPackageManager } from '@/src/utils/get-package-manager' +} from '../utils/registry' +import { logger } from '../utils/logger' +import { handleError } from '../utils/handle-error' +import { getPackageManager } from '../utils/get-package-manager' import { type Config, DEFAULT_COMPONENTS, @@ -27,7 +27,7 @@ import { getConfig, rawConfigSchema, resolveConfigPaths, -} from '@/src/utils/get-config' +} from '../utils/get-config' const PROJECT_DEPENDENCIES = { base: [ diff --git a/packages/cli/test/commands/init.test.ts b/packages/cli/test/commands/init.test.ts new file mode 100644 index 00000000..b597ed13 --- /dev/null +++ b/packages/cli/test/commands/init.test.ts @@ -0,0 +1,160 @@ +import fs from 'node:fs' +import path from 'node:path' +import { execa } from 'execa' +import { afterEach, expect, test, vi } from 'vitest' + +import { runInit } from '../../src/commands/init' +import { getConfig } from '../../src/utils/get-config' +import * as getPackageManger from '../../src/utils/get-package-manager' +import * as registry from '../../src/utils/registry' + +vi.mock('execa') +vi.mock('fs/promises', () => ({ + writeFile: vi.fn(), + mkdir: vi.fn(), +})) +vi.mock('ora') + +test('init config-full', async () => { + vi.spyOn(getPackageManger, 'getPackageManager').mockResolvedValue('pnpm') + vi.spyOn(registry, 'getRegistryBaseColor').mockResolvedValue({ + inlineColors: {}, + cssVars: {}, + inlineColorsTemplate: + '@tailwind base;\n@tailwind components;\n@tailwind utilities;\n', + cssVarsTemplate: + '@tailwind base;\n@tailwind components;\n@tailwind utilities;\n', + }) + const mockMkdir = vi.spyOn(fs.promises, 'mkdir').mockResolvedValue(undefined) + const mockWriteFile = vi.spyOn(fs.promises, 'writeFile').mockResolvedValue() + + const targetDir = path.resolve(__dirname, '../fixtures/config-full') + const config = await getConfig(targetDir) + + await runInit(targetDir, config!) + + expect(mockMkdir).toHaveBeenNthCalledWith( + 1, + expect.stringMatching(/src\/app$/), + expect.anything(), + ) + expect(mockMkdir).toHaveBeenNthCalledWith( + 2, + expect.stringMatching(/src\/lib$/), + expect.anything(), + ) + expect(mockMkdir).toHaveBeenNthCalledWith( + 3, + expect.stringMatching(/src\/components$/), + expect.anything(), + ) + expect(mockWriteFile).toHaveBeenNthCalledWith( + 1, + expect.stringMatching(/tailwind.config.ts$/), + expect.stringContaining('/** @type {import(\'tailwindcss\').Config} */'), + 'utf8', + ) + expect(mockWriteFile).toHaveBeenNthCalledWith( + 2, + expect.stringMatching(/src\/app\/globals.css$/), + expect.stringContaining('@tailwind base'), + 'utf8', + ) + expect(mockWriteFile).toHaveBeenNthCalledWith( + 3, + expect.stringMatching(/src\/lib\/utils.ts$/), + expect.stringContaining('import { type ClassValue, clsx } from "clsx"'), + 'utf8', + ) + expect(execa).toHaveBeenCalledWith( + 'pnpm', + [ + 'add', + 'tailwindcss-animate', + 'class-variance-authority', + 'clsx', + 'tailwind-merge', + '@radix-ui/react-icons', + ], + { + cwd: targetDir, + }, + ) + + mockMkdir.mockRestore() + mockWriteFile.mockRestore() +}) + +test('init config-partial', async () => { + vi.spyOn(getPackageManger, 'getPackageManager').mockResolvedValue('npm') + vi.spyOn(registry, 'getRegistryBaseColor').mockResolvedValue({ + inlineColors: {}, + cssVars: {}, + inlineColorsTemplate: + '@tailwind base;\n@tailwind components;\n@tailwind utilities;\n', + cssVarsTemplate: + '@tailwind base;\n@tailwind components;\n@tailwind utilities;\n', + }) + const mockMkdir = vi.spyOn(fs.promises, 'mkdir').mockResolvedValue(undefined) + const mockWriteFile = vi.spyOn(fs.promises, 'writeFile').mockResolvedValue() + + const targetDir = path.resolve(__dirname, '../fixtures/config-partial') + const config = await getConfig(targetDir) + + await runInit(targetDir, config!) + + expect(mockMkdir).toHaveBeenNthCalledWith( + 1, + expect.stringMatching(/src\/assets\/css$/), + expect.anything(), + ) + expect(mockMkdir).toHaveBeenNthCalledWith( + 2, + expect.stringMatching(/lib$/), + expect.anything(), + ) + expect(mockMkdir).toHaveBeenNthCalledWith( + 3, + expect.stringMatching(/components$/), + expect.anything(), + ) + expect(mockWriteFile).toHaveBeenNthCalledWith( + 1, + expect.stringMatching(/tailwind.config.ts$/), + expect.stringContaining('/** @type {import(\'tailwindcss\').Config} */'), + 'utf8', + ) + expect(mockWriteFile).toHaveBeenNthCalledWith( + 2, + expect.stringMatching(/src\/assets\/css\/tailwind.css$/), + expect.stringContaining('@tailwind base'), + 'utf8', + ) + expect(mockWriteFile).toHaveBeenNthCalledWith( + 3, + expect.stringMatching(/utils.ts$/), + expect.stringContaining('import { type ClassValue, clsx } from "clsx"'), + 'utf8', + ) + expect(execa).toHaveBeenCalledWith( + 'npm', + [ + 'install', + 'tailwindcss-animate', + 'class-variance-authority', + 'clsx', + 'tailwind-merge', + 'lucide-react', + ], + { + cwd: targetDir, + }, + ) + + mockMkdir.mockRestore() + mockWriteFile.mockRestore() +}) + +afterEach(() => { + vi.resetAllMocks() +}) diff --git a/packages/cli/test/fixtures/colors/neutral.json b/packages/cli/test/fixtures/colors/neutral.json new file mode 100644 index 00000000..c2488562 --- /dev/null +++ b/packages/cli/test/fixtures/colors/neutral.json @@ -0,0 +1,92 @@ +{ + "inlineColors": { + "light": { + "background": "white", + "foreground": "neutral-950", + "muted": "neutral-100", + "muted-foreground": "neutral-500", + "popover": "white", + "popover-foreground": "neutral-950", + "border": "neutral-200", + "input": "neutral-200", + "card": "white", + "card-foreground": "neutral-950", + "primary": "neutral-900", + "primary-foreground": "neutral-50", + "secondary": "neutral-100", + "secondary-foreground": "neutral-900", + "accent": "neutral-100", + "accent-foreground": "neutral-900", + "destructive": "red-500", + "destructive-foreground": "neutral-50", + "ring": "neutral-400" + }, + "dark": { + "background": "neutral-950", + "foreground": "neutral-50", + "muted": "neutral-800", + "muted-foreground": "neutral-400", + "popover": "neutral-950", + "popover-foreground": "neutral-50", + "border": "neutral-800", + "input": "neutral-800", + "card": "neutral-950", + "card-foreground": "neutral-50", + "primary": "neutral-50", + "primary-foreground": "neutral-900", + "secondary": "neutral-800", + "secondary-foreground": "neutral-50", + "accent": "neutral-800", + "accent-foreground": "neutral-50", + "destructive": "red-900", + "destructive-foreground": "red-50", + "ring": "neutral-800" + } + }, + "cssVars": { + "light": { + "background": "0 0% 100%", + "foreground": "0 0% 3.9%", + "muted": "0 0% 96.1%", + "muted-foreground": "0 0% 45.1%", + "popover": "0 0% 100%", + "popover-foreground": "0 0% 3.9%", + "border": "0 0% 89.8%", + "input": "0 0% 89.8%", + "card": "0 0% 100%", + "card-foreground": "0 0% 3.9%", + "primary": "0 0% 9%", + "primary-foreground": "0 0% 98%", + "secondary": "0 0% 96.1%", + "secondary-foreground": "0 0% 9%", + "accent": "0 0% 96.1%", + "accent-foreground": "0 0% 9%", + "destructive": "0 84.2% 60.2%", + "destructive-foreground": "0 0% 98%", + "ring": "0 0% 63.9%" + }, + "dark": { + "background": "0 0% 3.9%", + "foreground": "0 0% 98%", + "muted": "0 0% 14.9%", + "muted-foreground": "0 0% 63.9%", + "popover": "0 0% 3.9%", + "popover-foreground": "0 0% 98%", + "border": "0 0% 14.9%", + "input": "0 0% 14.9%", + "card": "0 0% 3.9%", + "card-foreground": "0 0% 98%", + "primary": "0 0% 98%", + "primary-foreground": "0 0% 9%", + "secondary": "0 0% 14.9%", + "secondary-foreground": "0 0% 98%", + "accent": "0 0% 14.9%", + "accent-foreground": "0 0% 98%", + "destructive": "0 62.8% 30.6%", + "destructive-foreground": "0 85.7% 97.3%", + "ring": "0 0% 14.9%" + } + }, + "inlineColorsTemplate": "@tailwind base;\n@tailwind components;\n@tailwind utilities;\n", + "cssVarsTemplate": "@tailwind base;\n@tailwind components;\n@tailwind utilities;\n \n@layer base {\n :root {\n --background: 0 0% 100%;\n --foreground: 0 0% 3.9%;\n \n --muted: 0 0% 96.1%;\n --muted-foreground: 0 0% 45.1%;\n \n --popover: 0 0% 100%;\n --popover-foreground: 0 0% 3.9%;\n \n --card: 0 0% 100%;\n --card-foreground: 0 0% 3.9%;\n \n --border: 0 0% 89.8%;\n --input: 0 0% 89.8%;\n \n --primary: 0 0% 9%;\n --primary-foreground: 0 0% 98%;\n \n --secondary: 0 0% 96.1%;\n --secondary-foreground: 0 0% 9%;\n \n --accent: 0 0% 96.1%;\n --accent-foreground: 0 0% 9%;\n \n --destructive: 0 84.2% 60.2%;\n --destructive-foreground: 0 0% 98%;\n \n --ring: 0 0% 63.9%;\n \n --radius: 0.5rem;\n }\n \n .dark {\n --background: 0 0% 3.9%;\n --foreground: 0 0% 98%;\n \n --muted: 0 0% 14.9%;\n --muted-foreground: 0 0% 63.9%;\n \n --popover: 0 0% 3.9%;\n --popover-foreground: 0 0% 98%;\n \n --card: 0 0% 3.9%;\n --card-foreground: 0 0% 98%;\n \n --border: 0 0% 14.9%;\n --input: 0 0% 14.9%;\n \n --primary: 0 0% 98%;\n --primary-foreground: 0 0% 9%;\n \n --secondary: 0 0% 14.9%;\n --secondary-foreground: 0 0% 98%;\n \n --accent: 0 0% 14.9%;\n --accent-foreground: 0 0% 98%;\n \n --destructive: 0 62.8% 30.6%;\n --destructive-foreground: 0 85.7% 97.3%;\n \n --ring: 0 0% 14.9%;\n }\n}\n \n@layer base {\n * {\n @apply border-border;\n }\n body {\n @apply bg-background text-foreground;\n }\n}" +} \ No newline at end of file diff --git a/packages/cli/test/fixtures/colors/slate.json b/packages/cli/test/fixtures/colors/slate.json new file mode 100644 index 00000000..46469cb7 --- /dev/null +++ b/packages/cli/test/fixtures/colors/slate.json @@ -0,0 +1,92 @@ +{ + "inlineColors": { + "light": { + "background": "white", + "foreground": "slate-950", + "muted": "slate-100", + "muted-foreground": "slate-500", + "popover": "white", + "popover-foreground": "slate-950", + "border": "slate-200", + "input": "slate-200", + "card": "white", + "card-foreground": "slate-950", + "primary": "slate-900", + "primary-foreground": "slate-50", + "secondary": "slate-100", + "secondary-foreground": "slate-900", + "accent": "slate-100", + "accent-foreground": "slate-900", + "destructive": "red-500", + "destructive-foreground": "slate-50", + "ring": "slate-400" + }, + "dark": { + "background": "slate-950", + "foreground": "slate-50", + "muted": "slate-800", + "muted-foreground": "slate-400", + "popover": "slate-950", + "popover-foreground": "slate-50", + "border": "slate-800", + "input": "slate-800", + "card": "slate-950", + "card-foreground": "slate-50", + "primary": "slate-50", + "primary-foreground": "slate-900", + "secondary": "slate-800", + "secondary-foreground": "slate-50", + "accent": "slate-800", + "accent-foreground": "slate-50", + "destructive": "red-900", + "destructive-foreground": "red-50", + "ring": "slate-800" + } + }, + "cssVars": { + "light": { + "background": "0 0% 100%", + "foreground": "222.2 84% 4.9%", + "muted": "210 40% 96.1%", + "muted-foreground": "215.4 16.3% 46.9%", + "popover": "0 0% 100%", + "popover-foreground": "222.2 84% 4.9%", + "border": "214.3 31.8% 91.4%", + "input": "214.3 31.8% 91.4%", + "card": "0 0% 100%", + "card-foreground": "222.2 84% 4.9%", + "primary": "222.2 47.4% 11.2%", + "primary-foreground": "210 40% 98%", + "secondary": "210 40% 96.1%", + "secondary-foreground": "222.2 47.4% 11.2%", + "accent": "210 40% 96.1%", + "accent-foreground": "222.2 47.4% 11.2%", + "destructive": "0 84.2% 60.2%", + "destructive-foreground": "210 40% 98%", + "ring": "215 20.2% 65.1%" + }, + "dark": { + "background": "222.2 84% 4.9%", + "foreground": "210 40% 98%", + "muted": "217.2 32.6% 17.5%", + "muted-foreground": "215 20.2% 65.1%", + "popover": "222.2 84% 4.9%", + "popover-foreground": "210 40% 98%", + "border": "217.2 32.6% 17.5%", + "input": "217.2 32.6% 17.5%", + "card": "222.2 84% 4.9%", + "card-foreground": "210 40% 98%", + "primary": "210 40% 98%", + "primary-foreground": "222.2 47.4% 11.2%", + "secondary": "217.2 32.6% 17.5%", + "secondary-foreground": "210 40% 98%", + "accent": "217.2 32.6% 17.5%", + "accent-foreground": "210 40% 98%", + "destructive": "0 62.8% 30.6%", + "destructive-foreground": "0 85.7% 97.3%", + "ring": "217.2 32.6% 17.5%" + } + }, + "inlineColorsTemplate": "@tailwind base;\n@tailwind components;\n@tailwind utilities;\n", + "cssVarsTemplate": "@tailwind base;\n@tailwind components;\n@tailwind utilities;\n \n@layer base {\n :root {\n --background: 0 0% 100%;\n --foreground: 222.2 84% 4.9%;\n \n --muted: 210 40% 96.1%;\n --muted-foreground: 215.4 16.3% 46.9%;\n \n --popover: 0 0% 100%;\n --popover-foreground: 222.2 84% 4.9%;\n \n --card: 0 0% 100%;\n --card-foreground: 222.2 84% 4.9%;\n \n --border: 214.3 31.8% 91.4%;\n --input: 214.3 31.8% 91.4%;\n \n --primary: 222.2 47.4% 11.2%;\n --primary-foreground: 210 40% 98%;\n \n --secondary: 210 40% 96.1%;\n --secondary-foreground: 222.2 47.4% 11.2%;\n \n --accent: 210 40% 96.1%;\n --accent-foreground: 222.2 47.4% 11.2%;\n \n --destructive: 0 84.2% 60.2%;\n --destructive-foreground: 210 40% 98%;\n \n --ring: 215 20.2% 65.1%;\n \n --radius: 0.5rem;\n }\n \n .dark {\n --background: 222.2 84% 4.9%;\n --foreground: 210 40% 98%;\n \n --muted: 217.2 32.6% 17.5%;\n --muted-foreground: 215 20.2% 65.1%;\n \n --popover: 222.2 84% 4.9%;\n --popover-foreground: 210 40% 98%;\n \n --card: 222.2 84% 4.9%;\n --card-foreground: 210 40% 98%;\n \n --border: 217.2 32.6% 17.5%;\n --input: 217.2 32.6% 17.5%;\n \n --primary: 210 40% 98%;\n --primary-foreground: 222.2 47.4% 11.2%;\n \n --secondary: 217.2 32.6% 17.5%;\n --secondary-foreground: 210 40% 98%;\n \n --accent: 217.2 32.6% 17.5%;\n --accent-foreground: 210 40% 98%;\n \n --destructive: 0 62.8% 30.6%;\n --destructive-foreground: 0 85.7% 97.3%;\n \n --ring: 217.2 32.6% 17.5%;\n }\n}\n \n@layer base {\n * {\n @apply border-border;\n }\n body {\n @apply bg-background text-foreground;\n }\n}" +} \ No newline at end of file diff --git a/packages/cli/test/fixtures/colors/stone.json b/packages/cli/test/fixtures/colors/stone.json new file mode 100644 index 00000000..05e92bb5 --- /dev/null +++ b/packages/cli/test/fixtures/colors/stone.json @@ -0,0 +1,92 @@ +{ + "inlineColors": { + "light": { + "background": "white", + "foreground": "stone-950", + "muted": "stone-100", + "muted-foreground": "stone-500", + "popover": "white", + "popover-foreground": "stone-950", + "border": "stone-200", + "input": "stone-200", + "card": "white", + "card-foreground": "stone-950", + "primary": "stone-900", + "primary-foreground": "stone-50", + "secondary": "stone-100", + "secondary-foreground": "stone-900", + "accent": "stone-100", + "accent-foreground": "stone-900", + "destructive": "red-500", + "destructive-foreground": "stone-50", + "ring": "stone-400" + }, + "dark": { + "background": "stone-950", + "foreground": "stone-50", + "muted": "stone-800", + "muted-foreground": "stone-400", + "popover": "stone-950", + "popover-foreground": "stone-50", + "border": "stone-800", + "input": "stone-800", + "card": "stone-950", + "card-foreground": "stone-50", + "primary": "stone-50", + "primary-foreground": "stone-900", + "secondary": "stone-800", + "secondary-foreground": "stone-50", + "accent": "stone-800", + "accent-foreground": "stone-50", + "destructive": "red-900", + "destructive-foreground": "red-50", + "ring": "stone-800" + } + }, + "cssVars": { + "light": { + "background": "0 0% 100%", + "foreground": "20 14.3% 4.1%", + "muted": "60 4.8% 95.9%", + "muted-foreground": "25 5.3% 44.7%", + "popover": "0 0% 100%", + "popover-foreground": "20 14.3% 4.1%", + "border": "20 5.9% 90%", + "input": "20 5.9% 90%", + "card": "0 0% 100%", + "card-foreground": "20 14.3% 4.1%", + "primary": "24 9.8% 10%", + "primary-foreground": "60 9.1% 97.8%", + "secondary": "60 4.8% 95.9%", + "secondary-foreground": "24 9.8% 10%", + "accent": "60 4.8% 95.9%", + "accent-foreground": "24 9.8% 10%", + "destructive": "0 84.2% 60.2%", + "destructive-foreground": "60 9.1% 97.8%", + "ring": "24 5.4% 63.9%" + }, + "dark": { + "background": "20 14.3% 4.1%", + "foreground": "60 9.1% 97.8%", + "muted": "12 6.5% 15.1%", + "muted-foreground": "24 5.4% 63.9%", + "popover": "20 14.3% 4.1%", + "popover-foreground": "60 9.1% 97.8%", + "border": "12 6.5% 15.1%", + "input": "12 6.5% 15.1%", + "card": "20 14.3% 4.1%", + "card-foreground": "60 9.1% 97.8%", + "primary": "60 9.1% 97.8%", + "primary-foreground": "24 9.8% 10%", + "secondary": "12 6.5% 15.1%", + "secondary-foreground": "60 9.1% 97.8%", + "accent": "12 6.5% 15.1%", + "accent-foreground": "60 9.1% 97.8%", + "destructive": "0 62.8% 30.6%", + "destructive-foreground": "0 85.7% 97.3%", + "ring": "12 6.5% 15.1%" + } + }, + "inlineColorsTemplate": "@tailwind base;\n@tailwind components;\n@tailwind utilities;\n", + "cssVarsTemplate": "@tailwind base;\n@tailwind components;\n@tailwind utilities;\n \n@layer base {\n :root {\n --background: 0 0% 100%;\n --foreground: 20 14.3% 4.1%;\n \n --muted: 60 4.8% 95.9%;\n --muted-foreground: 25 5.3% 44.7%;\n \n --popover: 0 0% 100%;\n --popover-foreground: 20 14.3% 4.1%;\n \n --card: 0 0% 100%;\n --card-foreground: 20 14.3% 4.1%;\n \n --border: 20 5.9% 90%;\n --input: 20 5.9% 90%;\n \n --primary: 24 9.8% 10%;\n --primary-foreground: 60 9.1% 97.8%;\n \n --secondary: 60 4.8% 95.9%;\n --secondary-foreground: 24 9.8% 10%;\n \n --accent: 60 4.8% 95.9%;\n --accent-foreground: 24 9.8% 10%;\n \n --destructive: 0 84.2% 60.2%;\n --destructive-foreground: 60 9.1% 97.8%;\n \n --ring: 24 5.4% 63.9%;\n \n --radius: 0.5rem;\n }\n \n .dark {\n --background: 20 14.3% 4.1%;\n --foreground: 60 9.1% 97.8%;\n \n --muted: 12 6.5% 15.1%;\n --muted-foreground: 24 5.4% 63.9%;\n \n --popover: 20 14.3% 4.1%;\n --popover-foreground: 60 9.1% 97.8%;\n \n --card: 20 14.3% 4.1%;\n --card-foreground: 60 9.1% 97.8%;\n \n --border: 12 6.5% 15.1%;\n --input: 12 6.5% 15.1%;\n \n --primary: 60 9.1% 97.8%;\n --primary-foreground: 24 9.8% 10%;\n \n --secondary: 12 6.5% 15.1%;\n --secondary-foreground: 60 9.1% 97.8%;\n \n --accent: 12 6.5% 15.1%;\n --accent-foreground: 60 9.1% 97.8%;\n \n --destructive: 0 62.8% 30.6%;\n --destructive-foreground: 0 85.7% 97.3%;\n \n --ring: 12 6.5% 15.1%;\n }\n}\n \n@layer base {\n * {\n @apply border-border;\n }\n body {\n @apply bg-background text-foreground;\n }\n}" +} \ No newline at end of file diff --git a/packages/cli/test/fixtures/colors/zinc.json b/packages/cli/test/fixtures/colors/zinc.json new file mode 100644 index 00000000..c26bf0e8 --- /dev/null +++ b/packages/cli/test/fixtures/colors/zinc.json @@ -0,0 +1,92 @@ +{ + "inlineColors": { + "light": { + "background": "white", + "foreground": "zinc-950", + "muted": "zinc-100", + "muted-foreground": "zinc-500", + "popover": "white", + "popover-foreground": "zinc-950", + "border": "zinc-200", + "input": "zinc-200", + "card": "white", + "card-foreground": "zinc-950", + "primary": "zinc-900", + "primary-foreground": "zinc-50", + "secondary": "zinc-100", + "secondary-foreground": "zinc-900", + "accent": "zinc-100", + "accent-foreground": "zinc-900", + "destructive": "red-500", + "destructive-foreground": "zinc-50", + "ring": "zinc-400" + }, + "dark": { + "background": "zinc-950", + "foreground": "zinc-50", + "muted": "zinc-800", + "muted-foreground": "zinc-400", + "popover": "zinc-950", + "popover-foreground": "zinc-50", + "border": "zinc-800", + "input": "zinc-800", + "card": "zinc-950", + "card-foreground": "zinc-50", + "primary": "zinc-50", + "primary-foreground": "zinc-900", + "secondary": "zinc-800", + "secondary-foreground": "zinc-50", + "accent": "zinc-800", + "accent-foreground": "zinc-50", + "destructive": "red-900", + "destructive-foreground": "red-50", + "ring": "zinc-800" + } + }, + "cssVars": { + "light": { + "background": "0 0% 100%", + "foreground": "240 10% 3.9%", + "muted": "240 4.8% 95.9%", + "muted-foreground": "240 3.8% 46.1%", + "popover": "0 0% 100%", + "popover-foreground": "240 10% 3.9%", + "border": "240 5.9% 90%", + "input": "240 5.9% 90%", + "card": "0 0% 100%", + "card-foreground": "240 10% 3.9%", + "primary": "240 5.9% 10%", + "primary-foreground": "0 0% 98%", + "secondary": "240 4.8% 95.9%", + "secondary-foreground": "240 5.9% 10%", + "accent": "240 4.8% 95.9%", + "accent-foreground": "240 5.9% 10%", + "destructive": "0 84.2% 60.2%", + "destructive-foreground": "0 0% 98%", + "ring": "240 5% 64.9%" + }, + "dark": { + "background": "240 10% 3.9%", + "foreground": "0 0% 98%", + "muted": "240 3.7% 15.9%", + "muted-foreground": "240 5% 64.9%", + "popover": "240 10% 3.9%", + "popover-foreground": "0 0% 98%", + "border": "240 3.7% 15.9%", + "input": "240 3.7% 15.9%", + "card": "240 10% 3.9%", + "card-foreground": "0 0% 98%", + "primary": "0 0% 98%", + "primary-foreground": "240 5.9% 10%", + "secondary": "240 3.7% 15.9%", + "secondary-foreground": "0 0% 98%", + "accent": "240 3.7% 15.9%", + "accent-foreground": "0 0% 98%", + "destructive": "0 62.8% 30.6%", + "destructive-foreground": "0 85.7% 97.3%", + "ring": "240 3.7% 15.9%" + } + }, + "inlineColorsTemplate": "@tailwind base;\n@tailwind components;\n@tailwind utilities;\n", + "cssVarsTemplate": "@tailwind base;\n@tailwind components;\n@tailwind utilities;\n \n@layer base {\n :root {\n --background: 0 0% 100%;\n --foreground: 240 10% 3.9%;\n \n --muted: 240 4.8% 95.9%;\n --muted-foreground: 240 3.8% 46.1%;\n \n --popover: 0 0% 100%;\n --popover-foreground: 240 10% 3.9%;\n \n --card: 0 0% 100%;\n --card-foreground: 240 10% 3.9%;\n \n --border: 240 5.9% 90%;\n --input: 240 5.9% 90%;\n \n --primary: 240 5.9% 10%;\n --primary-foreground: 0 0% 98%;\n \n --secondary: 240 4.8% 95.9%;\n --secondary-foreground: 240 5.9% 10%;\n \n --accent: 240 4.8% 95.9%;\n --accent-foreground: 240 5.9% 10%;\n \n --destructive: 0 84.2% 60.2%;\n --destructive-foreground: 0 0% 98%;\n \n --ring: 240 5% 64.9%;\n \n --radius: 0.5rem;\n }\n \n .dark {\n --background: 240 10% 3.9%;\n --foreground: 0 0% 98%;\n \n --muted: 240 3.7% 15.9%;\n --muted-foreground: 240 5% 64.9%;\n \n --popover: 240 10% 3.9%;\n --popover-foreground: 0 0% 98%;\n \n --card: 240 10% 3.9%;\n --card-foreground: 0 0% 98%;\n \n --border: 240 3.7% 15.9%;\n --input: 240 3.7% 15.9%;\n \n --primary: 0 0% 98%;\n --primary-foreground: 240 5.9% 10%;\n \n --secondary: 240 3.7% 15.9%;\n --secondary-foreground: 0 0% 98%;\n \n --accent: 240 3.7% 15.9%;\n --accent-foreground: 0 0% 98%;\n \n --destructive: 0 62.8% 30.6%;\n --destructive-foreground: 0 85.7% 97.3%;\n \n --ring: 240 3.7% 15.9%;\n }\n}\n \n@layer base {\n * {\n @apply border-border;\n }\n body {\n @apply bg-background text-foreground;\n }\n}" +} \ No newline at end of file diff --git a/packages/cli/test/fixtures/config-full/components.json b/packages/cli/test/fixtures/config-full/components.json new file mode 100644 index 00000000..98192ad1 --- /dev/null +++ b/packages/cli/test/fixtures/config-full/components.json @@ -0,0 +1,14 @@ +{ + "style": "default", + "tailwind": { + "config": "tailwind.config.ts", + "css": "src/app/globals.css", + "baseColor": "zinc", + "cssVariables": true + }, + "rsc": false, + "aliases": { + "utils": "~/lib/utils", + "components": "~/components" + } +} diff --git a/packages/cli/test/fixtures/config-full/package.json b/packages/cli/test/fixtures/config-full/package.json new file mode 100644 index 00000000..833dc70a --- /dev/null +++ b/packages/cli/test/fixtures/config-full/package.json @@ -0,0 +1,7 @@ +{ + "name": "test-cli-config-full", + "version": "1.0.0", + "main": "index.js", + "author": "shadcn", + "license": "MIT" +} diff --git a/packages/cli/test/fixtures/config-full/tsconfig.json b/packages/cli/test/fixtures/config-full/tsconfig.json new file mode 100644 index 00000000..03ebb748 --- /dev/null +++ b/packages/cli/test/fixtures/config-full/tsconfig.json @@ -0,0 +1,33 @@ +{ + "compilerOptions": { + "target": "es2017", + "lib": ["dom", "dom.iterable", "esnext"], + "allowJs": true, + "checkJs": true, + "skipLibCheck": true, + "strict": true, + "forceConsistentCasingInFileNames": true, + "noEmit": true, + "esModuleInterop": true, + "module": "esnext", + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true, + "jsx": "preserve", + "incremental": true, + "noUncheckedIndexedAccess": true, + "baseUrl": ".", + "paths": { + "~/*": ["./src/*"] + } + }, + "include": [ + ".eslintrc.cjs", + "next-env.d.ts", + "**/*.ts", + "**/*.tsx", + "**/*.cjs", + "**/*.mjs" + ], + "exclude": ["node_modules"] +} diff --git a/packages/cli/test/fixtures/config-invalid/components.json b/packages/cli/test/fixtures/config-invalid/components.json new file mode 100644 index 00000000..3cbc313f --- /dev/null +++ b/packages/cli/test/fixtures/config-invalid/components.json @@ -0,0 +1,5 @@ +{ + "cn": "./components", + "ui": "./ui", + "does-not-exist": "./does-not-exist" +} diff --git a/packages/cli/test/fixtures/config-invalid/package.json b/packages/cli/test/fixtures/config-invalid/package.json new file mode 100644 index 00000000..79b27998 --- /dev/null +++ b/packages/cli/test/fixtures/config-invalid/package.json @@ -0,0 +1,7 @@ +{ + "name": "test-cli-config-invalid", + "version": "1.0.0", + "main": "index.js", + "author": "shadcn", + "license": "MIT" +} diff --git a/packages/cli/test/fixtures/config-jsx/components.json b/packages/cli/test/fixtures/config-jsx/components.json new file mode 100644 index 00000000..92b1f5e0 --- /dev/null +++ b/packages/cli/test/fixtures/config-jsx/components.json @@ -0,0 +1,14 @@ +{ + "style": "default", + "tsx": false, + "tailwind": { + "config": "./tailwind.config.js", + "css": "./src/assets/css/tailwind.css", + "baseColor": "neutral", + "cssVariables": false + }, + "aliases": { + "utils": "@/lib/utils", + "components": "@/components" + } +} diff --git a/packages/cli/test/fixtures/config-jsx/jsconfig.json b/packages/cli/test/fixtures/config-jsx/jsconfig.json new file mode 100644 index 00000000..2a2e4b3b --- /dev/null +++ b/packages/cli/test/fixtures/config-jsx/jsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "paths": { + "@/*": ["./*"] + } + } +} diff --git a/packages/cli/test/fixtures/config-jsx/package.json b/packages/cli/test/fixtures/config-jsx/package.json new file mode 100644 index 00000000..b239ba4a --- /dev/null +++ b/packages/cli/test/fixtures/config-jsx/package.json @@ -0,0 +1,7 @@ +{ + "name": "test-cli-config-partial", + "version": "1.0.0", + "main": "index.js", + "author": "shadcn", + "license": "MIT" +} diff --git a/packages/cli/test/fixtures/config-none/package.json b/packages/cli/test/fixtures/config-none/package.json new file mode 100644 index 00000000..74c6960a --- /dev/null +++ b/packages/cli/test/fixtures/config-none/package.json @@ -0,0 +1,7 @@ +{ + "name": "test-cli-config-none", + "version": "1.0.0", + "main": "index.js", + "author": "shadcn", + "license": "MIT" +} diff --git a/packages/cli/test/fixtures/config-partial/components.json b/packages/cli/test/fixtures/config-partial/components.json new file mode 100644 index 00000000..b0602580 --- /dev/null +++ b/packages/cli/test/fixtures/config-partial/components.json @@ -0,0 +1,13 @@ +{ + "style": "default", + "tailwind": { + "config": "./tailwind.config.ts", + "css": "./src/assets/css/tailwind.css", + "baseColor": "neutral", + "cssVariables": false + }, + "aliases": { + "utils": "@/lib/utils", + "components": "@/components" + } +} diff --git a/packages/cli/test/fixtures/config-partial/package.json b/packages/cli/test/fixtures/config-partial/package.json new file mode 100644 index 00000000..b239ba4a --- /dev/null +++ b/packages/cli/test/fixtures/config-partial/package.json @@ -0,0 +1,7 @@ +{ + "name": "test-cli-config-partial", + "version": "1.0.0", + "main": "index.js", + "author": "shadcn", + "license": "MIT" +} diff --git a/packages/cli/test/fixtures/config-partial/tsconfig.json b/packages/cli/test/fixtures/config-partial/tsconfig.json new file mode 100644 index 00000000..7f519f45 --- /dev/null +++ b/packages/cli/test/fixtures/config-partial/tsconfig.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "compilerOptions": { + "baseUrl": ".", + "paths": { + "@/*": ["./*"] + } + } +} diff --git a/packages/cli/test/fixtures/project-bun/bun.lockb b/packages/cli/test/fixtures/project-bun/bun.lockb new file mode 100644 index 00000000..fea2ca25 Binary files /dev/null and b/packages/cli/test/fixtures/project-bun/bun.lockb differ diff --git a/packages/cli/test/fixtures/project-bun/package.json b/packages/cli/test/fixtures/project-bun/package.json new file mode 100644 index 00000000..b8cfd201 --- /dev/null +++ b/packages/cli/test/fixtures/project-bun/package.json @@ -0,0 +1,7 @@ +{ + "name": "test-cli-project-bun", + "version": "1.0.0", + "main": "index.js", + "author": "shadcn", + "license": "MIT" +} diff --git a/packages/cli/test/fixtures/project-npm/package-lock.json b/packages/cli/test/fixtures/project-npm/package-lock.json new file mode 100644 index 00000000..9b6d3cd8 --- /dev/null +++ b/packages/cli/test/fixtures/project-npm/package-lock.json @@ -0,0 +1,13 @@ +{ + "name": "test-cli-npm-project", + "version": "1.0.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "npm-project", + "version": "1.0.0", + "license": "MIT" + } + } +} diff --git a/packages/cli/test/fixtures/project-npm/package.json b/packages/cli/test/fixtures/project-npm/package.json new file mode 100644 index 00000000..68c468ac --- /dev/null +++ b/packages/cli/test/fixtures/project-npm/package.json @@ -0,0 +1,7 @@ +{ + "name": "test-cli-project-npm", + "version": "1.0.0", + "main": "index.js", + "author": "shadcn", + "license": "MIT" +} diff --git a/packages/cli/test/fixtures/project-pnpm/package.json b/packages/cli/test/fixtures/project-pnpm/package.json new file mode 100644 index 00000000..af855da3 --- /dev/null +++ b/packages/cli/test/fixtures/project-pnpm/package.json @@ -0,0 +1,7 @@ +{ + "name": "test-cli-project-pnpm", + "version": "1.0.0", + "main": "index.js", + "author": "shadcn", + "license": "MIT" +} diff --git a/packages/cli/test/fixtures/project-pnpm/pnpm-lock.yaml b/packages/cli/test/fixtures/project-pnpm/pnpm-lock.yaml new file mode 100644 index 00000000..7a06cc79 --- /dev/null +++ b/packages/cli/test/fixtures/project-pnpm/pnpm-lock.yaml @@ -0,0 +1 @@ +lockfileVersion: '6.0' diff --git a/packages/cli/test/fixtures/project-src/components.json b/packages/cli/test/fixtures/project-src/components.json new file mode 100644 index 00000000..1f7b81e6 --- /dev/null +++ b/packages/cli/test/fixtures/project-src/components.json @@ -0,0 +1,7 @@ +{ + "components": "src/components", + "ui": "src/ui", + "styles": "src/styles/main.css", + "utils": "src/lib/cn.ts", + "tailwindConfig": "tailwind.config.ts" +} diff --git a/packages/cli/test/fixtures/project-src/package-lock.json b/packages/cli/test/fixtures/project-src/package-lock.json new file mode 100644 index 00000000..98ef11bd --- /dev/null +++ b/packages/cli/test/fixtures/project-src/package-lock.json @@ -0,0 +1,13 @@ +{ + "name": "test-cli-project-src", + "version": "1.0.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "npm-project", + "version": "1.0.0", + "license": "MIT" + } + } +} diff --git a/packages/cli/test/fixtures/project-src/package.json b/packages/cli/test/fixtures/project-src/package.json new file mode 100644 index 00000000..a536a6f0 --- /dev/null +++ b/packages/cli/test/fixtures/project-src/package.json @@ -0,0 +1,5 @@ +{ + "name": "project-src", + "version": "0.1.0", + "private": true +} diff --git a/packages/cli/test/fixtures/project-yarn/package.json b/packages/cli/test/fixtures/project-yarn/package.json new file mode 100644 index 00000000..ed044dce --- /dev/null +++ b/packages/cli/test/fixtures/project-yarn/package.json @@ -0,0 +1,7 @@ +{ + "name": "test-cli-project-yarn", + "version": "1.0.0", + "main": "index.js", + "author": "shadcn", + "license": "MIT" +} diff --git a/packages/cli/test/fixtures/project-yarn/yarn.lock b/packages/cli/test/fixtures/project-yarn/yarn.lock new file mode 100644 index 00000000..fb57ccd1 --- /dev/null +++ b/packages/cli/test/fixtures/project-yarn/yarn.lock @@ -0,0 +1,4 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + diff --git a/packages/cli/test/fixtures/project/components.json b/packages/cli/test/fixtures/project/components.json new file mode 100644 index 00000000..054e09ac --- /dev/null +++ b/packages/cli/test/fixtures/project/components.json @@ -0,0 +1,8 @@ +{ + "tailwindConfig": "./tailwind.config.ts", + "importPaths": { + "styles": "~/styles/globals.css", + "utils:cn": "~/lib/cn.ts", + "components:ui": "~/components/ui" + } +} diff --git a/packages/cli/test/fixtures/project/package.json b/packages/cli/test/fixtures/project/package.json new file mode 100644 index 00000000..30a6a922 --- /dev/null +++ b/packages/cli/test/fixtures/project/package.json @@ -0,0 +1,5 @@ +{ + "name": "test-cli-project", + "version": "0.1.0", + "private": true +} diff --git a/packages/cli/test/fixtures/project/pnpm-lock.yaml b/packages/cli/test/fixtures/project/pnpm-lock.yaml new file mode 100644 index 00000000..7becc665 --- /dev/null +++ b/packages/cli/test/fixtures/project/pnpm-lock.yaml @@ -0,0 +1 @@ +lockfileVersion: "6.0" diff --git a/packages/cli/test/fixtures/with-base-url/tsconfig.json b/packages/cli/test/fixtures/with-base-url/tsconfig.json new file mode 100644 index 00000000..7f519f45 --- /dev/null +++ b/packages/cli/test/fixtures/with-base-url/tsconfig.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "compilerOptions": { + "baseUrl": ".", + "paths": { + "@/*": ["./*"] + } + } +} diff --git a/packages/cli/test/fixtures/without-base-url/tsconfig.json b/packages/cli/test/fixtures/without-base-url/tsconfig.json new file mode 100644 index 00000000..b43c5102 --- /dev/null +++ b/packages/cli/test/fixtures/without-base-url/tsconfig.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "compilerOptions": { + "paths": { + "~/components/*": ["./components/*"], + "~/lib/*": ["./lib/*"] + } + } +} diff --git a/packages/cli/test/utils/__snapshots__/transform-css-vars.test.ts.snap b/packages/cli/test/utils/__snapshots__/transform-css-vars.test.ts.snap new file mode 100644 index 00000000..9f5962a2 --- /dev/null +++ b/packages/cli/test/utils/__snapshots__/transform-css-vars.test.ts.snap @@ -0,0 +1,25 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`transform css vars 1`] = ` +"import * as React from \\"react\\" +export function Foo() { + return