bigblocks
Version:
Complete Bitcoin UI component library - authentication, social, wallet, market, inscriptions, and blockchain interactions for React
147 lines (146 loc) • 6.16 kB
JavaScript
import chalk from "chalk";
import { Command } from "commander";
import ora from "ora";
import prompts from "prompts";
import { installComponent } from "../utils/installer.js";
import { getRegistryIndex } from "../utils/registry.js";
// Import aliases to check both alias and full names
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 const add = new Command()
.name("add")
.description("Add components to your project")
.argument("[components...]", "Names of components to add")
.option("-a, --all", "Add all available components")
.option("-o, --overwrite", "Overwrite existing files")
.option("--skip-deps", "Skip dependency installation")
.action(async (components, options) => {
try {
const spinner = ora();
// Load registry index
spinner.start("Loading component registry...");
const index = await getRegistryIndex();
const availableComponents = index.map((c) => c.name);
spinner.succeed("Registry loaded");
// Determine which components to install
let toInstall = [];
if (options.all) {
const { confirmAll } = await prompts({
type: "confirm",
name: "confirmAll",
message: "Are you sure you want to install all components? This may overwrite existing files.",
initial: false,
});
if (!confirmAll) {
console.log(chalk.yellow("Installation cancelled."));
return;
}
toInstall = availableComponents;
}
else if (components.length === 0) {
// Interactive selection
const { selected } = await prompts({
type: "multiselect",
name: "selected",
message: "Select components to add",
choices: availableComponents.map((name) => ({
title: name,
value: name,
})),
});
if (!selected || selected.length === 0) {
console.log(chalk.yellow("No components selected"));
return;
}
toInstall = selected;
}
else {
// Validate component names (check both aliases and full names)
for (const name of components) {
const fullName = COMPONENT_ALIASES[name] || name;
if (!availableComponents.includes(fullName)) {
console.error(chalk.red(`Component "${name}" not found`));
console.log(chalk.gray("\nAvailable components:"));
console.log(availableComponents.join(", "));
process.exit(1);
}
}
toInstall = components;
}
if (toInstall.length === 0) {
console.log("No components selected");
return;
}
// Install components
const installedSet = new Set();
const allDependencies = {
deps: new Set(),
devDeps: new Set(),
};
for (const name of toInstall) {
try {
await installComponent(name, options, installedSet, allDependencies, spinner);
}
catch (error) {
console.error(chalk.red(`Failed to install ${name}:`), error instanceof Error ? error.message : String(error));
}
}
console.log(chalk.green(`\n✓ Installed ${installedSet.size} components`));
}
catch (error) {
console.error(chalk.red("Installation failed:"), error instanceof Error ? error.message : String(error));
}
});