@srcroot/ui 0.0.19 → 0.0.21
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/dist/index.js +44 -93
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -511,12 +511,35 @@ async function init(options) {
|
|
|
511
511
|
const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
512
512
|
const tailwindVersion = allDeps["tailwindcss"] || "";
|
|
513
513
|
const isTailwind4 = tailwindVersion.includes("^4") || tailwindVersion.startsWith("4") || allDeps["@tailwindcss/postcss"];
|
|
514
|
-
const
|
|
515
|
-
const
|
|
516
|
-
const
|
|
517
|
-
const
|
|
518
|
-
const
|
|
519
|
-
const
|
|
514
|
+
const hasSrc = fs.existsSync(path.join(cwd, "src"));
|
|
515
|
+
const srcPath = hasSrc ? path.join(cwd, "src") : cwd;
|
|
516
|
+
const appPath = path.join(srcPath, "app");
|
|
517
|
+
const pagesPath = path.join(srcPath, "pages");
|
|
518
|
+
const hasAppDir = fs.existsSync(appPath);
|
|
519
|
+
const hasPagesDir = fs.existsSync(pagesPath);
|
|
520
|
+
const libDir = path.join(srcPath, "lib");
|
|
521
|
+
const componentsDir = path.join(srcPath, "components", "ui");
|
|
522
|
+
let globalsPath = "";
|
|
523
|
+
if (hasAppDir) {
|
|
524
|
+
if (fs.existsSync(path.join(appPath, "globals.css"))) {
|
|
525
|
+
globalsPath = path.join(appPath, "globals.css");
|
|
526
|
+
} else if (fs.existsSync(path.join(appPath, "global.css"))) {
|
|
527
|
+
globalsPath = path.join(appPath, "global.css");
|
|
528
|
+
} else {
|
|
529
|
+
globalsPath = path.join(appPath, "globals.css");
|
|
530
|
+
}
|
|
531
|
+
} else if (hasPagesDir) {
|
|
532
|
+
const stylesPath = path.join(srcPath, "styles");
|
|
533
|
+
if (fs.existsSync(path.join(stylesPath, "globals.css"))) {
|
|
534
|
+
globalsPath = path.join(stylesPath, "globals.css");
|
|
535
|
+
} else if (fs.existsSync(path.join(stylesPath, "global.css"))) {
|
|
536
|
+
globalsPath = path.join(stylesPath, "global.css");
|
|
537
|
+
} else {
|
|
538
|
+
globalsPath = path.join(stylesPath, "globals.css");
|
|
539
|
+
}
|
|
540
|
+
} else {
|
|
541
|
+
globalsPath = path.join(srcPath, "globals.css");
|
|
542
|
+
}
|
|
520
543
|
let selectedTheme = options.theme || "slate";
|
|
521
544
|
if (!options.yes && !options.theme) {
|
|
522
545
|
const themeChoices = Object.entries(THEMES).map(([key, theme]) => ({
|
|
@@ -556,96 +579,24 @@ async function init(options) {
|
|
|
556
579
|
} else {
|
|
557
580
|
spinner.info(`Tailwind 4 detected - skipping ${chalk.cyan("tailwind.config.ts")}`);
|
|
558
581
|
}
|
|
559
|
-
spinner.start("Checking dependencies...");
|
|
560
|
-
const currentPkg = await fs.readJson(packageJsonPath);
|
|
561
|
-
const currentDeps = { ...currentPkg.dependencies, ...currentPkg.devDependencies };
|
|
562
|
-
const missing = [];
|
|
563
|
-
const requiredDeps = {
|
|
564
|
-
"clsx": "clsx",
|
|
565
|
-
"tailwind-merge": "tailwind-merge",
|
|
566
|
-
"class-variance-authority": "class-variance-authority",
|
|
567
|
-
"lucide-react": "lucide-react"
|
|
568
|
-
};
|
|
569
|
-
if (!isTailwind4) {
|
|
570
|
-
requiredDeps["tailwindcss-animate"] = "tailwindcss-animate";
|
|
571
|
-
}
|
|
572
|
-
for (const [depName, installCmd2] of Object.entries(requiredDeps)) {
|
|
573
|
-
if (!currentDeps[depName]) {
|
|
574
|
-
missing.push(installCmd2);
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
if (missing.length === 0) {
|
|
578
|
-
spinner.succeed(chalk.green("All dependencies already installed"));
|
|
579
|
-
} else {
|
|
580
|
-
spinner.info(`Found ${chalk.cyan(missing.length)} missing ${missing.length === 1 ? "dependency" : "dependencies"}: ${chalk.dim(missing.map((d) => d.split("@")[0]).join(", "))}`);
|
|
581
|
-
}
|
|
582
|
-
async function runCommand(command, cwd2) {
|
|
583
|
-
const { exec } = await import("child_process");
|
|
584
|
-
const { promisify } = await import("util");
|
|
585
|
-
const execAsync = promisify(exec);
|
|
586
|
-
return await execAsync(command, { cwd: cwd2 });
|
|
587
|
-
}
|
|
588
|
-
async function installOneByOne(spinner2, packageManager2, installCmd2, missing2, cwd2) {
|
|
589
|
-
spinner2.warn("Batch installation failed. Attempting to install dependencies one by one...");
|
|
590
|
-
let allSucceeded = true;
|
|
591
|
-
const installFlags = packageManager2 === "npm" ? "--legacy-peer-deps" : "";
|
|
592
|
-
for (const dep of missing2) {
|
|
593
|
-
spinner2.start(`Installing ${chalk.cyan(dep)} via ${packageManager2}${installFlags ? " (with --legacy-peer-deps)" : ""}...`);
|
|
594
|
-
try {
|
|
595
|
-
const command = installFlags ? `${packageManager2} ${installCmd2} ${installFlags} ${dep}` : `${packageManager2} ${installCmd2} ${dep}`;
|
|
596
|
-
await runCommand(command, cwd2);
|
|
597
|
-
spinner2.succeed(`Installed ${chalk.green(dep)}`);
|
|
598
|
-
} catch (depError) {
|
|
599
|
-
allSucceeded = false;
|
|
600
|
-
spinner2.fail(`Failed to install ${chalk.red(dep)}`);
|
|
601
|
-
if (depError.stdout) {
|
|
602
|
-
console.log(chalk.dim(`
|
|
603
|
-
=== stdout for ${dep} ===`));
|
|
604
|
-
console.log(chalk.dim(depError.stdout.toString()));
|
|
605
|
-
}
|
|
606
|
-
if (depError.stderr) {
|
|
607
|
-
console.log(chalk.red(`
|
|
608
|
-
=== stderr for ${dep} ===`));
|
|
609
|
-
console.error(chalk.red(depError.stderr.toString()));
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
if (allSucceeded) {
|
|
614
|
-
console.log(chalk.green("\n\u2705 All dependencies installed successfully!\n"));
|
|
615
|
-
} else {
|
|
616
|
-
console.log(chalk.yellow("\n\u26A0 Some dependencies failed to install."));
|
|
617
|
-
const manualCmd = installFlags ? `${packageManager2} ${installCmd2} ${installFlags} ${missing2.join(" ")}` : `${packageManager2} ${installCmd2} ${missing2.join(" ")}`;
|
|
618
|
-
console.log(chalk.dim(`
|
|
619
|
-
Please manually run: ${manualCmd}
|
|
620
|
-
`));
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
if (missing.length > 0) {
|
|
624
|
-
spinner.start(`Installing dependencies via ${packageManager}: ${missing.join(", ")}...`);
|
|
625
|
-
try {
|
|
626
|
-
await runCommand(`${packageManager} ${installCmd} ${missing.join(" ")}`, cwd);
|
|
627
|
-
spinner.succeed("Dependencies installed");
|
|
628
|
-
} catch (error) {
|
|
629
|
-
const stderr = error.stderr?.toString() || "";
|
|
630
|
-
if (packageManager === "npm" && (stderr.includes("ERESOLVE") || stderr.includes("peer dependency") || stderr.includes("conflicting peer dependency") || stderr.includes("Cannot read properties of null"))) {
|
|
631
|
-
spinner.start("Batch installation failed. Retrying with --legacy-peer-deps...");
|
|
632
|
-
try {
|
|
633
|
-
await runCommand(`npm install --legacy-peer-deps ${missing.join(" ")}`, cwd);
|
|
634
|
-
spinner.succeed("Dependencies installed (used --legacy-peer-deps)");
|
|
635
|
-
} catch (retryError) {
|
|
636
|
-
await installOneByOne(spinner, packageManager, installCmd, missing, cwd);
|
|
637
|
-
}
|
|
638
|
-
} else {
|
|
639
|
-
await installOneByOne(spinner, packageManager, installCmd, missing, cwd);
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
582
|
console.log(chalk.green("\n\u2705 Project initialized successfully!\n"));
|
|
644
583
|
console.log(`Theme: ${chalk.cyan(THEMES[selectedTheme].name)}`);
|
|
645
584
|
console.log(`Tailwind: ${chalk.cyan(isTailwind4 ? "v4" : "v3")}`);
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
585
|
+
const requiredDeps = [
|
|
586
|
+
"clsx",
|
|
587
|
+
"tailwind-merge",
|
|
588
|
+
"class-variance-authority",
|
|
589
|
+
"lucide-react"
|
|
590
|
+
];
|
|
591
|
+
if (!isTailwind4) {
|
|
592
|
+
requiredDeps.push("tailwindcss-animate");
|
|
593
|
+
}
|
|
594
|
+
console.log(chalk.cyan("\n\u{1F4E6} Required dependencies:"));
|
|
595
|
+
console.log(chalk.dim(` ${packageManager} ${installCmd} ${requiredDeps.join(" ")}`));
|
|
596
|
+
console.log("\n\u2728 Next steps:");
|
|
597
|
+
console.log(chalk.dim(" 1. Install dependencies (command above)"));
|
|
598
|
+
console.log(chalk.dim(" 2. npx @srcroot/ui add button"));
|
|
599
|
+
console.log(chalk.dim(" 3. npx @srcroot/ui add --all"));
|
|
649
600
|
console.log();
|
|
650
601
|
} catch (error) {
|
|
651
602
|
spinner.fail("Failed to initialize project");
|