purvex-ui 1.0.4 ā 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 -100
package/package.json
CHANGED
package/src/commands/add.js
CHANGED
|
@@ -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(
|
|
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
|
-
|
|
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
|
|
27
|
-
|
|
28
|
-
console.log(chalk.
|
|
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
|
-
//
|
|
36
|
-
const
|
|
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(
|
|
96
|
+
console.log(chalk.green(`ā
Created directory: ${path.relative(process.cwd(), targetDir)}`));
|
|
58
97
|
}
|
|
59
98
|
|
|
60
|
-
//
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
118
|
-
console.log(chalk.green.bold(
|
|
119
|
-
console.log(chalk.white('
|
|
120
|
-
console.log(chalk.cyan(
|
|
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);
|