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.js CHANGED
@@ -352,21 +352,44 @@ import path from "path";
352
352
  async function ensureDir(dirPath) {
353
353
  await fs.ensureDir(dirPath);
354
354
  }
355
- async function writeFile(filePath, content) {
355
+ async function writeFile(filePath, content, shouldOverwrite = true) {
356
356
  const dir = path.dirname(filePath);
357
357
  await ensureDir(dir);
358
- await fs.writeFile(filePath, content, "utf-8");
358
+ const writeOptions = shouldOverwrite ? { encoding: "utf-8", flag: "w" } : { encoding: "utf-8", flag: "wx" };
359
+ await fs.writeFile(filePath, content, writeOptions);
360
+ }
361
+ async function exists(pathToCheck) {
362
+ try {
363
+ await fs.access(pathToCheck);
364
+ return true;
365
+ } catch {
366
+ return false;
367
+ }
359
368
  }
360
369
  async function createDirectories(dirs) {
361
370
  for (const dir of dirs) {
362
371
  await ensureDir(dir);
363
372
  }
364
373
  }
365
- async function writeFiles(files) {
374
+ async function writeFiles(files, shouldOverwrite = true) {
366
375
  for (const file of files) {
367
- await writeFile(file.path, file.content);
368
- logger.dim(` Created: ${file.path}`);
376
+ const fileExists = await exists(file.path);
377
+ await writeFile(file.path, file.content, shouldOverwrite);
378
+ if (fileExists) {
379
+ logger.dim(` Updated: ${file.path}`);
380
+ } else {
381
+ logger.dim(` Created: ${file.path}`);
382
+ }
383
+ }
384
+ }
385
+ async function checkExistingFiles(filePaths) {
386
+ const existingFiles = [];
387
+ for (const filePath of filePaths) {
388
+ if (await exists(filePath)) {
389
+ existingFiles.push(filePath);
390
+ }
369
391
  }
392
+ return existingFiles;
370
393
  }
371
394
 
372
395
  // src/templates/ddd/entity.ts
@@ -572,7 +595,7 @@ function generateComponent(config) {
572
595
  const hasAnimations = animations.listAnimations || animations.cardAnimations;
573
596
  const imports = `'use client';
574
597
 
575
- ${hasAnimations ? `import { motion } from 'framer-motion';` : ""}
598
+ ${hasAnimations ? `import { motion, type Variants } from 'framer-motion';` : ""}
576
599
  import { useEffect, useState } from 'react';
577
600
  import { ${entityName} } from '../../domain/entities/${moduleName}.entity';
578
601
  import { Get${entityName}sUseCase } from '../../application/use-cases/get-${moduleName}s.use-case';
@@ -632,7 +655,7 @@ import {
632
655
  ${includeRowSelection ? `import { Checkbox } from "@/components/ui/checkbox";` : ""}`;
633
656
  const animationVariants = hasAnimations ? `
634
657
  // Framer Motion animation variants
635
- const containerVariants = {
658
+ const containerVariants: Variants = {
636
659
  hidden: { opacity: 0 },
637
660
  visible: {
638
661
  opacity: 1,
@@ -642,7 +665,7 @@ const containerVariants = {
642
665
  }
643
666
  };
644
667
 
645
- const itemVariants = {
668
+ const itemVariants: Variants = {
646
669
  hidden: { opacity: 0, x: -20 },
647
670
  visible: {
648
671
  opacity: 1,
@@ -650,6 +673,10 @@ const itemVariants = {
650
673
  transition: { duration: ${animations.intensity === "bold" ? "0.3" : animations.intensity === "subtle" ? "0.15" : "0.2"} }
651
674
  }
652
675
  };
676
+ ${animations.listAnimations ? `
677
+ // Create motion-wrapped TableRow component
678
+ const MotionTableRow = motion(TableRow);
679
+ ` : ""}
653
680
  ` : "";
654
681
  const dataFetchingCode = isTanStack ? `
655
682
  // TanStack Query data fetching
@@ -952,7 +979,7 @@ ${tableHeaders}
952
979
  ) : (
953
980
  ${animations.listAnimations ? `
954
981
  data.map((item, index) => (
955
- <motion.tr
982
+ <MotionTableRow
956
983
  key={item.id}
957
984
  variants={itemVariants}
958
985
  initial="hidden"
@@ -989,7 +1016,7 @@ ${tableCells}
989
1016
  </DropdownMenu>
990
1017
  </div>
991
1018
  </TableCell>
992
- ${animations.listAnimations ? `</motion.tr>` : `</TableRow>`}
1019
+ ${animations.listAnimations ? `</MotionTableRow>` : `</TableRow>`}
993
1020
  ))
994
1021
  )}
995
1022
  </TableBody>
@@ -1107,10 +1134,10 @@ import { motion } from 'framer-motion';
1107
1134
  export default function Template({ children }: { children: React.ReactNode }) {
1108
1135
  return (
1109
1136
  <motion.div
1110
- initial=${animConfig.initial}
1111
- animate=${animConfig.animate}
1137
+ initial={${animConfig.initial}}
1138
+ animate={${animConfig.animate}}
1112
1139
  exit={{ opacity: 0, y: -20 }}
1113
- transition=${animConfig.transition}
1140
+ transition={${animConfig.transition}}
1114
1141
  >
1115
1142
  {children}
1116
1143
  </motion.div>
@@ -1169,7 +1196,19 @@ var DDDGenerator = class {
1169
1196
  content: generateTemplate(this.config)
1170
1197
  });
1171
1198
  }
1172
- await writeFiles(files);
1199
+ const filePaths = files.map((f) => f.path);
1200
+ const existingFiles = await checkExistingFiles(filePaths);
1201
+ if (existingFiles.length > 0) {
1202
+ console.log("");
1203
+ logger.warning(`Found ${existingFiles.length} existing file(s):`);
1204
+ existingFiles.forEach((file) => {
1205
+ const relativePath = path2.relative(cwd, file);
1206
+ logger.dim(` - ${relativePath}`);
1207
+ });
1208
+ console.log("");
1209
+ logger.info("Overwriting existing files...");
1210
+ }
1211
+ await writeFiles(files, true);
1173
1212
  const instructions = this.generateInstructions();
1174
1213
  return { files, instructions };
1175
1214
  }
@@ -1298,7 +1337,7 @@ ${mockDataFields}
1298
1337
  ${fetchFunction}`;
1299
1338
  const imports = `'use client';
1300
1339
 
1301
- ${hasAnimations ? `import { motion } from 'framer-motion';` : ""}
1340
+ ${hasAnimations ? `import { motion, type Variants } from 'framer-motion';` : ""}
1302
1341
  import { useEffect, useState } from 'react';
1303
1342
  ${isTanStack ? `import { useQuery } from '@tanstack/react-query';` : ""}
1304
1343
  import { Button } from '@/components/ui/button';
@@ -1355,7 +1394,7 @@ import {
1355
1394
  ${includeRowSelection ? `import { Checkbox } from "@/components/ui/checkbox";` : ""}`;
1356
1395
  const animationVariants = hasAnimations ? `
1357
1396
  // Framer Motion animation variants
1358
- const containerVariants = {
1397
+ const containerVariants: Variants = {
1359
1398
  hidden: { opacity: 0 },
1360
1399
  visible: {
1361
1400
  opacity: 1,
@@ -1365,7 +1404,7 @@ const containerVariants = {
1365
1404
  }
1366
1405
  };
1367
1406
 
1368
- const itemVariants = {
1407
+ const itemVariants: Variants = {
1369
1408
  hidden: { opacity: 0, x: -20 },
1370
1409
  visible: {
1371
1410
  opacity: 1,
@@ -1373,6 +1412,10 @@ const itemVariants = {
1373
1412
  transition: { duration: ${animations.intensity === "bold" ? "0.3" : animations.intensity === "subtle" ? "0.15" : "0.2"} }
1374
1413
  }
1375
1414
  };
1415
+ ${animations.listAnimations ? `
1416
+ // Create motion-wrapped TableRow component
1417
+ const MotionTableRow = motion(TableRow);
1418
+ ` : ""}
1376
1419
  ` : "";
1377
1420
  const rowSelectionCode = includeRowSelection ? `
1378
1421
  const [selectedRows, setSelectedRows] = useState<Set<string>>(new Set());
@@ -1626,7 +1669,7 @@ ${tableHeaders}
1626
1669
  ) : (
1627
1670
  ${animations.listAnimations ? `
1628
1671
  data.map((item, index) => (
1629
- <motion.tr
1672
+ <MotionTableRow
1630
1673
  key={item.id}
1631
1674
  variants={itemVariants}
1632
1675
  initial="hidden"
@@ -1663,7 +1706,7 @@ ${tableCells}
1663
1706
  </DropdownMenu>
1664
1707
  </div>
1665
1708
  </TableCell>
1666
- ${animations.listAnimations ? `</motion.tr>` : `</TableRow>`}
1709
+ ${animations.listAnimations ? `</MotionTableRow>` : `</TableRow>`}
1667
1710
  ))
1668
1711
  )}
1669
1712
  </TableBody>
@@ -1770,7 +1813,19 @@ var SimplifiedGenerator = class {
1770
1813
  content: generateTemplate(this.config)
1771
1814
  });
1772
1815
  }
1773
- await writeFiles(files);
1816
+ const filePaths = files.map((f) => f.path);
1817
+ const existingFiles = await checkExistingFiles(filePaths);
1818
+ if (existingFiles.length > 0) {
1819
+ console.log("");
1820
+ logger.warning(`Found ${existingFiles.length} existing file(s):`);
1821
+ existingFiles.forEach((file) => {
1822
+ const relativePath = path3.relative(cwd, file);
1823
+ logger.dim(` - ${relativePath}`);
1824
+ });
1825
+ console.log("");
1826
+ logger.info("Overwriting existing files...");
1827
+ }
1828
+ await writeFiles(files, true);
1774
1829
  const instructions = this.generateInstructions();
1775
1830
  return { files, instructions };
1776
1831
  }