dimaac 1.0.1 → 1.0.2

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/index.js +148 -77
  2. package/package.json +6 -6
package/index.js CHANGED
@@ -5,30 +5,13 @@ const fs = require('fs');
5
5
  const path = require('path');
6
6
  const https = require('https');
7
7
 
8
- const GITHUB_RAW_BASE = 'https://raw.githubusercontent.com/Hank-D-Tank/dimaac-ui/main';
8
+ const API_BASE = 'https://ui.dimaac.com/api';
9
+ const REGISTRY_URL = `${API_BASE}/components`;
9
10
 
10
11
  program
11
12
  .name('dimaac')
12
13
  .description('Add DiMaac UI components to your projects')
13
- .version('1.0.1');
14
-
15
- const componentCategories = {
16
- 'reveals': ['TextScrambleReveal', 'LiquidImageReveal'],
17
- 'cards': ['MouseTiltCard', 'SwipeableCards'],
18
- 'interactive': ['MouseTrail', 'ContextMenu'],
19
- 'gallery': ['ScrollingGallery', 'ImageGallery'],
20
- 'loaders': ['TextLoader'],
21
- 'layout': ['ExpandablePanel']
22
- };
23
-
24
- const exampleCategories = {
25
- 'reveals': ['TextScrambleRevealDemo', 'LiquidImageRevealDemo'],
26
- 'cards': ['MouseTiltCardDemo', 'SwipeableCardsDemo'],
27
- 'interactive': ['MouseTrailDemo', 'ContextMenuDemo'],
28
- 'gallery': ['ScrollingGalleryDemo', 'ImageGalleryDemo'],
29
- 'loaders': ['TextLoaderDemo'],
30
- 'layout': ['ExpandablePanelDemo']
31
- };
14
+ .version('1.0.2');
32
15
 
33
16
  function ensureDirectoryExists(dirPath) {
34
17
  if (!fs.existsSync(dirPath)) {
@@ -53,55 +36,121 @@ function downloadFile(url, destination) {
53
36
  });
54
37
  }
55
38
 
56
- async function installComponent(componentName, includeExample = false) {
57
- let category = null;
58
- let actualComponentName = null;
59
-
60
- for (const [cat, components] of Object.entries(componentCategories)) {
61
- if (components.includes(componentName)) {
62
- category = cat;
63
- actualComponentName = componentName;
64
- break;
65
- }
39
+ function fetchRegistry() {
40
+ return new Promise((resolve, reject) => {
41
+ https.get(REGISTRY_URL, (response) => {
42
+ let data = '';
43
+
44
+ response.on('data', (chunk) => {
45
+ data += chunk;
46
+ });
47
+
48
+ response.on('end', () => {
49
+ try {
50
+ const registry = JSON.parse(data);
51
+ if (registry.success) {
52
+ resolve(registry.components);
53
+ } else {
54
+ reject(new Error('Failed to fetch component registry'));
55
+ }
56
+ } catch (error) {
57
+ reject(new Error('Invalid registry response'));
58
+ }
59
+ });
60
+ }).on('error', reject);
61
+ });
62
+ }
63
+
64
+ // Convert slug (post-swiper) to PascalCase (PostSwiper) for matching
65
+ function slugToPascal(slug) {
66
+ if (!slug || typeof slug !== 'string') return slug;
67
+ return slug
68
+ .split(/[-_\s]+/)
69
+ .map(part => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase())
70
+ .join('');
71
+ }
72
+
73
+ async function findComponent(componentName, registry) {
74
+ if (!componentName) return null;
75
+
76
+ // Try exact match first
77
+ for (const [category, components] of Object.entries(registry)) {
78
+ const component = components.find(comp => comp.name === componentName);
79
+ if (component) return { category, component };
66
80
  }
67
81
 
68
- if (!category) {
69
- console.error(`Component "${componentName}" not found.`);
70
- console.log('Available components:');
71
- Object.entries(componentCategories).forEach(([cat, components]) => {
72
- console.log(` ${cat}:`);
73
- components.forEach(comp => console.log(` - ${comp}`));
74
- });
75
- return;
82
+ // Try case-insensitive match
83
+ const nameLower = componentName.toLowerCase();
84
+ for (const [category, components] of Object.entries(registry)) {
85
+ const component = components.find(
86
+ comp => comp.name.toLowerCase() === nameLower
87
+ );
88
+ if (component) return { category, component };
76
89
  }
77
90
 
78
- const componentDir = path.join(process.cwd(), 'components', category);
79
- ensureDirectoryExists(componentDir);
91
+ // Try slug-to-PascalCase (e.g. post-swiper -> PostSwiper)
92
+ const pascalName = slugToPascal(componentName);
93
+ if (pascalName !== componentName) {
94
+ for (const [category, components] of Object.entries(registry)) {
95
+ const component = components.find(comp => comp.name === pascalName);
96
+ if (component) return { category, component };
97
+ }
98
+ }
80
99
 
81
- const sourceUrl = `${GITHUB_RAW_BASE}/src/ui/components/${category}/${actualComponentName}.tsx`;
82
- const destination = path.join(componentDir, `${actualComponentName}.tsx`);
100
+ return null;
101
+ }
83
102
 
103
+ async function installComponent(componentName, includeExample = false) {
84
104
  try {
85
- await downloadFile(sourceUrl, destination);
86
- console.log(`āœ… Successfully installed ${actualComponentName} to components/${category}/`);
105
+ console.log('šŸ“¦ Fetching latest component registry...');
106
+ const registry = await fetchRegistry();
107
+
108
+ const result = await findComponent(componentName, registry);
109
+
110
+ if (!result) {
111
+ console.error(`Component "${componentName}" not found.`);
112
+ console.log('\nšŸ“¦ Available components:');
113
+ Object.entries(registry).forEach(([category, components]) => {
114
+ console.log(`\n ${category.toUpperCase()}:`);
115
+ components.forEach(comp => console.log(` - ${comp.name} (${comp.description})`));
116
+ });
117
+ return;
118
+ }
87
119
 
88
- if (includeExample) {
89
- const exampleName = `${actualComponentName}Demo`;
90
- const exampleDir = path.join(process.cwd(), 'examples', category);
120
+ const { category, component } = result;
121
+ const componentDir = path.join(process.cwd(), 'ui', 'components');
122
+ ensureDirectoryExists(componentDir);
123
+
124
+ const destination = path.join(componentDir, `${component.name}.tsx`);
125
+
126
+ console.log(`ā¬‡ļø Downloading ${component.name}...`);
127
+ await downloadFile(component.sourceUrl, destination);
128
+ console.log(`āœ… Successfully installed ${component.name} to ui/components/`);
129
+
130
+ if (includeExample && component.exampleUrl) {
131
+ const exampleDir = path.join(process.cwd(), 'examples');
91
132
  ensureDirectoryExists(exampleDir);
92
133
 
93
- const exampleUrl = `${GITHUB_RAW_BASE}/src/examples/components/${category}/${exampleName}.tsx`;
94
- const exampleDestination = path.join(exampleDir, `${exampleName}.tsx`);
134
+ const exampleDestination = path.join(exampleDir, `${component.name}Demo.tsx`);
95
135
 
96
136
  try {
97
- await downloadFile(exampleUrl, exampleDestination);
98
- console.log(`āœ… Successfully installed ${exampleName} to examples/${category}/`);
137
+ console.log(`ā¬‡ļø Downloading example...`);
138
+ await downloadFile(component.exampleUrl, exampleDestination);
139
+ console.log(`āœ… Successfully installed ${component.name}Demo to examples/`);
99
140
  } catch (error) {
100
- console.log(`āš ļø Example not found for ${actualComponentName}`);
141
+ console.log(`āš ļø Example not found for ${component.name}`);
101
142
  }
102
143
  }
144
+
145
+ if (component.dependencies && component.dependencies.length > 0) {
146
+ console.log(`\nšŸ“‹ Required dependencies:`);
147
+ component.dependencies.forEach(dep => console.log(` - ${dep}`));
148
+ console.log(`\nInstall with: npm install ${component.dependencies.join(' ')}`);
149
+ }
150
+
103
151
  } catch (error) {
104
- console.error(`āŒ Failed to install ${actualComponentName}:`, error.message);
152
+ console.error(`āŒ Failed to install ${componentName}:`, error.message);
153
+ console.log('\nšŸ’” Make sure you have an internet connection and try again.');
105
154
  }
106
155
  }
107
156
 
@@ -110,11 +159,12 @@ program
110
159
  .description('Initialize DiMaac UI in your project')
111
160
  .action(async () => {
112
161
  console.log('šŸš€ Initializing DiMaac UI...');
113
-
114
- const componentsDir = path.join(process.cwd(), 'components');
162
+
163
+ const uiDir = path.join(process.cwd(), 'ui');
164
+ const componentsDir = path.join(process.cwd(), 'ui', 'components');
115
165
  ensureDirectoryExists(componentsDir);
116
-
117
- console.log('āœ… Created components directory');
166
+
167
+ console.log('āœ… Created ui/components directory');
118
168
  console.log('šŸ“¦ DiMaac UI initialized successfully!');
119
169
  console.log('\nNext steps:');
120
170
  console.log(' npx dimaac add [component]');
@@ -130,24 +180,38 @@ program
130
180
  .option('--all', 'Install all components')
131
181
  .action(async (component, options) => {
132
182
  if (options.all) {
133
- console.log('Installing all components...');
134
- for (const [category, components] of Object.entries(componentCategories)) {
135
- for (const comp of components) {
136
- await installComponent(comp, options.example);
183
+ try {
184
+ console.log('šŸ“¦ Fetching latest component registry...');
185
+ const registry = await fetchRegistry();
186
+
187
+ console.log('Installing all components...');
188
+ for (const [category, components] of Object.entries(registry)) {
189
+ for (const comp of components) {
190
+ await installComponent(comp.name, options.example);
191
+ }
137
192
  }
193
+ } catch (error) {
194
+ console.error('āŒ Failed to fetch component registry:', error.message);
138
195
  }
139
196
  return;
140
197
  }
141
198
 
142
199
  if (!component) {
143
- console.log('\nšŸ“¦ Available Components:');
144
- Object.entries(componentCategories).forEach(([category, components]) => {
145
- console.log(`\n ${category.toUpperCase()}:`);
146
- components.forEach(comp => console.log(` - ${comp}`));
147
- });
148
- console.log('\nUsage: npx dimaac add [component]');
149
- console.log('Example: npx dimaac add MouseTiltCard');
150
- console.log('Add -e flag to include example: npx dimaac add MouseTiltCard -e');
200
+ try {
201
+ console.log('šŸ“¦ Fetching latest component registry...');
202
+ const registry = await fetchRegistry();
203
+
204
+ console.log('\nšŸ“¦ Available Components:');
205
+ Object.entries(registry).forEach(([category, components]) => {
206
+ console.log(`\n ${category.toUpperCase()}:`);
207
+ components.forEach(comp => console.log(` - ${comp.name} (${comp.description})`));
208
+ });
209
+ console.log('\nUsage: npx dimaac add [component]');
210
+ console.log('Example: npx dimaac add MouseTiltCard');
211
+ console.log('Add -e flag to include example: npx dimaac add MouseTiltCard -e');
212
+ } catch (error) {
213
+ console.error('āŒ Failed to fetch component registry:', error.message);
214
+ }
151
215
  return;
152
216
  }
153
217
 
@@ -157,14 +221,21 @@ program
157
221
  program
158
222
  .command('list')
159
223
  .description('List all available components')
160
- .action(() => {
161
- console.log('\nšŸ“¦ Available Components:');
162
- Object.entries(componentCategories).forEach(([category, components]) => {
163
- console.log(`\n ${category.toUpperCase()}:`);
164
- components.forEach(comp => console.log(` - ${comp}`));
165
- });
166
- console.log('\nUsage: npx dimaac add [component] [-e]');
167
- console.log('Add -e flag to include example/demo files');
224
+ .action(async () => {
225
+ try {
226
+ console.log('šŸ“¦ Fetching latest component registry...');
227
+ const registry = await fetchRegistry();
228
+
229
+ console.log('\nšŸ“¦ Available Components:');
230
+ Object.entries(registry).forEach(([category, components]) => {
231
+ console.log(`\n ${category.toUpperCase()}:`);
232
+ components.forEach(comp => console.log(` - ${comp.name} (${comp.description})`));
233
+ });
234
+ console.log('\nUsage: npx dimaac add [component] [-e]');
235
+ console.log('Add -e flag to include example/demo files');
236
+ } catch (error) {
237
+ console.error('āŒ Failed to fetch component registry:', error.message);
238
+ }
168
239
  });
169
240
 
170
241
  program.parse();
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "dimaac",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Add DiMaac UI components to your projects",
5
5
  "main": "index.js",
6
6
  "bin": {
7
- "dimaac": "./index.js"
7
+ "dimaac": "index.js"
8
8
  },
9
9
  "scripts": {
10
10
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -27,10 +27,10 @@
27
27
  },
28
28
  "repository": {
29
29
  "type": "git",
30
- "url": "https://github.com/your-username/dimaac-ui.git"
30
+ "url": "git+https://github.com/DimaacUI/DiMaac-UI.git"
31
31
  },
32
32
  "bugs": {
33
- "url": "https://github.com/your-username/dimaac-ui/issues"
33
+ "url": "https://github.com/DimaacUI/DiMaac-UI/issues"
34
34
  },
35
- "homepage": "https://github.com/your-username/dimaac-ui#readme"
36
- }
35
+ "homepage": "https://github.com/DimaacUI/DiMaac-UI#readme"
36
+ }