purvex-ui 1.0.3 → 1.0.4

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 +79 -32
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "purvex-ui",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "React component generator with Tailwind CSS v4 & Purple Elegant theme",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -4,77 +4,124 @@ 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. 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');
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
+ ];
13
16
 
14
- if (!fs.existsSync(registryPath)) {
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
+ }
25
+
26
+ if (!registryPath) {
15
27
  console.log(chalk.red('āŒ Registry not found'));
28
+ console.log(chalk.yellow('\\nAvailable components:'));
29
+ console.log(chalk.cyan(' • button'));
30
+ console.log(chalk.cyan(' • card'));
31
+ console.log(chalk.cyan(' • avatar'));
16
32
  return;
17
33
  }
18
34
 
35
+ // 2. Load registry
19
36
  const registryContent = fs.readFileSync(registryPath, 'utf-8');
20
37
  const registry = JSON.parse(registryContent);
21
38
 
22
- // 2. Find component
39
+ // 3. Cari component
23
40
  const component = registry.components.find(c => c.name === componentName);
24
41
 
25
42
  if (!component) {
26
43
  console.log(chalk.red(`āŒ Component "${componentName}" not found`));
27
- console.log(chalk.yellow('\nAvailable components:'));
44
+ console.log(chalk.yellow('\\nAvailable components:'));
28
45
  registry.components.forEach(c => {
29
46
  console.log(chalk.cyan(` - ${c.name}`));
30
47
  });
31
48
  return;
32
49
  }
33
50
 
34
- // 3. Setup target directory INSIDE src
51
+ // 4. Buat target directory
35
52
  const userProjectRoot = process.cwd();
36
53
  const targetDir = path.join(userProjectRoot, 'src', 'components', 'ui');
37
54
 
38
- // Auto create directory jika belum ada
39
55
  if (!fs.existsSync(targetDir)) {
40
56
  fs.mkdirSync(targetDir, { recursive: true });
57
+ console.log(chalk.green(`āœ… Created: ${path.relative(userProjectRoot, targetDir)}`));
41
58
  }
42
59
 
43
- // 4. Copy template files
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
+ }
76
+
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
44
102
  for (const file of component.files) {
45
- const sourcePath = path.join(rootDir, 'templates', file);
103
+ const sourcePath = path.join(templatesDir, file);
46
104
  const targetPath = path.join(targetDir, path.basename(file));
47
105
 
48
106
  if (!fs.existsSync(sourcePath)) {
49
- console.log(chalk.yellow(`āš ļø Template ${file} not found, skipping...`));
107
+ console.log(chalk.yellow(\`āš ļø Template \${file} not found\`));
50
108
  continue;
51
109
  }
52
110
 
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
111
+ const content = fs.readFileSync(sourcePath, 'utf-8');
61
112
  fs.writeFileSync(targetPath, content);
62
113
 
63
- const relativePath = path.relative(userProjectRoot, targetPath);
64
- console.log(chalk.green('āœ… Created: ') + relativePath);
114
+ console.log(chalk.green(\`āœ… Created: \${path.relative(userProjectRoot, targetPath)}\`));
65
115
  }
66
116
 
67
- // 5. Success message
68
- console.log(chalk.green.bold(`\nšŸŽ‰ Component ${componentName} added successfully!`));
69
- console.log(chalk.white('\nUsage:'));
70
- 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:'));
73
- console.log(chalk.cyan(' npm run dev'));
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}";\`));
74
121
 
75
122
  } catch (error) {
76
- console.error(chalk.red('āŒ Error adding component:'), error.message);
123
+ console.error(chalk.red('āŒ Error:'), error.message);
77
124
  }
78
125
  }
79
126
 
80
- module.exports = { addComponent };
127
+ module.exports = { addComponent };