netcore-blueprint 1.0.14 → 1.0.15
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/create.js +40 -44
- package/package.json +1 -1
package/create.js
CHANGED
|
@@ -3,61 +3,57 @@
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const oldProjectName = "Blueprint"; // Your template project name
|
|
7
|
+
const newProjectName = process.argv[2];
|
|
8
|
+
|
|
9
|
+
if (!newProjectName) {
|
|
10
|
+
console.error("❌ Please specify the new project name.");
|
|
9
11
|
process.exit(1);
|
|
10
12
|
}
|
|
11
13
|
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
"Blueprint.API.sln",
|
|
15
|
-
"Blueprint.API",
|
|
16
|
-
"Blueprint.Core",
|
|
17
|
-
"Blueprint.Infra",
|
|
18
|
-
"Blueprint.Test",
|
|
19
|
-
"README.md",
|
|
20
|
-
"gitignore" // Rename later
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
function copyFilesRecursively(src, dest) {
|
|
24
|
-
if (fs.lstatSync(src).isDirectory()) {
|
|
25
|
-
fs.mkdirSync(dest, { recursive: true });
|
|
26
|
-
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
27
|
-
for (let entry of entries) {
|
|
28
|
-
const srcPath = path.join(src, entry.name);
|
|
29
|
-
const destPath = path.join(dest, entry.name);
|
|
30
|
-
copyFilesRecursively(srcPath, destPath);
|
|
31
|
-
}
|
|
32
|
-
} else {
|
|
33
|
-
fs.copyFileSync(src, dest);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
14
|
+
const templatePath = path.join(__dirname, `${oldProjectName}Template`);
|
|
15
|
+
const destinationPath = path.join(process.cwd(), newProjectName);
|
|
36
16
|
|
|
37
|
-
// Ensure destination
|
|
17
|
+
// Ensure the destination directory does not already exist
|
|
38
18
|
if (fs.existsSync(destinationPath)) {
|
|
39
|
-
console.error(`❌ Project directory "${
|
|
19
|
+
console.error(`❌ Project directory "${newProjectName}" already exists.`);
|
|
40
20
|
process.exit(1);
|
|
41
21
|
}
|
|
42
22
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
templateItems.forEach(item => {
|
|
47
|
-
const srcPath = path.join(__dirname, item);
|
|
48
|
-
let destPath = path.join(destinationPath, item);
|
|
23
|
+
// Function to recursively copy and rename files/folders
|
|
24
|
+
function copyAndRename(src, dest) {
|
|
25
|
+
const stat = fs.lstatSync(src);
|
|
49
26
|
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
|
|
27
|
+
if (stat.isDirectory()) {
|
|
28
|
+
// Rename folder if needed
|
|
29
|
+
const newDir = path.join(path.dirname(dest), path.basename(dest).replace(oldProjectName, newProjectName));
|
|
30
|
+
fs.mkdirSync(newDir, { recursive: true });
|
|
53
31
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
32
|
+
fs.readdirSync(src).forEach(entry => {
|
|
33
|
+
copyAndRename(path.join(src, entry), path.join(newDir, entry));
|
|
34
|
+
});
|
|
57
35
|
} else {
|
|
58
|
-
|
|
59
|
-
|
|
36
|
+
// Read file content
|
|
37
|
+
let content = fs.readFileSync(src, 'utf8');
|
|
38
|
+
|
|
39
|
+
// Replace all occurrences of "Blueprint" dynamically
|
|
40
|
+
const regex = new RegExp(oldProjectName, "g");
|
|
41
|
+
content = content.replace(regex, newProjectName);
|
|
42
|
+
|
|
43
|
+
// Rename file if needed
|
|
44
|
+
const newFileName = path.basename(dest).replace(oldProjectName, newProjectName);
|
|
45
|
+
const newDest = path.join(path.dirname(dest), newFileName);
|
|
46
|
+
|
|
47
|
+
fs.writeFileSync(newDest, content);
|
|
60
48
|
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Start copying the template
|
|
52
|
+
fs.mkdirSync(destinationPath, { recursive: true });
|
|
53
|
+
|
|
54
|
+
fs.readdirSync(templatePath).forEach(item => {
|
|
55
|
+
copyAndRename(path.join(templatePath, item), path.join(destinationPath, item));
|
|
61
56
|
});
|
|
62
57
|
|
|
63
|
-
console.log(`🎉 Project "${
|
|
58
|
+
console.log(`🎉 Project "${newProjectName}" created successfully at ${destinationPath}`);
|
|
59
|
+
console.log(`📌 Open "${newProjectName}.sln" in Visual Studio to get started!`);
|