create-fullstack-boilerplate 2.1.0 ā 2.1.2
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 +1 -1
- package/lib/copyProject.js +33 -8
- package/lib/setupMainDB.js +3 -1
- package/lib/utils.js +56 -13
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
try {
|
|
52
52
|
console.log("\nšļø Setting Up Full Stack Project...\n");
|
|
53
53
|
|
|
54
|
-
const answers = await mainPrompts();
|
|
54
|
+
const answers = await mainPrompts();
|
|
55
55
|
// const templateDir = path.join(__dirname, "template");
|
|
56
56
|
const targetDir = path.join(process.cwd(), answers.projectName);
|
|
57
57
|
|
package/lib/copyProject.js
CHANGED
|
@@ -1,27 +1,52 @@
|
|
|
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
|
+
// Normalize paths to handle Windows paths with spaces
|
|
7
|
+
const normalizedSrc = path.normalize(src);
|
|
8
|
+
const normalizedDest = path.normalize(dest);
|
|
9
|
+
|
|
8
10
|
// Check if destination already exists
|
|
9
|
-
if (await fs.pathExists(
|
|
10
|
-
throw new Error(`Directory '${path.basename(
|
|
11
|
+
if (await fs.pathExists(normalizedDest)) {
|
|
12
|
+
throw new Error(`Directory '${path.basename(normalizedDest)}' already exists. Please choose a different project name.`);
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
// Check if source template exists
|
|
14
|
-
if (!await fs.pathExists(
|
|
15
|
-
throw new Error(`Template directory not found
|
|
16
|
+
if (!await fs.pathExists(normalizedSrc)) {
|
|
17
|
+
throw new Error(`Template directory not found at: ${normalizedSrc}`);
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
log("Creating project directory...");
|
|
21
|
+
|
|
19
22
|
try {
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
// Ensure destination directory exists first
|
|
24
|
+
await fs.ensureDir(normalizedDest);
|
|
25
|
+
|
|
26
|
+
// Copy with error handling
|
|
27
|
+
await fs.copy(normalizedSrc, normalizedDest, {
|
|
28
|
+
overwrite: false,
|
|
29
|
+
errorOnExist: false,
|
|
30
|
+
filter: (item) => {
|
|
31
|
+
// Filter out node_modules
|
|
32
|
+
return !item.includes("node_modules");
|
|
33
|
+
}
|
|
22
34
|
});
|
|
35
|
+
|
|
36
|
+
// Verify the copy was successful by checking if backend exists
|
|
37
|
+
const backendPath = path.join(normalizedDest, "backend");
|
|
38
|
+
if (!await fs.pathExists(backendPath)) {
|
|
39
|
+
throw new Error(`Copy verification failed: backend folder not found at ${backendPath}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
23
42
|
console.log("ā
Files copied successfully.");
|
|
24
43
|
} catch (err) {
|
|
44
|
+
// Clean up on failure
|
|
45
|
+
try {
|
|
46
|
+
await fs.remove(normalizedDest);
|
|
47
|
+
} catch (cleanupErr) {
|
|
48
|
+
// Ignore cleanup errors
|
|
49
|
+
}
|
|
25
50
|
throw new Error(`Failed to copy project files: ${err.message}`);
|
|
26
51
|
}
|
|
27
52
|
};
|
package/lib/setupMainDB.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
const { replaceInFiles, log } = require("./utils");
|
|
2
|
+
const path = require("path");
|
|
2
3
|
|
|
3
4
|
module.exports = async function setupMainDB(targetDir, dialect) {
|
|
4
5
|
log("Configuring main DB in backend...");
|
|
5
|
-
|
|
6
|
+
const backendDir = path.join(targetDir, "backend");
|
|
7
|
+
await replaceInFiles(backendDir, {
|
|
6
8
|
"__DB_DIALECT__": dialect
|
|
7
9
|
});
|
|
8
10
|
console.log("ā
Main DB configured.");
|
package/lib/utils.js
CHANGED
|
@@ -26,16 +26,35 @@ async function replaceInFiles(base, replacements) {
|
|
|
26
26
|
const exts = [".js", ".ts", ".json", ".md", ".env", ".yml"];
|
|
27
27
|
|
|
28
28
|
async function walk(dir) {
|
|
29
|
-
|
|
29
|
+
// Check if directory exists
|
|
30
|
+
if (!await fs.pathExists(dir)) {
|
|
31
|
+
console.warn(`Warning: Directory ${dir} does not exist, skipping...`);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let items;
|
|
36
|
+
try {
|
|
37
|
+
items = await fs.readdir(dir);
|
|
38
|
+
} catch (err) {
|
|
39
|
+
console.warn(`Warning: Could not read directory ${dir}: ${err.message}`);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
for (const item of items) {
|
|
30
44
|
const fullPath = path.join(dir, item);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
data =
|
|
45
|
+
try {
|
|
46
|
+
const stat = await fs.stat(fullPath);
|
|
47
|
+
if (stat.isDirectory()) {
|
|
48
|
+
await walk(fullPath);
|
|
49
|
+
} else if (exts.includes(path.extname(fullPath))) {
|
|
50
|
+
let data = await fs.readFile(fullPath, "utf8");
|
|
51
|
+
for (const [k, v] of Object.entries(replacements)) {
|
|
52
|
+
data = data.replaceAll(k, v);
|
|
53
|
+
}
|
|
54
|
+
await fs.writeFile(fullPath, data);
|
|
37
55
|
}
|
|
38
|
-
|
|
56
|
+
} catch (err) {
|
|
57
|
+
console.warn(`Warning: Error processing ${fullPath}: ${err.message}`);
|
|
39
58
|
}
|
|
40
59
|
}
|
|
41
60
|
}
|
|
@@ -62,10 +81,23 @@ function assertDependency(depName, cwd) {
|
|
|
62
81
|
|
|
63
82
|
// ------------------ Run npm install ------------------
|
|
64
83
|
async function runInstall(cwd) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
+
}
|
|
69
101
|
}
|
|
70
102
|
|
|
71
103
|
// ------------------ Installing Dynamic DB Drivers ----------------
|
|
@@ -77,8 +109,19 @@ async function installDBDriver(targetDir, dialect) {
|
|
|
77
109
|
if (dialect === "postgres") pkg = "pg";
|
|
78
110
|
if (!pkg) return;
|
|
79
111
|
|
|
112
|
+
// Normalize path for Windows
|
|
113
|
+
const normalizedDir = path.normalize(targetDir);
|
|
114
|
+
|
|
80
115
|
console.log(`ā”ļø Installing ${pkg}...`);
|
|
81
|
-
|
|
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
|
+
}
|
|
82
125
|
}
|
|
83
126
|
|
|
84
127
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-fullstack-boilerplate",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
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": {
|