bigblocks
Version:
Complete Bitcoin UI component library - authentication, social, wallet, market, inscriptions, and blockchain interactions for React
78 lines (76 loc) • 2.84 kB
JavaScript
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import chalk from "chalk";
import { Command } from "commander";
import ora from "ora";
import prompts from "prompts";
export const init = new Command()
.name("init")
.description("Initialize BigBlocks in your project")
.action(async () => {
const spinner = ora();
console.log(chalk.bold("Initializing BigBlocks..."));
// Check if components.json exists
const configPath = join(process.cwd(), "components.json");
if (existsSync(configPath)) {
const { overwrite } = await prompts({
type: "confirm",
name: "overwrite",
message: "components.json already exists. Overwrite?",
initial: false,
});
if (!overwrite) {
console.log(chalk.yellow("Initialization cancelled."));
return;
}
}
// Detect project structure
const hasSrcDir = existsSync(join(process.cwd(), "src"));
const hasAppDir = existsSync(join(process.cwd(), "app"));
// Create default config
const defaultConfig = {
$schema: "https://ui.shadcn.com/schema/components.json",
style: "default",
rsc: hasAppDir,
tsx: true,
tailwind: {
config: "tailwind.config.js",
css: hasAppDir ? "app/globals.css" : "src/index.css",
baseColor: "zinc",
cssVariables: true,
prefix: "",
},
aliases: {
components: "@/components",
ui: "@/components/ui",
lib: "@/lib",
utils: "@/lib/utils",
hooks: "@/hooks",
},
};
// Write config
spinner.start("Creating components.json...");
writeFileSync(configPath, JSON.stringify(defaultConfig, null, 2));
spinner.succeed(chalk.green("✓ Created components.json"));
// Create utils file
const utilsDir = join(process.cwd(), hasSrcDir ? "src/lib" : "lib");
if (!existsSync(utilsDir)) {
mkdirSync(utilsDir, { recursive: true });
}
const utilsPath = join(utilsDir, "utils.ts");
if (!existsSync(utilsPath)) {
spinner.start("Creating utils.ts...");
const utilsContent = `import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
`;
writeFileSync(utilsPath, utilsContent);
spinner.succeed(chalk.green(`✓ Created ${utilsPath}`));
}
console.log(chalk.green("\n✓ BigBlocks initialized successfully!"));
console.log(chalk.gray("\nNext steps:"));
console.log(chalk.gray(" 1. Make sure you have shadcn/ui set up: npx shadcn@latest init"));
console.log(chalk.gray(" 2. Add components: bigblocks add <component>"));
});