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.
- package/index.mjs +39 -31
- 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
|
-
//
|
|
8
|
-
|
|
9
|
-
|
|
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("❌
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
36
|
+
console.log(`Found!`);
|
|
37
|
+
console.log(`⏳ Downloading '${componentName}'...`);
|
|
30
38
|
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
|
42
|
-
|
|
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
|
-
|
|
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(
|
|
58
|
+
console.error(`\n❌ Error: ${error.message}\n`);
|
|
51
59
|
}
|
|
52
60
|
}
|
|
53
61
|
|
|
54
|
-
|
|
62
|
+
fetchComponent();
|