-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.ts
More file actions
70 lines (57 loc) · 2.12 KB
/
init.ts
File metadata and controls
70 lines (57 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import fs from 'fs-extra'
import path from 'path'
import ora from 'ora'
import chalk from 'chalk'
export async function initProject(_options: { yes?: boolean } = {}) {
const spinner = ora('Initializing Cvians UI project...').start()
try {
// Check if package.json exists
const packageJsonPath = path.join(process.cwd(), 'package.json')
const hasPackageJson = await fs.pathExists(packageJsonPath)
if (!hasPackageJson) {
spinner.fail(chalk.red('No package.json found. Please run this command in a valid Node.js project.'))
return
}
// Create necessary directories
const componentsDir = path.join(process.cwd(), 'components', 'ui')
const libDir = path.join(process.cwd(), 'lib')
await fs.ensureDir(componentsDir)
await fs.ensureDir(libDir)
// Create utils file
const utilsContent = `import { type ClassValue, clsx } from 'clsx'
import { twMerge } from 'tailwind-merge'
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}`
await fs.writeFile(path.join(libDir, 'utils.ts'), utilsContent)
// Create components.json config
const componentsConfig = {
"$schema": "https://ui.shadcn.com/schema.json",
"style": "default",
"rsc": false,
"tsx": true,
"tailwind": {
"config": "tailwind.config.js",
"css": "app/globals.css",
"baseColor": "slate",
"cssVariables": true
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils"
}
}
await fs.writeFile(
path.join(process.cwd(), 'components.json'),
JSON.stringify(componentsConfig, null, 2)
)
spinner.succeed(chalk.green('Cvians UI initialized successfully!'))
console.log(chalk.blue('\\nNext steps:'))
console.log(chalk.gray('1. Install dependencies: npm install clsx tailwind-merge'))
console.log(chalk.gray('2. Set up Tailwind CSS if not already configured'))
console.log(chalk.gray('3. Add components: cvians add excel-table'))
} catch (error) {
spinner.fail(chalk.red('Failed to initialize Cvians UI project'))
console.error(error)
}
}