purvex-ui 1.0.4 → 1.0.6

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "purvex-ui",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "React component generator with Tailwind CSS v4 & Purple Elegant theme",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -4,120 +4,110 @@ const chalk = require('chalk');
4
4
 
5
5
  async function addComponent(componentName, options) {
6
6
  try {
7
- console.log(chalk.blue.bold(`\\nšŸ”„ Adding ${componentName}...\\n`));
7
+ console.log(chalk.blue.bold(`\nšŸ”„ Adding ${componentName}...\n`));
8
8
 
9
- // 1. Cari registry file
10
- const possiblePaths = [
11
- path.join(__dirname, '..', 'registry', 'components.json'),
12
- path.join(__dirname, 'registry', 'components.json'),
13
- path.join(process.cwd(), 'node_modules', 'purvex-ui', 'registry', 'components.json'),
14
- path.join(process.cwd(), 'registry', 'components.json')
15
- ];
16
-
17
- let registryPath = null;
18
- for (const p of possiblePaths) {
19
- if (fs.existsSync(p)) {
20
- registryPath = p;
21
- console.log(chalk.gray(`Found registry at: ${p}`));
22
- break;
23
- }
24
- }
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
+ };
25
81
 
26
- if (!registryPath) {
27
- console.log(chalk.red('āŒ Registry not found'));
28
- console.log(chalk.yellow('\\nAvailable components:'));
82
+ // Check if component exists
83
+ if (!TEMPLATES[componentName]) {
84
+ console.log(chalk.red(`āŒ Component "${componentName}" not available`));
85
+ console.log(chalk.yellow('\nAvailable components:'));
29
86
  console.log(chalk.cyan(' • button'));
30
87
  console.log(chalk.cyan(' • card'));
31
88
  console.log(chalk.cyan(' • avatar'));
32
89
  return;
33
90
  }
34
91
 
35
- // 2. Load registry
36
- const registryContent = fs.readFileSync(registryPath, 'utf-8');
37
- const registry = JSON.parse(registryContent);
38
-
39
- // 3. Cari component
40
- const component = registry.components.find(c => c.name === componentName);
41
-
42
- if (!component) {
43
- console.log(chalk.red(`āŒ Component "${componentName}" not found`));
44
- console.log(chalk.yellow('\\nAvailable components:'));
45
- registry.components.forEach(c => {
46
- console.log(chalk.cyan(` - ${c.name}`));
47
- });
48
- return;
49
- }
50
-
51
- // 4. Buat target directory
52
- const userProjectRoot = process.cwd();
53
- const targetDir = path.join(userProjectRoot, 'src', 'components', 'ui');
54
-
92
+ // Create target directory
93
+ const targetDir = path.join(process.cwd(), 'src', 'components', 'ui');
55
94
  if (!fs.existsSync(targetDir)) {
56
95
  fs.mkdirSync(targetDir, { recursive: true });
57
- console.log(chalk.green(`āœ… Created: ${path.relative(userProjectRoot, targetDir)}`));
96
+ console.log(chalk.green(`āœ… Created directory: ${path.relative(process.cwd(), targetDir)}`));
58
97
  }
59
98
 
60
- // 5. Cari templates directory
61
- let templatesDir = null;
62
- const possibleTemplateDirs = [
63
- path.join(__dirname, '..', 'templates'),
64
- path.join(__dirname, 'templates'),
65
- path.join(process.cwd(), 'node_modules', 'purvex-ui', 'templates'),
66
- path.join(process.cwd(), 'templates')
67
- ];
68
-
69
- for (const dir of possibleTemplateDirs) {
70
- if (fs.existsSync(dir)) {
71
- templatesDir = dir;
72
- console.log(chalk.gray(`Found templates at: ${dir}`));
73
- break;
74
- }
75
- }
99
+ // Create component file
100
+ const filePath = path.join(targetDir, `${componentName}.jsx`);
101
+ fs.writeFileSync(filePath, TEMPLATES[componentName]);
76
102
 
77
- if (!templatesDir) {
78
- console.log(chalk.red('āŒ Templates directory not found'));
79
- console.log(chalk.yellow('Creating simple component file...'));
80
-
81
- // Fallback: buat file simple
82
- const componentContent = `import React from "react";
83
- import { cn } from "@/lib/utils";
84
-
85
- export const ${componentName.charAt(0).toUpperCase() + componentName.slice(1)} = ({ className, children, ...props }) => {
86
- return (
87
- <div className={cn("${componentName}", className)} {...props}>
88
- {children}
89
- </div>
90
- );
91
- };`;
92
-
93
- const targetPath = path.join(targetDir, \`\${componentName}.jsx\`);
94
- fs.writeFileSync(targetPath, componentContent);
95
-
96
- console.log(chalk.green(\`āœ… Created: \${path.relative(userProjectRoot, targetPath)}\`));
97
- console.log(chalk.green.bold(\`\\nšŸŽ‰ Component ${componentName} added!\`));
98
- return;
99
- }
100
-
101
- // 6. Copy template files
102
- for (const file of component.files) {
103
- const sourcePath = path.join(templatesDir, file);
104
- const targetPath = path.join(targetDir, path.basename(file));
105
-
106
- if (!fs.existsSync(sourcePath)) {
107
- console.log(chalk.yellow(\`āš ļø Template \${file} not found\`));
108
- continue;
109
- }
110
-
111
- const content = fs.readFileSync(sourcePath, 'utf-8');
112
- fs.writeFileSync(targetPath, content);
113
-
114
- console.log(chalk.green(\`āœ… Created: \${path.relative(userProjectRoot, targetPath)}\`));
115
- }
103
+ console.log(chalk.green(`āœ… Created: ${path.relative(process.cwd(), filePath)}`));
116
104
 
117
- // 7. Success message
118
- console.log(chalk.green.bold(\`\\nšŸŽ‰ Component \${componentName} added successfully!\`));
119
- console.log(chalk.white('\\nUsage:'));
120
- console.log(chalk.cyan(\` import { \${componentName.charAt(0).toUpperCase() + componentName.slice(1)} } from "@/components/ui/\${componentName}";\`));
105
+ // Success message
106
+ console.log(chalk.green.bold(`\nšŸŽ‰ Component ${componentName} added successfully!`));
107
+ console.log(chalk.white('\nUsage:'));
108
+ console.log(chalk.cyan(` import { ${componentName.charAt(0).toUpperCase() + componentName.slice(1)} } from "@/components/ui/${componentName}";`));
109
+ console.log(chalk.white('\nStart dev server:'));
110
+ console.log(chalk.cyan(' npm run dev'));
121
111
 
122
112
  } catch (error) {
123
113
  console.error(chalk.red('āŒ Error:'), error.message);
@@ -115,7 +115,7 @@ export default defineConfig({
115
115
  configContent = configContent.replace(
116
116
  /plugins:\s*\[([\s\S]*?)\]/,
117
117
  `plugins: [
118
- $1\n tailwindcss(),`
118
+ ,$1\n tailwindcss(),]`
119
119
  );
120
120
  // Tutup bracket dengan benar
121
121
  configContent = configContent.replace(/tailwindcss\(\),\s*$/, 'tailwindcss(),\n ]');