@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.
- package/index.js +43 -10
- 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
|
-
|
|
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: "
|
|
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
|
-
//
|
|
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(
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
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!")
|