UNPKG

bigblocks

Version:

Complete Bitcoin UI component library - authentication, social, wallet, market, inscriptions, and blockchain interactions for React

121 lines (120 loc) 5.11 kB
import { existsSync, readFileSync } from "node:fs"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const GITHUB_RAW_BASE = "https://raw.githubusercontent.com/bitcoin-sv/bigblocks/master"; export async function getRegistryIndex() { try { // Try remote first const response = await fetch(`${GITHUB_RAW_BASE}/registry/index.json`); if (response.ok) { return await response.json(); } } catch { // Fall back to local } // Try local registry (dist-registry when installed via npm, registry when developing) // When CLI is built, it's in dist/cli/utils, so need to go up 3 levels to reach project root const distPath = join(__dirname, "..", "..", "..", "dist-registry", "index.json"); if (existsSync(distPath)) { return JSON.parse(readFileSync(distPath, "utf-8")); } // Fallback to development registry const localPath = join(__dirname, "..", "..", "..", "registry", "index.json"); if (existsSync(localPath)) { return JSON.parse(readFileSync(localPath, "utf-8")); } throw new Error("Could not load registry index"); } // Short aliases for better DX const COMPONENT_ALIASES = { // Authentication "auth-button": "authentication-authbutton", "login-form": "authentication-loginform", "signup-flow": "authentication-signupflow", "device-link": "authentication-devicelinkqr", "oauth-restore": "authentication-oauthrestoreflow", "auth-flow": "authentication-authfloworchestrator", // UI Components "loading-button": "ui-components-loadingbutton", "warning-card": "ui-components-warningcard", "bitcoin-avatar": "ui-components-bitcoinavatar", "qr-code": "ui-components-qrcoderenderer", "password-input": "ui-components-passwordinput", "error-display": "ui-components-errordisplay", modal: "ui-components-modal", dropzone: "ui-components-dropzone", // Profile "profile-card": "profile-management-profilecard", "profile-editor": "profile-management-profileeditor", "profile-dropdown": "profile-management-profiledropdownmenu", "profile-popover": "profile-management-profilepopover", "profile-switcher": "profile-management-profileswitcher", // Social "post-button": "social-components-postbutton", "like-button": "social-components-likebutton", "follow-button": "social-components-followbutton", "social-feed": "social-components-socialfeed", "post-card": "social-components-postcard", // Wallet "send-button": "wallet-components-sendbsvbutton", "donate-button": "wallet-components-donatebutton", "wallet-overview": "wallet-components-walletoverview", "token-balance": "wallet-components-tokenbalance", // Backup "backup-download": "backup-recovery-backupdownload", "backup-import": "backup-recovery-backupimport", "file-import": "backup-recovery-fileimport", "mnemonic-display": "backup-recovery-mnemonicdisplay", // Market "buy-button": "market-components-buylistingbutton", "sell-button": "market-components-createlistingbutton", "cancel-listing": "market-components-cancellistingbutton", "market-table": "market-components-markettable", // Inscriptions "inscription-button": "inscriptions-components-inscriptionbutton", "mint-button": "inscriptions-components-bsv20mintbutton", "collection-form": "inscriptions-components-collectionform", // Developer Tools "key-manager": "developer-tools-keymanager", "artifact-display": "developer-tools-artifactdisplay", // Providers "bitcoin-auth": "providers-bitcoinauthprovider", "bitcoin-query": "providers-bitcoinqueryprovider", }; export async function loadComponent(name) { // Check if it's an alias first const actualName = COMPONENT_ALIASES[name] || name; // Determine component type from actualName (not the alias) let subdir = "components"; if (actualName.startsWith("ui-") && !actualName.startsWith("ui-components-")) { subdir = "ui"; } else if (actualName.includes("-hook") || actualName.startsWith("use")) { subdir = "hooks"; } try { // Try remote first const response = await fetch(`${GITHUB_RAW_BASE}/registry/${subdir}/${actualName}.json`); if (response.ok) { return await response.json(); } } catch { // Fall back to local } // Try local registry (dist-registry when installed via npm, registry when developing) const distPath = join(__dirname, "..", "..", "..", "dist-registry", subdir, `${actualName}.json`); if (existsSync(distPath)) { return JSON.parse(readFileSync(distPath, "utf-8")); } // Fallback to development registry const localPath = join(__dirname, "..", "..", "..", "registry", subdir, `${actualName}.json`); if (existsSync(localPath)) { return JSON.parse(readFileSync(localPath, "utf-8")); } return null; }