shadcn-nextjs-page-generator 1.0.3 → 1.0.5

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.cjs CHANGED
@@ -385,21 +385,44 @@ var import_path = __toESM(require("path"), 1);
385
385
  async function ensureDir(dirPath) {
386
386
  await import_fs_extra.default.ensureDir(dirPath);
387
387
  }
388
- async function writeFile(filePath, content) {
388
+ async function writeFile(filePath, content, shouldOverwrite = true) {
389
389
  const dir = import_path.default.dirname(filePath);
390
390
  await ensureDir(dir);
391
- await import_fs_extra.default.writeFile(filePath, content, "utf-8");
391
+ const writeOptions = shouldOverwrite ? { encoding: "utf-8", flag: "w" } : { encoding: "utf-8", flag: "wx" };
392
+ await import_fs_extra.default.writeFile(filePath, content, writeOptions);
393
+ }
394
+ async function exists(pathToCheck) {
395
+ try {
396
+ await import_fs_extra.default.access(pathToCheck);
397
+ return true;
398
+ } catch {
399
+ return false;
400
+ }
392
401
  }
393
402
  async function createDirectories(dirs) {
394
403
  for (const dir of dirs) {
395
404
  await ensureDir(dir);
396
405
  }
397
406
  }
398
- async function writeFiles(files) {
407
+ async function writeFiles(files, shouldOverwrite = true) {
399
408
  for (const file of files) {
400
- await writeFile(file.path, file.content);
401
- logger.dim(` Created: ${file.path}`);
409
+ const fileExists = await exists(file.path);
410
+ await writeFile(file.path, file.content, shouldOverwrite);
411
+ if (fileExists) {
412
+ logger.dim(` Updated: ${file.path}`);
413
+ } else {
414
+ logger.dim(` Created: ${file.path}`);
415
+ }
416
+ }
417
+ }
418
+ async function checkExistingFiles(filePaths) {
419
+ const existingFiles = [];
420
+ for (const filePath of filePaths) {
421
+ if (await exists(filePath)) {
422
+ existingFiles.push(filePath);
423
+ }
402
424
  }
425
+ return existingFiles;
403
426
  }
404
427
 
405
428
  // src/templates/ddd/entity.ts
@@ -605,7 +628,7 @@ function generateComponent(config) {
605
628
  const hasAnimations = animations.listAnimations || animations.cardAnimations;
606
629
  const imports = `'use client';
607
630
 
608
- ${hasAnimations ? `import { motion } from 'framer-motion';` : ""}
631
+ ${hasAnimations ? `import { motion, type Variants } from 'framer-motion';` : ""}
609
632
  import { useEffect, useState } from 'react';
610
633
  import { ${entityName} } from '../../domain/entities/${moduleName}.entity';
611
634
  import { Get${entityName}sUseCase } from '../../application/use-cases/get-${moduleName}s.use-case';
@@ -665,7 +688,7 @@ import {
665
688
  ${includeRowSelection ? `import { Checkbox } from "@/components/ui/checkbox";` : ""}`;
666
689
  const animationVariants = hasAnimations ? `
667
690
  // Framer Motion animation variants
668
- const containerVariants = {
691
+ const containerVariants: Variants = {
669
692
  hidden: { opacity: 0 },
670
693
  visible: {
671
694
  opacity: 1,
@@ -675,7 +698,7 @@ const containerVariants = {
675
698
  }
676
699
  };
677
700
 
678
- const itemVariants = {
701
+ const itemVariants: Variants = {
679
702
  hidden: { opacity: 0, x: -20 },
680
703
  visible: {
681
704
  opacity: 1,
@@ -683,6 +706,10 @@ const itemVariants = {
683
706
  transition: { duration: ${animations.intensity === "bold" ? "0.3" : animations.intensity === "subtle" ? "0.15" : "0.2"} }
684
707
  }
685
708
  };
709
+ ${animations.listAnimations ? `
710
+ // Create motion-wrapped TableRow component
711
+ const MotionTableRow = motion(TableRow);
712
+ ` : ""}
686
713
  ` : "";
687
714
  const dataFetchingCode = isTanStack ? `
688
715
  // TanStack Query data fetching
@@ -985,7 +1012,7 @@ ${tableHeaders}
985
1012
  ) : (
986
1013
  ${animations.listAnimations ? `
987
1014
  data.map((item, index) => (
988
- <motion.tr
1015
+ <MotionTableRow
989
1016
  key={item.id}
990
1017
  variants={itemVariants}
991
1018
  initial="hidden"
@@ -1022,7 +1049,7 @@ ${tableCells}
1022
1049
  </DropdownMenu>
1023
1050
  </div>
1024
1051
  </TableCell>
1025
- ${animations.listAnimations ? `</motion.tr>` : `</TableRow>`}
1052
+ ${animations.listAnimations ? `</MotionTableRow>` : `</TableRow>`}
1026
1053
  ))
1027
1054
  )}
1028
1055
  </TableBody>
@@ -1140,10 +1167,10 @@ import { motion } from 'framer-motion';
1140
1167
  export default function Template({ children }: { children: React.ReactNode }) {
1141
1168
  return (
1142
1169
  <motion.div
1143
- initial=${animConfig.initial}
1144
- animate=${animConfig.animate}
1170
+ initial={${animConfig.initial}}
1171
+ animate={${animConfig.animate}}
1145
1172
  exit={{ opacity: 0, y: -20 }}
1146
- transition=${animConfig.transition}
1173
+ transition={${animConfig.transition}}
1147
1174
  >
1148
1175
  {children}
1149
1176
  </motion.div>
@@ -1202,7 +1229,19 @@ var DDDGenerator = class {
1202
1229
  content: generateTemplate(this.config)
1203
1230
  });
1204
1231
  }
1205
- await writeFiles(files);
1232
+ const filePaths = files.map((f) => f.path);
1233
+ const existingFiles = await checkExistingFiles(filePaths);
1234
+ if (existingFiles.length > 0) {
1235
+ console.log("");
1236
+ logger.warning(`Found ${existingFiles.length} existing file(s):`);
1237
+ existingFiles.forEach((file) => {
1238
+ const relativePath = import_path2.default.relative(cwd, file);
1239
+ logger.dim(` - ${relativePath}`);
1240
+ });
1241
+ console.log("");
1242
+ logger.info("Overwriting existing files...");
1243
+ }
1244
+ await writeFiles(files, true);
1206
1245
  const instructions = this.generateInstructions();
1207
1246
  return { files, instructions };
1208
1247
  }
@@ -1331,7 +1370,7 @@ ${mockDataFields}
1331
1370
  ${fetchFunction}`;
1332
1371
  const imports = `'use client';
1333
1372
 
1334
- ${hasAnimations ? `import { motion } from 'framer-motion';` : ""}
1373
+ ${hasAnimations ? `import { motion, type Variants } from 'framer-motion';` : ""}
1335
1374
  import { useEffect, useState } from 'react';
1336
1375
  ${isTanStack ? `import { useQuery } from '@tanstack/react-query';` : ""}
1337
1376
  import { Button } from '@/components/ui/button';
@@ -1388,7 +1427,7 @@ import {
1388
1427
  ${includeRowSelection ? `import { Checkbox } from "@/components/ui/checkbox";` : ""}`;
1389
1428
  const animationVariants = hasAnimations ? `
1390
1429
  // Framer Motion animation variants
1391
- const containerVariants = {
1430
+ const containerVariants: Variants = {
1392
1431
  hidden: { opacity: 0 },
1393
1432
  visible: {
1394
1433
  opacity: 1,
@@ -1398,7 +1437,7 @@ const containerVariants = {
1398
1437
  }
1399
1438
  };
1400
1439
 
1401
- const itemVariants = {
1440
+ const itemVariants: Variants = {
1402
1441
  hidden: { opacity: 0, x: -20 },
1403
1442
  visible: {
1404
1443
  opacity: 1,
@@ -1406,6 +1445,10 @@ const itemVariants = {
1406
1445
  transition: { duration: ${animations.intensity === "bold" ? "0.3" : animations.intensity === "subtle" ? "0.15" : "0.2"} }
1407
1446
  }
1408
1447
  };
1448
+ ${animations.listAnimations ? `
1449
+ // Create motion-wrapped TableRow component
1450
+ const MotionTableRow = motion(TableRow);
1451
+ ` : ""}
1409
1452
  ` : "";
1410
1453
  const rowSelectionCode = includeRowSelection ? `
1411
1454
  const [selectedRows, setSelectedRows] = useState<Set<string>>(new Set());
@@ -1659,7 +1702,7 @@ ${tableHeaders}
1659
1702
  ) : (
1660
1703
  ${animations.listAnimations ? `
1661
1704
  data.map((item, index) => (
1662
- <motion.tr
1705
+ <MotionTableRow
1663
1706
  key={item.id}
1664
1707
  variants={itemVariants}
1665
1708
  initial="hidden"
@@ -1696,7 +1739,7 @@ ${tableCells}
1696
1739
  </DropdownMenu>
1697
1740
  </div>
1698
1741
  </TableCell>
1699
- ${animations.listAnimations ? `</motion.tr>` : `</TableRow>`}
1742
+ ${animations.listAnimations ? `</MotionTableRow>` : `</TableRow>`}
1700
1743
  ))
1701
1744
  )}
1702
1745
  </TableBody>
@@ -1803,7 +1846,19 @@ var SimplifiedGenerator = class {
1803
1846
  content: generateTemplate(this.config)
1804
1847
  });
1805
1848
  }
1806
- await writeFiles(files);
1849
+ const filePaths = files.map((f) => f.path);
1850
+ const existingFiles = await checkExistingFiles(filePaths);
1851
+ if (existingFiles.length > 0) {
1852
+ console.log("");
1853
+ logger.warning(`Found ${existingFiles.length} existing file(s):`);
1854
+ existingFiles.forEach((file) => {
1855
+ const relativePath = import_path3.default.relative(cwd, file);
1856
+ logger.dim(` - ${relativePath}`);
1857
+ });
1858
+ console.log("");
1859
+ logger.info("Overwriting existing files...");
1860
+ }
1861
+ await writeFiles(files, true);
1807
1862
  const instructions = this.generateInstructions();
1808
1863
  return { files, instructions };
1809
1864
  }