viora-ui 1.0.7 → 1.0.9
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/cli.js +46 -9
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const { program } = require('commander');
|
|
4
4
|
const { execSync } = require('child_process');
|
|
5
5
|
|
|
6
|
-
const REGISTRY_URL = 'https://vioraui.dedyn.io/registry';
|
|
6
|
+
const REGISTRY_URL = 'https://www.vioraui.dedyn.io/registry';
|
|
7
7
|
|
|
8
8
|
program
|
|
9
9
|
.name('viora-ui')
|
|
@@ -22,15 +22,52 @@ program
|
|
|
22
22
|
console.log(`\x1b[36mAdding ${component} from Viora UI...\x1b[0m\n`);
|
|
23
23
|
|
|
24
24
|
const url = `${REGISTRY_URL}/${component}.json`;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
const https = require('https');
|
|
26
|
+
const fs = require('fs');
|
|
27
|
+
const path = require('path');
|
|
28
|
+
|
|
29
|
+
https.get(url, (res) => {
|
|
30
|
+
if (res.statusCode !== 200) {
|
|
31
|
+
console.error(`\x1b[31mFailed to find ${component} at registry. Component might not exist.\x1b[0m`);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let data = '';
|
|
36
|
+
res.on('data', chunk => data += chunk);
|
|
37
|
+
res.on('end', () => {
|
|
38
|
+
try {
|
|
39
|
+
const json = JSON.parse(data);
|
|
40
|
+
if (!json.files || json.files.length === 0) {
|
|
41
|
+
console.error('\x1b[31mNo files found for this component.\x1b[0m');
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// We put components neatly in components/kokonutui instead of relying on generic ui
|
|
46
|
+
const targetDir = path.join(process.cwd(), 'components', 'kokonutui');
|
|
47
|
+
if (!fs.existsSync(targetDir)) {
|
|
48
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
json.files.forEach(file => {
|
|
52
|
+
// Some registries use object {name, content}, some string. We handle object.
|
|
53
|
+
const fileName = path.basename(file.name || `${component}.tsx`);
|
|
54
|
+
const fileContent = file.content;
|
|
55
|
+
|
|
56
|
+
const targetPath = path.join(targetDir, fileName);
|
|
57
|
+
fs.writeFileSync(targetPath, fileContent);
|
|
58
|
+
console.log(`\x1b[32m✔ Created ${path.join('components', 'kokonutui', fileName)}\x1b[0m`);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
console.log('\x1b[36m\nDone! Component added successfully.\x1b[0m');
|
|
62
|
+
} catch (e) {
|
|
63
|
+
console.error('\x1b[31mFailed to parse component data.\x1b[0m');
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}).on('error', (e) => {
|
|
68
|
+
console.error(`\x1b[31mFailed to fetch component: ${e.message}\x1b[0m`);
|
|
32
69
|
process.exit(1);
|
|
33
|
-
}
|
|
70
|
+
});
|
|
34
71
|
});
|
|
35
72
|
|
|
36
73
|
program.parse(process.argv);
|