purvex-ui 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/commands/add.js +90 -53
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "purvex-ui",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "React component generator with Tailwind CSS v4 & Purple Elegant theme",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -6,75 +6,112 @@ async function addComponent(componentName, options) {
6
6
  try {
7
7
  console.log(chalk.blue.bold(`\nšŸ”„ Adding ${componentName}...\n`));
8
8
 
9
- // 1. Load registry
10
- const cliDir = path.dirname(path.dirname(__dirname));
11
- const rootDir = path.dirname(path.dirname(cliDir));
12
- const registryPath = path.join(rootDir, 'registry', 'components.json');
13
-
14
- if (!fs.existsSync(registryPath)) {
15
- console.log(chalk.red('āŒ Registry not found'));
16
- return;
17
- }
18
-
19
- const registryContent = fs.readFileSync(registryPath, 'utf-8');
20
- const registry = JSON.parse(registryContent);
21
-
22
- // 2. Find component
23
- const component = registry.components.find(c => c.name === componentName);
9
+ // Simple template dalam code
10
+ const TEMPLATES = {
11
+ button: `import React from "react";
12
+ import { cn } from "@/lib/utils";
13
+
14
+ const Button = React.forwardRef(function Button(
15
+ { className, variant = "default", size = "default", children, ...props },
16
+ ref
17
+ ) {
18
+ return (
19
+ <button
20
+ className={cn(
21
+ "inline-flex items-center justify-center rounded-lg px-5 py-2",
22
+ "bg-primary text-primary-foreground hover:bg-primary/90",
23
+ "font-bold text-sm transition-all",
24
+ className
25
+ )}
26
+ ref={ref}
27
+ {...props}
28
+ >
29
+ {children}
30
+ </button>
31
+ );
32
+ });
33
+
34
+ Button.displayName = "Button";
35
+
36
+ export { Button };`,
37
+
38
+ card: `import React from 'react';
39
+ import { cn } from '@/lib/utils';
40
+
41
+ const Card = React.forwardRef(function Card({ className, ...props }, ref) {
42
+ return (
43
+ <div
44
+ ref={ref}
45
+ className={cn("rounded-2xl border bg-card p-6", className)}
46
+ {...props}
47
+ />
48
+ );
49
+ });
50
+
51
+ Card.displayName = "Card";
52
+
53
+ export { Card };`,
54
+
55
+ avatar: `import React from 'react';
56
+ import { cn } from '@/lib/utils';
57
+
58
+ const Avatar = React.forwardRef(function Avatar({
59
+ src,
60
+ alt = "avatar",
61
+ size = 72,
62
+ className,
63
+ ...props
64
+ }, ref) {
65
+ return (
66
+ <div
67
+ ref={ref}
68
+ className={cn("rounded-full overflow-hidden shrink-0", className)}
69
+ style={{ width: \`\${size}px\`, height: \`\${size}px\` }}
70
+ {...props}
71
+ >
72
+ <img src={src} alt={alt} className="w-full h-full object-cover" />
73
+ </div>
74
+ );
75
+ });
76
+
77
+ Avatar.displayName = "Avatar";
78
+
79
+ export { Avatar };`
80
+ };
24
81
 
25
- if (!component) {
26
- console.log(chalk.red(`āŒ Component "${componentName}" not found`));
82
+ // Check if component exists
83
+ if (!TEMPLATES[componentName]) {
84
+ console.log(chalk.red(`āŒ Component "${componentName}" not available`));
27
85
  console.log(chalk.yellow('\nAvailable components:'));
28
- registry.components.forEach(c => {
29
- console.log(chalk.cyan(` - ${c.name}`));
30
- });
86
+ console.log(chalk.cyan(' • button'));
87
+ console.log(chalk.cyan(' • card'));
88
+ console.log(chalk.cyan(' • avatar'));
31
89
  return;
32
90
  }
33
91
 
34
- // 3. Setup target directory INSIDE src
35
- const userProjectRoot = process.cwd();
36
- const targetDir = path.join(userProjectRoot, 'src', 'components', 'ui');
37
-
38
- // Auto create directory jika belum ada
92
+ // Create target directory
93
+ const targetDir = path.join(process.cwd(), 'src', 'components', 'ui');
39
94
  if (!fs.existsSync(targetDir)) {
40
95
  fs.mkdirSync(targetDir, { recursive: true });
96
+ console.log(chalk.green(`āœ… Created directory: ${path.relative(process.cwd(), targetDir)}`));
41
97
  }
42
98
 
43
- // 4. Copy template files
44
- for (const file of component.files) {
45
- const sourcePath = path.join(rootDir, 'templates', file);
46
- const targetPath = path.join(targetDir, path.basename(file));
47
-
48
- if (!fs.existsSync(sourcePath)) {
49
- console.log(chalk.yellow(`āš ļø Template ${file} not found, skipping...`));
50
- continue;
51
- }
52
-
53
- // Read template
54
- let content = fs.readFileSync(sourcePath, 'utf-8');
55
-
56
- // Update import path untuk src/
57
- content = content.replace(/@\/lib\/utils/g, '@/lib/utils');
58
- content = content.replace(/@\/components\/ui/g, '@/components/ui');
59
-
60
- // Write to target
61
- fs.writeFileSync(targetPath, content);
62
-
63
- const relativePath = path.relative(userProjectRoot, targetPath);
64
- console.log(chalk.green('āœ… Created: ') + relativePath);
65
- }
99
+ // Create component file
100
+ const filePath = path.join(targetDir, `${componentName}.jsx`);
101
+ fs.writeFileSync(filePath, TEMPLATES[componentName]);
102
+
103
+ console.log(chalk.green(`āœ… Created: ${path.relative(process.cwd(), filePath)}`));
66
104
 
67
- // 5. Success message
105
+ // Success message
68
106
  console.log(chalk.green.bold(`\nšŸŽ‰ Component ${componentName} added successfully!`));
69
107
  console.log(chalk.white('\nUsage:'));
70
108
  console.log(chalk.cyan(` import { ${componentName.charAt(0).toUpperCase() + componentName.slice(1)} } from "@/components/ui/${componentName}";`));
71
-
72
- console.log(chalk.white('\nStart your dev server:'));
109
+ console.log(chalk.white('\nStart dev server:'));
73
110
  console.log(chalk.cyan(' npm run dev'));
74
111
 
75
112
  } catch (error) {
76
- console.error(chalk.red('āŒ Error adding component:'), error.message);
113
+ console.error(chalk.red('āŒ Error:'), error.message);
77
114
  }
78
115
  }
79
116
 
80
- module.exports = { addComponent };
117
+ module.exports = { addComponent };