-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·106 lines (86 loc) · 3.7 KB
/
Copy pathcli.js
File metadata and controls
executable file
·106 lines (86 loc) · 3.7 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env node
import { program } from 'commander';
import fs from 'fs-extra';
import path from 'path';
import { fileURLToPath } from 'url';
import ora from 'ora';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const componentFiles = [
{ name: 'navbar.tsx', required: true },
{ name: 'navbar-user.tsx', required: false, option: 'withUserDropdown' },
{ name: 'navbar-search.tsx', required: false, option: 'withSearch' },
];
const dependencies = {
'--with-user-dropdown': ['@radix-ui/react-dropdown-menu'],
'--with-search': ['@radix-ui/react-dialog'],
};
program
.name('add-navbar')
.description('Add the enhanced navbar component to your project')
.option('-d, --dir <path>', 'Installation directory for the component', 'components/navbar')
.option('--with-user-dropdown', 'Include the NavbarUser component (requires @radix-ui/react-dropdown-menu)', false)
.option('--with-search', 'Include the NavbarSearch component (Command Palette, requires @radix-ui/react-dialog)', false)
.action(async (options) => {
const { dir, withUserDropdown, withSearch } = options;
const targetDir = path.join(process.cwd(), dir);
const spinner = ora(`Installing navbar component(s) to ${dir}...`).start();
try {
// 1. Ensure target directory exists
await fs.ensureDir(targetDir);
// 2. Copy component files
const filesToCopy = componentFiles.filter(file =>
file.required ||
(file.option === 'withUserDropdown' && withUserDropdown) ||
(file.option === 'withSearch' && withSearch)
);
for (const file of filesToCopy) {
const sourcePath = path.join(__dirname, 'src', 'components', file.name);
const targetPath = path.join(targetDir, file.name);
await fs.copy(sourcePath, targetPath);
}
// 3. Create utils file if it doesn't exist
const utilsDir = path.join(process.cwd(), 'lib');
const utilsFile = path.join(utilsDir, 'utils.ts');
if (!await fs.pathExists(utilsFile)) {
await fs.ensureDir(utilsDir);
await fs.writeFile(utilsFile, `
import { type ClassValue, clsx } from "clsx"
import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
`);
}
spinner.succeed('Navbar component(s) installed successfully!');
console.log('\n--- Next Steps ---');
console.log(`1. Import the main component:`);
console.log(` import { Navbar, NavbarMobile, NavbarContent } from "${dir}/navbar"`);
if (withUserDropdown) {
console.log(`2. You included NavbarUser. Import it:`);
console.log(` import { NavbarUser, NavbarUserItem } from "${dir}/navbar-user"`);
}
if (withSearch) {
console.log(`3. You included NavbarSearch. Import it:`);
console.log(` import { NavbarSearch } from "${dir}/navbar-search"`);
}
// 4. Dependency check and suggestion
const requiredDeps = [];
if (withUserDropdown) requiredDeps.push(...dependencies['--with-user-dropdown']);
if (withSearch) requiredDeps.push(...dependencies['--with-search']);
if (requiredDeps.length > 0) {
console.log('\n4. Make sure you have the following Radix UI dependencies installed:');
console.log(` npm install ${requiredDeps.join(' ')}`);
}
console.log('\n5. Ensure your tailwind.config.js includes the component path:');
console.log(` content: [
// ...
'./${dir}/**/*.{js,ts,jsx,tsx}'
]`);
} catch (error) {
spinner.fail('Error installing navbar component(s).');
console.error('Details:', error.message);
process.exit(1);
}
});
program.parse(process.argv);