@hznrkv/sidebar 1.1.2 → 1.2.1

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.
Files changed (2) hide show
  1. package/index.js +43 -10
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -462,6 +462,17 @@ export default function Root() {
462
462
  async function main() {
463
463
  console.log("\n@hznrkv/sidebar — instalador\n")
464
464
 
465
+ // 0. Tema
466
+ const { theme } = await prompts({
467
+ type: "select",
468
+ name: "theme",
469
+ message: "Tema padrão:",
470
+ choices: [
471
+ { title: "Dark", value: "dark" },
472
+ { title: "Light", value: "light" },
473
+ ],
474
+ })
475
+
465
476
  // 1. Next.js
466
477
  const pkg = readJson("package.json")
467
478
  const hasNext = pkg?.dependencies?.next || pkg?.devDependencies?.next
@@ -485,11 +496,22 @@ async function main() {
485
496
  // 2. Shadcn
486
497
  const hasShadcn = exists("components.json")
487
498
 
488
- if (!hasShadcn) {
499
+ let reinitShadcn = !hasShadcn
500
+ if (hasShadcn) {
501
+ const { reinit } = await prompts({
502
+ type: "confirm",
503
+ name: "reinit",
504
+ message: "Shadcn encontrado. Reinicializar com novo tema/preset?",
505
+ initial: false,
506
+ })
507
+ reinitShadcn = reinit
508
+ }
509
+
510
+ if (reinitShadcn) {
489
511
  const { mode } = await prompts({
490
512
  type: "select",
491
513
  name: "mode",
492
- message: "Shadcn não encontrado. Como quer inicializar?",
514
+ message: "Como quer inicializar o Shadcn?",
493
515
  choices: [
494
516
  { title: "Instalação padrão", value: "default" },
495
517
  { title: "Tenho um preset pronto", value: "preset" },
@@ -604,23 +626,34 @@ async function main() {
604
626
  }
605
627
  }
606
628
 
607
- // 6. Patch no root layout para adicionar TooltipProvider
629
+ // 8. Patch no root layout
608
630
  const rootLayoutPath = path.join(cwd, "src/app/layout.tsx")
609
631
  if (fs.existsSync(rootLayoutPath)) {
610
632
  let rootLayout = fs.readFileSync(rootLayoutPath, "utf8")
633
+
634
+ // TooltipProvider
611
635
  if (!rootLayout.includes("TooltipProvider")) {
612
636
  rootLayout = rootLayout.replace(
613
637
  /^(import .+from .+;\n)/m,
614
638
  `$1import { TooltipProvider } from "@/components/ui/tooltip"\n`
615
639
  )
616
- rootLayout = rootLayout.replace(/<body([^>]*)>(\s*)\{children\}/, `<body$1>$2<TooltipProvider>{children}</TooltipProvider>`)
617
- rootLayout = rootLayout.replace(/<html([^>]*?)className="([^"]*)"/, (_, attrs, cls) => {
618
- if (cls.includes("dark")) return `<html${attrs}className="${cls}"`
619
- return `<html${attrs}className="${cls} dark"`
620
- })
621
- fs.writeFileSync(rootLayoutPath, rootLayout, "utf8")
622
- console.log(" ✔ src/app/layout.tsx (TooltipProvider + dark mode)")
640
+ rootLayout = rootLayout.replace(
641
+ /<body([^>]*)>\s*\{children\}\s*<\/body>/,
642
+ `<body$1><TooltipProvider>{children}</TooltipProvider></body>`
643
+ )
644
+ rootLayout = rootLayout.replace(
645
+ /<body([^>]*)>([\s\S]*?)<\/body>/,
646
+ (_, attrs, inner) => `<body${attrs}><TooltipProvider>${inner.trim()}</TooltipProvider></body>`
647
+ )
623
648
  }
649
+
650
+ // Tema: remove dark existente e reaplica conforme escolha
651
+ rootLayout = rootLayout
652
+ .replace(/"h-full dark"/, '"h-full"')
653
+ .replace(/"h-full"/, theme === "dark" ? '"h-full dark"' : '"h-full"')
654
+
655
+ fs.writeFileSync(rootLayoutPath, rootLayout, "utf8")
656
+ console.log(` ✔ src/app/layout.tsx (TooltipProvider + tema ${theme})`)
624
657
  }
625
658
 
626
659
  console.log("\n✔ Sidebar instalada com sucesso!")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hznrkv/sidebar",
3
- "version": "1.1.2",
3
+ "version": "1.2.1",
4
4
  "description": "CLI para instalar a sidebar @hznrkv em projetos Next.js + Shadcn",
5
5
  "bin": {
6
6
  "@hznrkv/sidebar": "./index.js"