create-fullstack-boilerplate 2.1.1 → 2.1.3

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.
@@ -1,27 +1,80 @@
1
1
  const { log } = require("./utils");
2
- // const fs = ensure("fs-extra");
3
2
  const fs = require("fs-extra");
4
-
5
3
  const path = require("path");
6
4
 
7
5
  module.exports = async function copyProject(src, dest) {
6
+ // Resolve absolute paths
7
+ const resolvedSrc = path.resolve(src);
8
+ const resolvedDest = path.resolve(dest);
9
+
8
10
  // Check if destination already exists
9
- if (await fs.pathExists(dest)) {
10
- throw new Error(`Directory '${path.basename(dest)}' already exists. Please choose a different project name.`);
11
+ if (await fs.pathExists(resolvedDest)) {
12
+ throw new Error(`Directory '${path.basename(resolvedDest)}' already exists. Please choose a different project name.`);
11
13
  }
12
14
 
13
15
  // Check if source template exists
14
- if (!await fs.pathExists(src)) {
15
- throw new Error(`Template directory not found. Package may be corrupted.`);
16
+ if (!await fs.pathExists(resolvedSrc)) {
17
+ throw new Error(`Template directory not found at: ${resolvedSrc}`);
18
+ }
19
+
20
+ // Verify backend exists in source
21
+ const srcBackend = path.join(resolvedSrc, "backend");
22
+ if (!await fs.pathExists(srcBackend)) {
23
+ throw new Error(`Template is missing backend folder at: ${srcBackend}`);
16
24
  }
17
25
 
18
26
  log("Creating project directory...");
27
+
19
28
  try {
20
- await fs.copy(src, dest, {
21
- filter: (item) => !item.includes("node_modules")
22
- });
29
+ // Create destination directory
30
+ await fs.ensureDir(resolvedDest);
31
+
32
+ // Copy backend
33
+ console.log("Copying backend...");
34
+ await fs.copy(
35
+ path.join(resolvedSrc, "backend"),
36
+ path.join(resolvedDest, "backend"),
37
+ { filter: (src) => !src.includes("node_modules") }
38
+ );
39
+
40
+ // Copy frontend
41
+ console.log("Copying frontend...");
42
+ await fs.copy(
43
+ path.join(resolvedSrc, "frontend"),
44
+ path.join(resolvedDest, "frontend"),
45
+ { filter: (src) => !src.includes("node_modules") }
46
+ );
47
+
48
+ // Copy root files if any (like .gitignore, README, etc.)
49
+ const rootFiles = await fs.readdir(resolvedSrc);
50
+ for (const file of rootFiles) {
51
+ const srcPath = path.join(resolvedSrc, file);
52
+ const stat = await fs.stat(srcPath);
53
+ if (stat.isFile()) {
54
+ await fs.copy(srcPath, path.join(resolvedDest, file));
55
+ }
56
+ }
57
+
58
+ // Verify the copy was successful
59
+ const backendPath = path.join(resolvedDest, "backend");
60
+ const frontendPath = path.join(resolvedDest, "frontend");
61
+
62
+ if (!await fs.pathExists(backendPath)) {
63
+ throw new Error(`Backend folder not copied to: ${backendPath}`);
64
+ }
65
+
66
+ if (!await fs.pathExists(frontendPath)) {
67
+ throw new Error(`Frontend folder not copied to: ${frontendPath}`);
68
+ }
69
+
23
70
  console.log("✅ Files copied successfully.");
24
71
  } catch (err) {
72
+ // Clean up on failure
73
+ try {
74
+ await fs.remove(resolvedDest);
75
+ } catch (cleanupErr) {
76
+ // Ignore cleanup errors
77
+ }
25
78
  throw new Error(`Failed to copy project files: ${err.message}`);
26
79
  }
27
80
  };
package/lib/utils.js CHANGED
@@ -81,10 +81,23 @@ function assertDependency(depName, cwd) {
81
81
 
82
82
  // ------------------ Run npm install ------------------
83
83
  async function runInstall(cwd) {
84
- await execa("npm", ["install"], {
85
- cwd,
86
- stdio: "inherit"
87
- });
84
+ // Normalize path for Windows
85
+ const normalizedCwd = path.normalize(cwd);
86
+
87
+ // Verify directory exists
88
+ if (!await fs.pathExists(normalizedCwd)) {
89
+ throw new Error(`Directory does not exist: ${normalizedCwd}`);
90
+ }
91
+
92
+ try {
93
+ await execa("npm", ["install"], {
94
+ cwd: normalizedCwd,
95
+ stdio: "inherit",
96
+ shell: true // Use shell for Windows compatibility
97
+ });
98
+ } catch (err) {
99
+ throw new Error(`npm install failed in ${normalizedCwd}: ${err.message}`);
100
+ }
88
101
  }
89
102
 
90
103
  // ------------------ Installing Dynamic DB Drivers ----------------
@@ -96,8 +109,19 @@ async function installDBDriver(targetDir, dialect) {
96
109
  if (dialect === "postgres") pkg = "pg";
97
110
  if (!pkg) return;
98
111
 
112
+ // Normalize path for Windows
113
+ const normalizedDir = path.normalize(targetDir);
114
+
99
115
  console.log(`➡️ Installing ${pkg}...`);
100
- await execa("npm", ["install", pkg], { cwd: targetDir, stdio: "inherit" });
116
+ try {
117
+ await execa("npm", ["install", pkg], {
118
+ cwd: normalizedDir,
119
+ stdio: "inherit",
120
+ shell: true // Use shell for Windows compatibility
121
+ });
122
+ } catch (err) {
123
+ console.warn(`Warning: Failed to install ${pkg}: ${err.message}`);
124
+ }
101
125
  }
102
126
 
103
127
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-fullstack-boilerplate",
3
- "version": "2.1.1",
3
+ "version": "2.1.3",
4
4
  "description": "A Full Stack Application Comprised of React for Frontend, Express & Sequelize with Node js for Backend to help developers get started on real implementation instead of spending time setting up projects.",
5
5
  "main": "index.js",
6
6
  "bin": {