saqlain-ui 1.0.0 → 1.0.1

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.mjs +39 -31
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -1,54 +1,62 @@
1
1
  #!/usr/bin/env node
2
2
  import fs from 'fs';
3
3
  import path from 'path';
4
- import { execSync } from 'child_process';
5
- let componentName = process.argv[2];
6
4
 
7
- // If the user typed "add", grab the next word instead!
8
- if (componentName === "add") {
9
- componentName = process.argv[3];
10
- }
5
+ // Read what the user types in the terminal
6
+ const args = process.argv.slice(2);
7
+ const command = args[0];
8
+ const componentName = args[1];
11
9
 
12
- if (!componentName) {
13
- console.error("❌ Please provide a component name. Example: my-ui add button");
10
+ if (command !== 'add' || !componentName) {
11
+ console.error("❌ Usage: npx saqlain-ui add <component-name>");
14
12
  process.exit(1);
15
13
  }
16
- const REGISTRY_URL = `https://my-ui-library-vpgx.vercel.app/registry/${componentName}.json`;
17
- const OUTPUT_DIR = './components/ui';
18
14
 
19
- async function addComponent() {
20
- try {
21
- console.log(`⏳ Fetching '${componentName}' from registry...`);
15
+ // The URL to your new alias dictionary
16
+ const INDEX_URL = 'https://my-ui-library-vpgx.vercel.app/registry/index.json';
17
+ const OUTPUT_DIR = path.join(process.cwd(), 'components/ui');
22
18
 
23
- const response = await fetch(REGISTRY_URL);
24
-
25
- if (!response.ok) {
26
- throw new Error(`Component '${componentName}' not found. Is your dev server running?`);
19
+ async function fetchComponent() {
20
+ try {
21
+ process.stdout.write(`🔍 Searching for '${componentName}'... `);
22
+
23
+ // 1. Fetch the master index file first
24
+ const indexResponse = await fetch(INDEX_URL);
25
+ if (!indexResponse.ok) throw new Error("Failed to reach the registry.");
26
+ const masterIndex = await indexResponse.json();
27
+
28
+ // 2. Check if the component exists in our alias dictionary!
29
+ if (!masterIndex[componentName]) {
30
+ console.log(`❌ Not found.`);
31
+ console.log(`\nOops! '${componentName}' doesn't exist in the registry.`);
32
+ console.log(`👉 Available components: ${Object.keys(masterIndex).join(', ')}\n`);
33
+ process.exit(1);
27
34
  }
28
35
 
29
- const componentData = await response.json();
36
+ console.log(`Found!`);
37
+ console.log(`⏳ Downloading '${componentName}'...`);
30
38
 
31
- // Check for and install NPM dependencies
32
- if (componentData.dependencies && componentData.dependencies.length > 0) {
33
- console.log(`📦 Installing dependencies: ${componentData.dependencies.join(', ')}...`);
34
- execSync(`npm install ${componentData.dependencies.join(' ')} --legacy-peer-deps`, { stdio: 'inherit' });
35
- }
39
+ // 3. It exists! Fetch the exact URL from our dictionary
40
+ const componentInfo = masterIndex[componentName];
41
+ const componentResponse = await fetch(componentInfo.downloadUrl);
42
+
43
+ if (!componentResponse.ok) throw new Error("Failed to download the component data.");
44
+ const componentData = await componentResponse.json();
36
45
 
46
+ // 4. Save it to the user's project
37
47
  if (!fs.existsSync(OUTPUT_DIR)) {
38
48
  fs.mkdirSync(OUTPUT_DIR, { recursive: true });
39
49
  }
40
50
 
41
- componentData.files.forEach(file => {
42
- const filePath = path.join(OUTPUT_DIR, file.name);
43
- fs.writeFileSync(filePath, file.content);
44
- console.log(`✅ Successfully installed ${file.name} into ${OUTPUT_DIR}/`);
45
- });
51
+ const fileInfo = componentData.files[0];
52
+ const filePath = path.join(OUTPUT_DIR, fileInfo.name);
46
53
 
47
- console.log(`🎉 Component '${componentName}' is ready to use!`);
54
+ fs.writeFileSync(filePath, fileInfo.content);
55
+ console.log(`✅ Successfully installed ${fileInfo.name} into ./components/ui/`);
48
56
 
49
57
  } catch (error) {
50
- console.error("❌ Error:", error.message);
58
+ console.error(`\n❌ Error: ${error.message}\n`);
51
59
  }
52
60
  }
53
61
 
54
- addComponent();
62
+ fetchComponent();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saqlain-ui",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "A beautifully crafted UI component library",
5
5
  "main": "index.mjs",
6
6
  "bin": {