chore: cleanup and update test
This commit is contained in:
parent
c041011791
commit
8c7f816502
|
|
@ -99,7 +99,7 @@ export const diff = new Command()
|
|||
consola.info(` - ${change.filePath}`)
|
||||
}
|
||||
|
||||
console.log('')
|
||||
consola.log('')
|
||||
consola.info(
|
||||
`Run ${colors.green('diff <component>')} to see the changes.`,
|
||||
)
|
||||
|
|
@ -128,7 +128,7 @@ export const diff = new Command()
|
|||
for (const change of changes) {
|
||||
consola.info(`- ${change.filePath}`)
|
||||
printDiff(change.patch)
|
||||
console.log('')
|
||||
consola.log('')
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
|
|
|
|||
|
|
@ -73,11 +73,11 @@ export const init = new Command()
|
|||
|
||||
await runInit(cwd, config)
|
||||
|
||||
console.log('')
|
||||
consola.log('')
|
||||
consola.info(
|
||||
`${colors.green('Success!')} Project initialization completed.`,
|
||||
)
|
||||
console.log('')
|
||||
consola.log('')
|
||||
}
|
||||
catch (error) {
|
||||
handleError(error)
|
||||
|
|
@ -206,7 +206,7 @@ export async function promptForConfig(
|
|||
}
|
||||
|
||||
// Write to file.
|
||||
console.log('')
|
||||
consola.log('')
|
||||
const spinner = ora('Writing components.json...').start()
|
||||
const targetPath = path.resolve(cwd, 'components.json')
|
||||
await fs.writeFile(targetPath, JSON.stringify(config, null, 2), 'utf8')
|
||||
|
|
@ -291,8 +291,8 @@ export async function runInit(cwd: string, config: Config) {
|
|||
|
||||
await Promise.allSettled(
|
||||
[
|
||||
await addNuxtDevDeps(),
|
||||
await addDependency(deps, {
|
||||
addNuxtDevDeps(),
|
||||
addDependency(deps, {
|
||||
cwd,
|
||||
silent: true,
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -100,23 +100,21 @@ export async function resolveConfigPaths(cwd: string, config: RawConfig) {
|
|||
utils: resolveImport(config.aliases.utils, tsConfig),
|
||||
components: resolveImport(config.aliases.components, tsConfig),
|
||||
ui: config.aliases['ui']
|
||||
? await resolveImport(config.aliases['ui'], tsConfig)
|
||||
: await resolveImport(config.aliases['components'], tsConfig),
|
||||
? resolveImport(config.aliases['ui'], tsConfig)
|
||||
: resolveImport(config.aliases['components'], tsConfig),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export async function getRawConfig(cwd: string): Promise<RawConfig | null> {
|
||||
try {
|
||||
// const configResult = await explorer.search(cwd)
|
||||
|
||||
const configResult = await c12LoadConfig({
|
||||
name: 'components',
|
||||
configFile: 'components.json',
|
||||
cwd,
|
||||
})
|
||||
|
||||
if (!configResult)
|
||||
if (!configResult.config || Object.keys(configResult.config).length === 0)
|
||||
return null
|
||||
|
||||
return rawConfigSchema.parse(configResult.config)
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import { execa } from 'execa'
|
||||
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 getPackageManger from '../../src/utils/get-package-manager'
|
||||
import * as registry from '../../src/utils/registry'
|
||||
|
||||
vi.mock('execa')
|
||||
vi.mock('nypm')
|
||||
vi.mock('fs/promises', () => ({
|
||||
writeFile: vi.fn(),
|
||||
mkdir: vi.fn(),
|
||||
|
|
@ -16,7 +15,6 @@ vi.mock('fs/promises', () => ({
|
|||
vi.mock('ora')
|
||||
|
||||
test('init config-full', async () => {
|
||||
vi.spyOn(getPackageManger, 'getPackageManager').mockResolvedValue('pnpm')
|
||||
vi.spyOn(registry, 'getRegistryBaseColor').mockResolvedValue({
|
||||
inlineColors: {},
|
||||
cssVars: {},
|
||||
|
|
@ -67,10 +65,8 @@ test('init config-full', async () => {
|
|||
expect.stringContaining("import { type ClassValue, clsx } from 'clsx'"),
|
||||
'utf8',
|
||||
)
|
||||
expect(execa).toHaveBeenCalledWith(
|
||||
'pnpm',
|
||||
expect(addDependency).toHaveBeenCalledWith(
|
||||
[
|
||||
'add',
|
||||
'tailwindcss-animate',
|
||||
'class-variance-authority',
|
||||
'clsx',
|
||||
|
|
@ -80,6 +76,7 @@ test('init config-full', async () => {
|
|||
],
|
||||
{
|
||||
cwd: targetDir,
|
||||
silent: true,
|
||||
},
|
||||
)
|
||||
|
||||
|
|
@ -88,7 +85,6 @@ test('init config-full', async () => {
|
|||
})
|
||||
|
||||
test('init config-partial', async () => {
|
||||
vi.spyOn(getPackageManger, 'getPackageManager').mockResolvedValue('npm')
|
||||
vi.spyOn(registry, 'getRegistryBaseColor').mockResolvedValue({
|
||||
inlineColors: {},
|
||||
cssVars: {},
|
||||
|
|
@ -139,10 +135,8 @@ test('init config-partial', async () => {
|
|||
expect.stringContaining("import { type ClassValue, clsx } from 'clsx'"),
|
||||
'utf8',
|
||||
)
|
||||
expect(execa).toHaveBeenCalledWith(
|
||||
'npm',
|
||||
expect(addDependency).toHaveBeenCalledWith(
|
||||
[
|
||||
'install',
|
||||
'tailwindcss-animate',
|
||||
'class-variance-authority',
|
||||
'clsx',
|
||||
|
|
@ -152,6 +146,7 @@ test('init config-partial', async () => {
|
|||
],
|
||||
{
|
||||
cwd: targetDir,
|
||||
silent: true,
|
||||
},
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ describe('apply color mapping', async () => {
|
|||
input:
|
||||
'text-destructive border-destructive/50 dark:border-destructive [&>svg]:text-destructive text-destructive',
|
||||
output:
|
||||
'text-red-500 border-red-500/50 dark:border-red-500 [&>svg]:text-red-500 text-red-500 dark:text-red-900 dark:border-red-900/50 dark:dark:border-red-900 dark:[&>svg]:text-red-900 dark:text-red-900',
|
||||
'text-red-500 border-red-500/50 dark:border-red-500 [&>svg]:text-red-500 dark:text-red-900 dark:border-red-900/50 dark:dark:border-red-900 dark:[&>svg]:text-red-900',
|
||||
},
|
||||
{
|
||||
input:
|
||||
|
|
|
|||
|
|
@ -71,6 +71,11 @@ test('get config', async () => {
|
|||
'../fixtures/config-partial',
|
||||
'./components',
|
||||
),
|
||||
ui: path.resolve(
|
||||
__dirname,
|
||||
'../fixtures/config-partial',
|
||||
'./components',
|
||||
),
|
||||
utils: path.resolve(
|
||||
__dirname,
|
||||
'../fixtures/config-partial',
|
||||
|
|
@ -111,6 +116,11 @@ test('get config', async () => {
|
|||
'../fixtures/config-full',
|
||||
'./src/components',
|
||||
),
|
||||
ui: path.resolve(
|
||||
__dirname,
|
||||
'../fixtures/config-full',
|
||||
'./src/components',
|
||||
),
|
||||
utils: path.resolve(
|
||||
__dirname,
|
||||
'../fixtures/config-full',
|
||||
|
|
@ -152,6 +162,11 @@ test('get config', async () => {
|
|||
'../fixtures/config-js',
|
||||
'./components',
|
||||
),
|
||||
ui: path.resolve(
|
||||
__dirname,
|
||||
'../fixtures/config-js',
|
||||
'./components',
|
||||
),
|
||||
utils: path.resolve(__dirname, '../fixtures/config-js', './lib/utils'),
|
||||
},
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
import path from 'node:path'
|
||||
import { expect, test } from 'vitest'
|
||||
|
||||
import { getPackageManager } from '../../src/utils/get-package-manager'
|
||||
|
||||
test('get package manager', async () => {
|
||||
expect(
|
||||
await getPackageManager(path.resolve(__dirname, '../fixtures/project-yarn')),
|
||||
).toBe('yarn')
|
||||
|
||||
expect(
|
||||
await getPackageManager(path.resolve(__dirname, '../fixtures/project-npm')),
|
||||
).toBe('npm')
|
||||
|
||||
expect(
|
||||
await getPackageManager(path.resolve(__dirname, '../fixtures/project-pnpm')),
|
||||
).toBe('pnpm')
|
||||
|
||||
expect(
|
||||
await getPackageManager(path.resolve(__dirname, '../fixtures/project-bun')),
|
||||
).toBe('bun')
|
||||
|
||||
expect(
|
||||
await getPackageManager(path.resolve(__dirname, '../fixtures/next')),
|
||||
).toBe('pnpm')
|
||||
})
|
||||
Loading…
Reference in New Issue
Block a user