@brxndxndiaz/ui 0.1.0

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.
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const fs = require("fs");
5
+ const path = require("path");
6
+
7
+ const REGISTRY_BASE = "https://ui.brndndiaz.dev/r";
8
+ const SOURCE_BASE =
9
+ process.env.BRXN_SOURCE_BASE ||
10
+ "https://raw.githubusercontent.com/brxndxndiaz/brxndxndiaz-ui/main";
11
+
12
+ function printHelp() {
13
+ console.log(`brxndxndiaz-ui
14
+
15
+ Usage:
16
+ brxndxndiaz-ui add <component>
17
+
18
+ Examples:
19
+ brxndxndiaz-ui add animated-timeline
20
+ `);
21
+ }
22
+
23
+ async function fetchJson(url) {
24
+ const res = await fetch(url);
25
+ if (!res.ok) {
26
+ throw new Error(`Request failed: ${res.status} ${res.statusText} (${url})`);
27
+ }
28
+ return res.json();
29
+ }
30
+
31
+ async function fetchText(url) {
32
+ const res = await fetch(url);
33
+ if (!res.ok) {
34
+ throw new Error(`Request failed: ${res.status} ${res.statusText} (${url})`);
35
+ }
36
+ return res.text();
37
+ }
38
+
39
+ async function writeFile(targetPath, content) {
40
+ const fullPath = path.resolve(process.cwd(), targetPath);
41
+ await fs.promises.mkdir(path.dirname(fullPath), { recursive: true });
42
+ await fs.promises.writeFile(fullPath, content, "utf8");
43
+ }
44
+
45
+ async function addComponent(name) {
46
+ const registryUrl = `${REGISTRY_BASE}/${name}.json`;
47
+ const item = await fetchJson(registryUrl);
48
+ if (!item?.files?.length) {
49
+ throw new Error(`Registry item has no files: ${registryUrl}`);
50
+ }
51
+
52
+ for (const file of item.files) {
53
+ const sourcePath = file.path;
54
+ const targetPath = file.target || file.path;
55
+ const sourceUrl = `${SOURCE_BASE}/${sourcePath}`;
56
+ const content = await fetchText(sourceUrl);
57
+ await writeFile(targetPath, content);
58
+ console.log(`Added ${targetPath}`);
59
+ }
60
+ }
61
+
62
+ async function main() {
63
+ const [, , command, arg] = process.argv;
64
+ if (!command || command === "-h" || command === "--help") {
65
+ printHelp();
66
+ return;
67
+ }
68
+
69
+ if (command !== "add" || !arg) {
70
+ printHelp();
71
+ process.exit(1);
72
+ }
73
+
74
+ await addComponent(arg);
75
+ }
76
+
77
+ main().catch((error) => {
78
+ console.error(`Error: ${error.message}`);
79
+ process.exit(1);
80
+ });
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@brxndxndiaz/ui",
3
+ "version": "0.1.0",
4
+ "private": false,
5
+ "description": "CLI for the brxndxndiaz UI registry.",
6
+ "scripts": {
7
+ "publish:public": "npm publish --access public"
8
+ },
9
+ "bin": {
10
+ "brxndxndiaz-ui": "bin/brxndxndiaz-ui.js"
11
+ },
12
+ "engines": {
13
+ "node": ">=18"
14
+ }
15
+ }