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.
- package/package.json +1 -1
- package/src/commands/add.js +90 -53
package/package.json
CHANGED
package/src/commands/add.js
CHANGED
|
@@ -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
|
-
//
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
26
|
-
|
|
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
|
-
|
|
29
|
-
|
|
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
|
-
//
|
|
35
|
-
const
|
|
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
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
//
|
|
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
|
|
113
|
+
console.error(chalk.red('ā Error:'), error.message);
|
|
77
114
|
}
|
|
78
115
|
}
|
|
79
116
|
|
|
80
|
-
module.exports = { addComponent };
|
|
117
|
+
module.exports = { addComponent };
|