* feat: add devDeps, add nypm for installing deps
* feat: custom ui dir
* refactor: use consola instead of chalk
* test: ui alias
* refactor: import { z } from 'zod' instead of *, replace node:path with pathe
* chore: add components name to `configFile` option
* chore: update `c12` which fix json5 parse issue
and it also supports .config directory
* chore: update `https-proxy-agent`
* fix: await until dependencies are installed then run detypes process
* feat: add tailwind prefix
* test: tw-prefix snapshot
* chore: add prefix option to init
* test: apply prefix
* fix: tw-prefix parse wrongly
* chore: hide prefix temporarily
---------
Co-authored-by: zernonia <zernonia@gmail.com>
160 lines
4.3 KiB
TypeScript
160 lines
4.3 KiB
TypeScript
import fs from 'node:fs'
|
|
import path from 'pathe'
|
|
import { addDependency, addDevDependency } from 'nypm'
|
|
import { afterEach, expect, test, vi } from 'vitest'
|
|
|
|
import { runInit } from '../../src/commands/init'
|
|
import { getConfig } from '../../src/utils/get-config'
|
|
import * as registry from '../../src/utils/registry'
|
|
|
|
vi.mock('nypm')
|
|
vi.mock('fs/promises', () => ({
|
|
writeFile: vi.fn(),
|
|
mkdir: vi.fn(),
|
|
}))
|
|
vi.mock('ora')
|
|
|
|
test('init config-full', async () => {
|
|
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$/),
|
|
// eslint-disable-next-line @typescript-eslint/quotes
|
|
expect.stringContaining("import { type ClassValue, clsx } from 'clsx'"),
|
|
'utf8',
|
|
)
|
|
expect(addDependency).toHaveBeenCalledWith(
|
|
[
|
|
'tailwindcss-animate',
|
|
'class-variance-authority',
|
|
'clsx',
|
|
'tailwind-merge',
|
|
'radix-vue',
|
|
'@radix-icons/vue',
|
|
],
|
|
{
|
|
cwd: targetDir,
|
|
silent: true,
|
|
},
|
|
)
|
|
|
|
mockMkdir.mockRestore()
|
|
mockWriteFile.mockRestore()
|
|
})
|
|
|
|
test('init config-partial', async () => {
|
|
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$/),
|
|
// eslint-disable-next-line @typescript-eslint/quotes
|
|
expect.stringContaining("import { type ClassValue, clsx } from 'clsx'"),
|
|
'utf8',
|
|
)
|
|
expect(addDependency).toHaveBeenCalledWith(
|
|
[
|
|
'tailwindcss-animate',
|
|
'class-variance-authority',
|
|
'clsx',
|
|
'tailwind-merge',
|
|
'radix-vue',
|
|
'lucide-vue-next',
|
|
],
|
|
{
|
|
cwd: targetDir,
|
|
silent: true,
|
|
},
|
|
)
|
|
|
|
mockMkdir.mockRestore()
|
|
mockWriteFile.mockRestore()
|
|
})
|
|
|
|
afterEach(() => {
|
|
vi.resetAllMocks()
|
|
})
|