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